Failed to Create Threads

General OpenMP discussion

Failed to Create Threads

Postby cbp_ece » Mon Dec 03, 2007 3:07 am

Hi,
I am executing the following code in MSVC 2005. But only "printf 2" is printing in th output. Its not creating 2 threads (creating only one thread). How to create threads and assign tasks to thread.

#include <stdio.h>
#include <omp.h>
int main()
{
int x;
x = 2;
#pragma omp parallel num_threads(2) shared(x)
{
if (omp_get_thread_num() == 0)
{
x = 5;
}
else
{
/* Print 1: the following read of x has a race */
printf("1: Thread# %d: x = %d\n", omp_get_thread_num(),x );
}
#pragma omp barrier
if (omp_get_thread_num() == 0)
{
/* Print 2 */
printf("2: Thread# %d: x = %d\n", omp_get_thread_num(),x );
}
else
{
/* Print 3 */
printf("3: Thread# %d: x = %d\n", omp_get_thread_num(),x );
}
}
return 0;
}
cbp_ece
 
Posts: 2
Joined: Mon Dec 03, 2007 3:02 am

Re: Failed to Create Threads

Postby lfm » Mon Dec 03, 2007 10:24 am

Are you sure you compiled and linked with the right options to enable OpenMP? Microsoft might be able to help. You could also try the Intel compiler. You could also try setting the OMP_NUM_THREADS environment variable although I would have expected the num_threads clause to override that.
-- Larry
lfm
 
Posts: 135
Joined: Sun Oct 21, 2007 4:58 pm
Location: OpenMP ARB


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot], Majestic-12 [Bot], Yahoo [Bot] and 8 guests