I tried a simple hello world program as can be found at the end of this topic. In a fresh Win32 console program it works. In a .DLL it works. In a fresh Win32 application from within a newly created thread CreateThread() it works. But within an MFC application it does not (e.g. InitDialog()).
Issues seen when called from within MFC:
- For one omp_set_dynamic(0); crashes as if the vcomp.dll was never loaded although I see it as loaded. omp_get_thread_num(); calls do work, but they always return 0. I see multiple threads actually spawning so #pragma omp parallel is working, but why are all the calls like omp_get_num_threads() returning crapola? It always returns 1 thread as the count and always returns 0 for thread ID numbers. I'm using the exact same hello world code below in all situations... whats up? I really really need the omp_get_thread_num() to work and any Google searches for MFC & OpenMP return doody...Please?
Edit: Yes I'm doing the obvious. /openmp compiler option set. including <omp.h>... etc.
- Code: Select all
int nthreads, tid;
/* Fork a team of threads giving them their own copies of variables */
#pragma omp parallel private(nthreads, tid)
/* Obtain thread number */
tid = omp_get_thread_num();
printf("Hello World from thread = %d\n", tid);
/* Only master thread does this */
if (tid == 0)
nthreads = omp_get_num_threads();
printf("Number of threads = %d\n", nthreads);
} /* All threads join master thread and disband */