Please Help. MFC + OpenMP?

General OpenMP discussion

Please Help. MFC + OpenMP?

Postby Hypershadow » Sat Jul 05, 2008 12:37 pm

Okay, just started using OpenMP... its great! (when it works)

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;
omp_set_dynamic(0);
omp_set_num_threads(10);

  /* 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 */
Hypershadow
 
Posts: 1
Joined: Sat Jul 05, 2008 12:27 pm

Re: Please Help. MFC + OpenMP?

Postby ejd » Sun Jul 06, 2008 8:44 pm

Unfortunately I have no idea. This site is really geared to answer general OpenMP questions and not specific implementation questions. Maybe someone else reading these forums will have an answer. I think your best bet though, is to post this on one of the Microsoft forums.
Last edited by ejd on Mon Jul 21, 2008 8:23 am, edited 1 time in total.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: Please Help. MFC + OpenMP?

Postby hello world » Wed Aug 13, 2008 11:16 pm

Your example works on my computer. I paste your program into the file ooo.c, for example,

// file ooo.c
#include <omp.h>
#include <stdio.h>
int main()
{
int nthreads, tid;
omp_set_dynamic(0);
omp_set_num_threads(10);

/* 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 */
}
// end of file ooo.c

The implementation is as:

C:\TEMP\c>gcc -fopenmp ooo.c

C:\TEMP\c>a
Hello World from thread = 1
Hello World from thread = 2
Hello World from thread = 4
Hello World from thread = 3
Hello World from thread = 6
Hello World from thread = 5
Hello World from thread = 8
Hello World from thread = 7
Hello World from thread = 0
Hello World from thread = 9
Number of threads = 10

It works. Which compiler do you use? gFortran for Windows, implementing omp v2.5 and v3.0, can be downloaded at http://www.equation.com
hello world
 


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 12 guests