C++ OpenMP parallel is not working

Hi,I'm trying to implement Parallel loop with OpenMP. I just googled and got the below sample, but it seems its not executing parallelly.

It takes same amount time for code which is with parallel and without parallel.

Without Parallel : It takes 39 secs.
-----------------

for (int I=0;I<100000;I++){
cout<<I<<"\t";
}


With Parallel : It takes 39 secs.
--------------

#include<omp.h>

#pragma omp parallel
{
#pragma omp for
for (int I=0;I<100000;I++)
{
cout<<I<<endl;
}
}


Could anyone guide me please, why parallel is not working and it takes same time. My machine is Dual Core.
Could anyone guide me please, why parallel is not working and it takes same time.

I haven't any experience with OpenMP, but this surely has to be one of the least parallelizable loops possible. You access the same object every iteration of the loop so every thread would be competing with every other thread for the same resource.
I'd say that a stream generally canot be parallelized
How many cores are there on your system? Also try to use command
like: export OMP_NUM_THREADS=8 to change the amount of threads
that you are using.
Hi, Thanks for valuable answers. I got answer for my problem, that is,
I'm developing in Visual studio 2012 and we need to change setting to support OpenMS in visual studio.

Right click on project - > Properties - > Configuration Properties - >C/C++ -> Language - > OpenMP Support -> Choose YES ( /openmp )

Last edited on
Topic archived. No new replies allowed.