Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Parallel
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 20-May-11 4:15am
Edited 20-May-11 5:19am
v3
Comments
Albert Holguin at 20-May-11 10:23am
   
this is library dependent, tag appropriately

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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!
  Permalink  
Comments
fresh_girl at 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 at 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 at 20-May-11 12:08pm
   
How can I get it disabled ??
E.F. Nijboer at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 480
1 Bhavik_Patel 190
2 Richard MacCutchan 155
3 PhilLenoir 155
4 Gihan Liyanage 155
0 Sergey Alexandrovich Kryukov 8,688
1 OriginalGriff 7,237
2 CPallini 2,598
3 Richard MacCutchan 2,080
4 Abhinav S 1,888


Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 20 May 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100