Click here to Skip to main content
15,885,366 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
as I was trying to learn openMP , I came across this sample of code
#include < stdio.h>
#include < omp.h> // Include OpenMP
int main(int argc, char **argv)
{
#pragma omp parallel num_threads(10)
		{
			int threadNum;
			threadNum = omp_get_thread_num();
			printf("This is thread %d\n", threadNum);
		}
	return 0;
}


the author said that it worked correctly print ids from 0-9.
but when I try it ,it only print id 0. i.e, only one thread is running .
knowing that my OS is win7 and processor is Intel icore7
Posted
Updated 20-May-11 5:19am
v3
Comments
Albert Holguin 20-May-11 10:23am    
this is library dependent, tag appropriately

1 solution

This example is also on the wiki where they use barriers. stdout doesn't have to be thread safe. Have another look at the wiki on this:
http://en.wikipedia.org/wiki/OpenMP[^]

Good luck!
 
Share this answer
 
Comments
fresh_girl 20-May-11 11:31am    
I read the wiki before , tried the code examples and many more but they all use one thread .
thank you .
E.F. Nijboer 20-May-11 12:03pm    
Another reason is that the the openMP implementation didn't choose for parallelization. Your processor also has boost and openMP could favor increasing your cpu frequency instead of setting up threads to execute the code on a lower frequency. The idea is of course to get the maximum through put and in your case this could simply be MHz over multi core. You could have a go with boost disabled and see if you can force it that way.
fresh_girl 20-May-11 12:08pm    
How can I get it disabled ??
E.F. Nijboer 20-May-11 14:16pm    
You can enable/disable it in the bios. More info: http://www.intel.com/support/processors/sb/cs-029908.htm#6

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900