I have the following code in which I want to run an algorithm on each connected component of a graph. I want to run them in parallel for maximum speed. However, the following code runs sequentially. Could you please help me find what the problem is Is it because I have a single core processor I will run my code on a cluster when I finish with the development.
Thanks in advance,

#pragma omp parallel for
for (int i=0; i<(int)connectedComponents.size();iter++)
ConnectedComponent* ccPtr = *iter;

Re: Visual C++ General problem with opm

Pintu Shukla

See if you want to run All of them to Parallel then you have to go for Multithreading with Thread Synchronization.Running sequential is not a good idea in your case as per i understand you assume you have 15 Sensor and you want to erform operation on all 15 sensor at run time.so you should have to go by above . But you should take precaution in this case other wise it can create a lots of issue for you.


Re: Visual C++ General problem with opm


Thanks for the reply,

But I am comfused. Isn't omp supposed to do it. Why does it wait for the current iteration to finish for creating a new thread. I supposed it would start the thread, while the function is running on that thread, it will move to next iteration and start a new thread and so on...Am I missing somthing

Re: Visual C++ General problem with opm

Bite Qiu - MSFT

First of all, make sure /openmp compiler switch is enabled, otherwise visual c++ compiler will skip #pragma omp statements.

Secondly, the default number of threads is equal to the number of logical prcessors in your machine, for a single core processor with no hyperthreading support, the logical processor number is 1, so there will be only 1 thread used to perform "parallel" tasks. To explicity specify the number of threads in a thread team, try use num_threads clauses (supported by parallel directive, so it should be able to add to clauses section in for directive: "#pragma omp [parallel] for [clauses]").

More information please refer to:




hope it helps