Click here to Skip to main content
12,700,957 members (29,530 online)
Rate this:
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 5:15am
Updated 20-May-11 6:19am
Albert Holguin 20-May-11 10:23am
this is library dependent, tag appropriately

1 solution

Rate this: bad
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:[^]

Good luck!
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:

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 20 May 2011
Copyright © CodeProject, 1999-2017
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