no parallelisation on mac intel

General OpenMP discussion

no parallelisation on mac intel

Postby alihelmy » Mon Jul 14, 2008 12:19 pm

Hey mates,

I'm sorry if this has been asked before or if im missing something... i tried googling and searching here for a little while but couldnt find anything, so...

i have this piece of code:
Code: Select all
#include <omp.h>
#include <stdio.h>

int main (int argc, char *argv[]) {
   int th_id, nthreads;
   int cpus = omp_get_num_procs();
   printf("number of cpus = %d\n", cpus);
#pragma omp parallel private(th_id)
   {
      th_id = omp_get_thread_num();
      printf("Hello World from thread %d\n", th_id);
#pragma omp barrier
      if ( th_id == 0 ) {
         nthreads = omp_get_num_threads();
         printf("There are %d threads\n",nthreads);
      }
   }
   return 0;
}


my current spec is:
Mac OS X 10.4, on Intel Core 2 Duo
GNU g++ 4.3 compiler


i compile using g++ main.cpp -fopenmp, and get no errors on compile, but when i run i get:
Code: Select all
number of cpus = 1
Hello World from thread 0
There are 1 threads


so why am i getting only one cpu from the omp call when i have a dual core cpu?
alihelmy
 
Posts: 3
Joined: Sun Jul 06, 2008 7:48 am

Re: no parallelisation on mac intel

Postby djo35 » Fri Jul 18, 2008 7:24 am

Hello alihelmy

That should work so if it isn't we need to check a few things out - (I have the same set-up here and your code works fine for me)

First things:

g++ main.cpp -fopenmp

should look more like

g++ -fopenmp main.cpp

for consistency, style and to stop GCC whining.

g++ is just an extension of gcc. We should check that you're actually calling gcc 4.3 (Apple by default uses 4.0 which doesn't have OMP by default)

try:
g++ --version

if you see
i686-apple-darwin9-g++-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465)

then we're not calling the correct g++ compiler - try compiling with

g++-4 -fopenmp main.cpp

(On my system g++-4 links to gcc 4.3 - I can check this with g++-4 --version )

If that's still not working, call back!

Dan
djo35
 
Posts: 11
Joined: Wed May 28, 2008 8:24 am

Re: no parallelisation on mac intel

Postby ejd » Mon Jul 21, 2008 7:47 am

The big problem I see here is the number being returned from the omp_get_num_procs call. You say that you have a Core 2 Duo, but this call doesn't seem to indicate it is seeing any more than one processor (or core). The routines for OpenMP are being found, otherwise you would be getting a link error, so I would assume that you have a version of gcc that supports OpenMP (though do make the checks Dan has suggested). I am afraid that I don't understand this either. Anyone else have any ideas??
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: no parallelisation on mac intel

Postby alihelmy » Mon Jul 21, 2008 9:01 am

djo35 wrote:Hello alihelmy

That should work so if it isn't we need to check a few things out - (I have the same set-up here and your code works fine for me)

First things:

g++ main.cpp -fopenmp

should look more like

g++ -fopenmp main.cpp

i tried that, same output with 1 cpu

djo35 wrote:g++ is just an extension of gcc. We should check that you're actually calling gcc 4.3 (Apple by default uses 4.0 which doesn't have OMP by default)

try:
g++ --version

if you see
i686-apple-darwin9-g++-4.0.1 (GCC) 4.0.1 (Apple Inc. build 5465)

then we're not calling the correct g++ compiler - try compiling with

g++-4 -fopenmp main.cpp

(On my system g++-4 links to gcc 4.3 - I can check this with g++-4 --version )

If that's still not working, call back!

Dan


i know that, i downloaded g++-4.3 from HPC for the Mac OS X and it reads:
>g++ --version
g++ (GCC) 4.3.0 20080125 (experimental)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


where did u get ur g++-4.3?
alihelmy
 
Posts: 3
Joined: Sun Jul 06, 2008 7:48 am

Re: no parallelisation on mac intel

Postby Jasper » Tue Jul 22, 2008 2:25 am

Don't forget to set the OMP_NUM_THREADS environment variable...

Jasper
Jasper
 

Re: no parallelisation on mac intel

Postby ejd » Tue Jul 22, 2008 7:10 am

The gcc code seems to be trying to get the number of processors that are online from the system. For some reason this doesn't seem to be working correctly (as far as I can tell). Since you have gcc installed, could you please compile the following program and tell me the result. Thanks.

Code: Select all
#include <stdio.h>
#include <unistd.h>

int main(void)
{
  printf("nprocs: %i\n", sysconf (_SC_NPROCESSORS_ONLN));
  return 0;
}
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: no parallelisation on mac intel

Postby alihelmy » Mon Jul 28, 2008 7:47 am

ejd wrote:The gcc code seems to be trying to get the number of processors that are online from the system. For some reason this doesn't seem to be working correctly (as far as I can tell). Since you have gcc installed, could you please compile the following program and tell me the result. Thanks.

Code: Select all
#include <stdio.h>
#include <unistd.h>

int main(void)
{
  printf("nprocs: %i\n", sysconf (_SC_NPROCESSORS_ONLN));
  return 0;
}


i could not compile the code... the error:

g++ -fopenmp main.cpp
main.cpp: In function 'int main()':
main.cpp:6: error: '_SC_NPROCESSORS_ONLN' was not declared in this scope


Jasper wrote:Don't forget to set the OMP_NUM_THREADS environment variable...

Jasper


how can i do that? and... why doesnt openmp auto-detect the number of threads?
alihelmy
 
Posts: 3
Joined: Sun Jul 06, 2008 7:48 am

Re: no parallelisation on mac intel

Postby ejd » Mon Jul 28, 2008 8:20 am

alihelmy wrote:i could not compile the code... the error:

g++ -fopenmp main.cpp
main.cpp: In function 'int main()':
main.cpp:6: error: '_SC_NPROCESSORS_ONLN' was not declared in this scope


Looks like I will have to go back and see if I can figure out exactly what is done on the Mac that is different. Sorry about that - but I don't have a Mac I can try things on.

alihelmy wrote:
Jasper wrote:Don't forget to set the OMP_NUM_THREADS environment variable...

Jasper


how can i do that? and... why doesnt openmp auto-detect the number of threads?

You can either set the environment variable (setenv OMP_NUM_THREADS 2), call a routine (omp_set_num_threads(2);), or use a clause on the parallel directive (num_threads(2)) to try and set the number of threads to be used.

The problem with auto-detection of the number of processors is, that you don't know if the system is a being used by one or multiple users. In the one user case, you most likely want to use all the processors. However, in the multiple user case, that will slow things down for everyone. That is why the OpenMP default for the number of processors to use is implementation defined. There is no "right" answer that fits all circumstances.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: no parallelisation on mac intel

Postby jakub » Fri Sep 19, 2008 7:39 am

The problem is that darwin apparently doesn't (or is it just older versions of darwin?) support the POSIX _SC_NPROCESSORS_ONLN. omp_get_num_procs is implemented as for the generic (posix) version:

int
omp_get_num_procs (void)
{
#ifdef _SC_NPROCESSORS_ONLN
return sysconf (_SC_NPROCESSORS_ONLN);
#else
return gomp_icv (false)->nthreads_var;
#endif
}

Googling around this might work:

#include <sys/sysctl.h>
...
int
omp_get_num_procs (void)
{
#ifdef _SC_NPROCESSORS_ONLN
return sysconf (_SC_NPROCESSORS_ONLN);
#elif defined HW_NCPU
int ncpus = 1;
size_t len = sizeof(ncpus);
sysctl((int[2]) {CTL_HW, HW_NCPU}, 2, &ncpus, &len, NULL, 0);
return ncpus;
#else
return gomp_icv (false)->nthreads_var;
#endif
}

and similarly for other places in libgomp/config/posix/proc.c - actually much better would be just copy & modify libgomp/config/darwin/proc.c and adjust it, then just change configury to prefer that file on darwin.

That said, I have no access to darwin, so somebody with such access would need to write a patch and test it, then submit. libgomp is primarily optimized for Linux, support for other architectures is worse.
jakub
 
Posts: 74
Joined: Fri Oct 26, 2007 3:19 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 12 guests