Good for multi-thread program?

Hi,

I am running a heavy simulation which takes time, its main structure looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
for(int i=0; i<1000; i++) { // repeat what's inside 1000 times -- A

   for(int j=0; j<2000; j++) { // sequential computation from 1 to 2000 --B
      // create and run a big object of vectors: myV
      //......
   }

   // some similar loops running on the vector created in part <B>
   for(auto iter = myV.being(); iter != myV.end(); iter++) { // --C
      // ......
   }
   for(auto iter = myV.being(); iter != myV.end(); iter++) { // --D
      // ......
   }

   // ......
   for(auto iter = myV.being(); iter != myV.end(); iter++) { // --K
      // ......
   }

}

Should I use multi-thread programming to speed up? for part <A>? or maybe for part <C> to <K>?
Could someone expert in this area give me some opinion, please?

Thanks in advance.
If each for loop's data is independent of others, you can put each to a function and then call each function in a thread. If loops need to execute in series, I don't think you have any chances.
In threads you need to care about data races, shared data, thread finish etc.

Good Luck
Thanks for your opinion. Any other comments please?
Are your loops C .. K going to be altering the content of myV?

If not then you'll be fine with threads doing the work.

Jim
closed account (zb0S216C)
Do each of the loops need to run in sync with each other?
Is there any communication between the loops?
Do each of the loops have a specified time-frame in which they need to finish?
Does one loop have a priority over another?
Do your loops access a common resource?
Should each thread execute two or more of the loops rather than one?
Should each thread remain active after it has finished?

Wazzak
Topic archived. No new replies allowed.