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?
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.
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?