Unable to make my program run in parallel!

General OpenMP discussion

Unable to make my program run in parallel!

Postby hildy » Mon Jun 30, 2008 3:23 am

I am about to parallelize a program written with serial programming. When I try to run the program the #pragma omp parallel regions seem to run in serial anyway. The following code is an example of my problem:

Code: Select all
# ifdef _OPENMP_
     // /*omp\| disables dynamic thread handling
     omp_set_dynamic(0);
     // /*omp\| enables nested parallelism
     omp_set_nested(1);
    
     #pragma omp parallel
     {
        int thread = omp_get_thread_num();
        # ifdef IO_DEBUG_ESS
                 ESUTIL::IO::notifyStream( ESUTIL::IO::DEBUG_ESS )
                <<" Calling from thread number: " << thread << std::endl;
      # endif
      
      if (thread == 0)
      {
         bool isParallel = omp_in_parallel();
         int nothreads = omp_get_num_threads();
         # ifdef IO_DEBUG_ESS
                    ESUTIL::IO::notifyStream( ESUTIL::IO::DEBUG_ESS )
                   <<"The current number of threads are: " << nothreads <<  "\nMaximum number of threads available is: " << omp_get_max_threads() << "\nCode is parallel = " << isParallel << std::endl ;
         # endif
      }
        
        
     }
    
    
    
    
# endif     


This code gives the output:

Calling from thread number: 0
The current number of threads are: 1
Maximum number of threads available is: 4
Code is parallel = 0


When I run simple openMP programs, like the omp_hello.c example for instance, there is no problem. As of yet only one function in one class has been modified so it can't be a problem relating to nested parallelism.
I use Trolltech Qt 4.4.0 and compiling with the QMAKE_CXXFLAG = -fopenmp and QMAKE_LFLAG = -fopenmp variables in the .pro- file. I use g++ from the gcc 4.3.1 package and my computer specs are: a MSI P35 Neo motherboard with a Intel Core2 Quad 2.4 GHz and 4 GB RAM. I run Ubuntu 8.04 64-bits operating system. I also have remembered to included the omp.h library so that isn't the problem.
hildy
 
Posts: 14
Joined: Mon Jun 30, 2008 2:39 am

Re: Unable to make my program run in parallel!

Postby ejd » Mon Jun 30, 2008 3:38 am

Try one of the following:
  • setenv OMP_NUM_THREADS 4
  • adding a call after OMP_SET_DYNAMIC(0) ro OMP_SET_NUM_THREADS(4)
  • adding a NUM_THREADS(4) clause to the omp parallel pragma
Any one of these should tell the run time how many threads to use for the parallel region.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: Unable to make my program run in parallel!

Postby hildy » Mon Jun 30, 2008 3:48 am

No, it does not help. The only thing that changes with adding a omp_set_num_ threads() or the other two options is that the omp_get_max_threads() changes to the setted value.
hildy
 
Posts: 14
Joined: Mon Jun 30, 2008 2:39 am

Re: Unable to make my program run in parallel!

Postby ejd » Mon Jun 30, 2008 6:06 am

Sorry about that. That is the usual cause and I missed the real problem. Your first ifdef is wrong. The macro that is defined is "_OPENMP" and not "_OPENMP_" (note no trailing underscore).
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: Unable to make my program run in parallel!

Postby hildy » Mon Jun 30, 2008 6:41 am

I found the problem.
In the .pro -file I had type QMAKE_LFLAG = -fopenmp but the variable should have been named QMAKE_LFLAGS
Thanks for the help anyway.
hildy
 
Posts: 14
Joined: Mon Jun 30, 2008 2:39 am


Return to Using OpenMP

Who is online

Users browsing this forum: Yahoo [Bot] and 4 guests

cron