Say I have a std::vector<Object*>. The vector is large ( > 1000 elements) and each Object* needs to have extensive computation done on it. The for loop that runs each the computation on each element then, can be easily parallelized. In fact, I could process all 1000 elements in parallel for maximum speedup (“embarrassingly parallel?”)
Now I’m wondering 2 things:
1) Is it safe to read and write to different elements of a std::vector without a lock? (not modifying the vector itself!)
2) Are there easy ways or conventions or patterns to follow to cut a for loop and dispatch to threads?
1) Yes
2) You can use OpenMP to paralellize vector handling. If you are working with Microsoft VC++ 2010, Concurrency library has parallel_for and parallel_for_each algorithms.