This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

omp_get_num_procs() not working on macintosh?


Hi,
	I'm not able to detect the number of processors using omp_get_num_procs()  on 
a macintosh.
	I've installed gcc/g++ v4.3 from hpc.sourceforge.net (the "Tiger" version)
[Url 1 below].  (Installed = extracted to /)
$ g++ --version
g++ (GCC) 4.3.0 20080125 (experimental)
	I compile the code below with no problems.
$ g++ -fopenmp main.cpp -o openmpTest
	When the code executes omp_get_num_procs() detects 1 processor.
$ ./openmpTest
num procs 1
thread 0  i: 0
thread 0  i: 1
thread 0  i: 2
thread 0  i: 3
thread 0  i: 4
thread 0  i: 5
thread 0  i: 6
thread 0  i: 7
thread 0  i: 8
thread 0  i: 9

	This macintosh has two physical chips and 2 cores per chip.
$ sysctl hw 
[...]
hw.ncpu: 4
hw.activecpu: 4
[...]

	Does anybody know why omp_get_num_procs() is returning 1 on this machine?  
Let me know if you need more info!

Thanks,
	C.


[1]http://prdownloads.sourceforge.net/hpc/gcc-intel-bin.tar.gz?download


-----------------------------------------------------------------------------
// "g++ -fopenmp  main.cpp -o openmpTest"
#include <iostream>

#ifdef _OPENMP		// defined at compile time by -fopenmp
#include <omp.h>
#endif

using namespace std;

int main (int argc, char **argv) {
	int n_iters = 10;

	#ifdef OMP_H			// defined in header omp.h
	cout<<"num procs "<<omp_get_num_procs()<<endl;
	#pragma omp parallel num_threads(omp_get_num_procs())
	#pragma omp for schedule(dynamic, 1)
	#endif
	for (int i = 0; i < n_iters; ++i) {
		#ifdef OMP_H			// defined in header omp.h
		cout<<"thread "<<omp_get_thread_num()<<"  ";
		#endif
		cout<<"i: "<<i<<endl;
		sleep(5/(i+1));		// simulate a load
	}

	return 0;
}
-----------------------------------------------------------------------------


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]