views:

14

answers:

1
#include <omp.h>
#include <stdio.h>


int main(int argc, char* argv[])
{
 omp_set_num_threads(4);
 printf("numThreads = %d\n", omp_get_num_threads());
}

This code prints:

numThreads = 1

This is compiled in Visual Studio 2010 Ultimate. I have turned Project Configuration Properties (All Configurations) -> C/C++ -> Language -> Open MP Support to Yes(/openmp)

I'm at a loss. I've isolated this issue from a larger project where I'd like to use more than one thread.

Any ideas?

A: 

omp_get_num_threads – Size of the active team

Returns the number of threads in the current team. In a sequential section of the program omp_get_num_threads returns 1.

http://gcc.gnu.org/onlinedocs/libgomp/omp_005fget_005fnum_005fthreads.html#omp_005fget_005fnum_005fthreads

This means, use this function inside of parallel loop to know how many thread OMP uses.

Alex Farber