Reputation: 499
For an unknown reason, when I compile with MPI omp_get_max_threads()
, the number of threads returned (12) is half of the capacity my computer has (24 threads, 12 cores). This strange behaviour appeared without reason for two days now, while everything was working well before. I have installed MPI from source. I tried to install it again in the same way but still faced the same problem.
I have read several posts, and seen the oversubscribe
or the omp_set_dynamic()
solutions, but I am not satisfied with neither of these, because I am running a cluster with different type of machines, and I really want to determine the maximum number of threads dynamically.
How can I find the variables driving the default result of omp_get_max_threads()
?
#include <omp.h>
#include <mpi.h>
#include <iostream>
int main(int argc, char** argv){
int provided;
MPI_Init_thread(NULL, NULL, MPI_THREAD_SINGLE, &provided);
//int num_cpu = omp_get_max_threads();
//omp_set_dynamic(0);
//omp_set_num_threads(4);
std::cout << omp_get_max_threads()<< std::endl;
MPI_Finalize();
return 0;
}
Compiling it with mpicxx not_fun.cpp -fopenmp -o not_fun
. If I execute it with ./not_fun
result is 24, which is correct. If I execute it with mpiexec -np 4 ./not_fun
result is 12, not correct.
I am not sure if this is related.
I ultimately had a problem with my RAM, and one stick is not working properly so I removed it. It could perhaps be related, but I don't think so. I installed again MPI with the new RAM configuration, and still got the same problem.
Upvotes: 0
Views: 538
Reputation: 5794
You're misunderstanding what a thread is. A thread is a software construct, having nothing to do with hardware. Try writing a program that prints out the number of threads, and do OMP_NUM_THREADS=321 ./yourprogram
It will report both the max and actual number of threads to be 321. If you want something relating to the number of cores, use omp_get_num_procs
. (And just to be clear: the number of threads comes from the OMP_NUM_THREADS
environment variable, or any explicit override in your source.)
If you write an MPI program, and you do the same thing, you'll find that (probably) each MPI process gets an equal number of "procs" and multiplying MPI procs (on one node) and OMP procs will be less equal than the core count. But that may depend on your implementation.
Upvotes: 2