10 Replies - 1023 Views - Last Post: 24 April 2013 - 12:54 PM Rate Topic: -----

#1 C.Andrews   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 169
  • Joined: 18-October 12

General threading questions

Posted 24 April 2013 - 09:39 AM

I'm working with a program that calculates many, many iterations of a function to predict the amount of genetic progress (within a group of traits) we can make in a population of animals by assigning different weights to each trait and looking at which animals should be selected based on the resulting values.

I want to split the work up to cut down on processing time, and currently I have one BackgroundWorker analyzing the males, and one analyzing the females. My thinking was that would give me 3 threads in my application, one for the main UI, one for processing males, and one for processing females. I have 4 cores on the PC where I'm running the application, so that should mean that my Windows resource scheduler can (in theory) run the application without any of the threads competing for clock cycles with each other.

What I've found is that when I examine the application while it's running, the resource monitor reports that it's using 9 threads, rather than 3, so my question is: what the *@&#? I don't understand where all these threads came from, and what I need to do differently to ensure my two major threads (the processing threads) don't have to compete with on another.

Is This A Good Question/Topic? 0
  • +

Replies To: General threading questions

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14502
  • View blog
  • Posts: 58,139
  • Joined: 12-June 08

Re: General threading questions

Posted 24 April 2013 - 09:45 AM

Don't freak out about those other threads.. I mean hell.. and an empty, generic, windows form creates like ten.

Ideally you would be using the new 'tasks' and not background workers.

http://blog.stephenc...from-tasks.html
http://msdn.microsof...tasks.task.aspx
http://www.dreaminco...arallelfor-101/
Was This Post Helpful? 0
  • +
  • -

#3 C.Andrews   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: General threading questions

Posted 24 April 2013 - 09:53 AM

View Postmodi123_1, on 24 April 2013 - 04:45 PM, said:

Ideally you would be using the new 'tasks' and not background workers.



GAH! I just got my stupid head wrapped around using backgroundworkers correctly! I thought that was the preferred method for multi-threading these days?! Guess I better get to reading...grumble...
Was This Post Helpful? 0
  • +
  • -

#4 dbasnett   User is offline

  • D.I.C Addict
  • member icon

Reputation: 121
  • View blog
  • Posts: 666
  • Joined: 01-October 08

Re: General threading questions

Posted 24 April 2013 - 10:54 AM

Backgroundworkers is fine.
Was This Post Helpful? 0
  • +
  • -

#5 C.Andrews   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: General threading questions

Posted 24 April 2013 - 12:32 PM

View Postmodi123_1, on 24 April 2013 - 04:45 PM, said:

Don't freak out about those other threads.. I mean hell.. and an empty, generic, windows form creates like ten.

Ideally you would be using the new 'tasks' and not background workers.

http://blog.stephenc...from-tasks.html
http://msdn.microsof...tasks.task.aspx
http://www.dreaminco...arallelfor-101/



I looked over your examples using Parallel.For, and I have to say that method is exactly what I conceptualized as a solution to my computation problems; unfortunately, implementing those techniques is way beyond my skill. If I were working with a simply for loop I could probably dumb my way through it, but my computation involves a deeply nested series of loops to calculate all my permutations. Even that is probably a dumb hack of a solution, but as I mentioned, I'm not a real programmer.

Another thing that might be an issue: each iteration of my loop makes a decision on what to do with the values it generates based on what has come before. If the new value is better than the previous low value, the old value gets kicked out and the new value takes its place in a table. How would that work with iterations finishing out of sequential order?

If you're curious, here is the method I'm using:

Spoiler

This post has been edited by C.Andrews: 24 April 2013 - 01:03 PM

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14502
  • View blog
  • Posts: 58,139
  • Joined: 12-June 08

Re: General threading questions

Posted 24 April 2013 - 12:35 PM

FFS that's ugly. What is this - some branch of genetic algorithms for.. birds?
Was This Post Helpful? 0
  • +
  • -

#7 andrewsw   User is online

  • head thrashing
  • member icon

Reputation: 6629
  • View blog
  • Posts: 27,098
  • Joined: 12-December 12

Re: General threading questions

Posted 24 April 2013 - 12:39 PM

Wow!? I've never seen 25 Nexts in a row :online2long: :helpsmilie:
Was This Post Helpful? 0
  • +
  • -

#8 C.Andrews   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: General threading questions

Posted 24 April 2013 - 12:40 PM

View Postmodi123_1, on 24 April 2013 - 07:35 PM, said:

FFS that's ugly.


qft.

The computations I'm running are simulations to determine the best birds to use as breeders for the next generation. We want to maximize the index value for each bird within certain limits for 25+ different traits, and my program steps through these permutations and presents the best results to the user.

It's fugly, and poorly written, but it's a damn sight better than what's currently being done: right now the selector takes this simulation algorithm, manually changes the weight value of one or two traits, and reruns the single sim until a satisfactory answer is reached. Currently around 30 or so simualtions are tested each generation out of the billions of possible permutations.
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14502
  • View blog
  • Posts: 58,139
  • Joined: 12-June 08

Re: General threading questions

Posted 24 April 2013 - 12:45 PM

Okay.. I'll bite. You mention birds and breeding.. is this for some sort of game, Chocobo racing, or real world application. I mean what's the end game with all of this?
Was This Post Helpful? 0
  • +
  • -

#10 C.Andrews   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 169
  • Joined: 18-October 12

Re: General threading questions

Posted 24 April 2013 - 12:47 PM

View Postmodi123_1, on 24 April 2013 - 07:45 PM, said:

Okay.. I'll bite. You mention birds and breeding.. is this for some sort of game, Chocobo racing, or real world application. I mean what's the end game with all of this?



I'm a Data Analyst for a poultry breeding company. One of the geneticists asked me if I could come up with a method for running their simulations automatically to replace the clunky, manual method they currently use. As I mentioned, I'm not actually a programmer, but I do sometimes get myself in over my head trying to do task automation to make my own life easier.
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14502
  • View blog
  • Posts: 58,139
  • Joined: 12-June 08

Re: General threading questions

Posted 24 April 2013 - 12:54 PM

Ah.. gotcha.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1