omp_get_max_threads returns too many threads
The followin test fails if the environment variable OMP_NUM_THREADS
(or its counterpart NX_ARGS="--smp-workers=..."
) is lower than the available number of SMP PEs.
#include <stdio.h>
#include <stdlib.h>
#include <omp.h>
#include <assert.h>
int main(int argc, char *argv[])
{
int max_threads = omp_get_max_threads();
int num_threads = 0;
#pragma omp parallel
{
#pragma omp atomic
num_threads++;
}
if (max_threads != num_threads)
{
fprintf(stderr, "max_threads (%d) != num_threads (%d)\n", max_threads, num_threads);
exit(EXIT_FAILURE);
}
return EXIT_SUCCESS;
}
Correct execution
roger@bsccs325:~/tmp$ NX_ARGS="--summary" ./prova
MSG: [?] ========== Nanos++ Initial Environment Summary ==========
MSG: [?] === PID: 12873
MSG: [?] === Num. worker threads: 8
MSG: [?] === System CPUs: active[ 0-7 ] - inactive[ ]
MSG: [?] === Binding: true
MSG: [?] === Prog. Model: OpenMP
MSG: [?] === Plugin: SMP PE Plugin
MSG: [?] === | PEs: 8
MSG: [?] === | Worker Threads: 8
MSG: [?] === Plugin: GPU PE Plugin
MSG: [?] === | PEs: 0
MSG: [?] === | Worker Threads: 0
MSG: [?] === Plugin: OpenCL PE Plugin
MSG: [?] === | PEs: 0
MSG: [?] === | Worker Threads: 0
MSG: [?] =========================================================
MSG: [?] ============ Nanos++ Final Execution Summary ============
MSG: [?] === Application ended in 0 seconds
MSG: [?] === 8 tasks have been executed
MSG: [?] =========================================================
Wrong execution
$ OMP_NUM_THREADS=4 NX_ARGS="--summary" ./prova
MSG: [?] ========== Nanos++ Initial Environment Summary ==========
MSG: [?] === PID: 12934
MSG: [?] === Num. worker threads: 4
MSG: [?] === System CPUs: active[ 0-7 ] - inactive[ ]
MSG: [?] === Binding: true
MSG: [?] === Prog. Model: OpenMP
MSG: [?] === Plugin: SMP PE Plugin
MSG: [?] === | PEs: 8
MSG: [?] === | Worker Threads: 4
MSG: [?] === Plugin: GPU PE Plugin
MSG: [?] === | PEs: 0
MSG: [?] === | Worker Threads: 0
MSG: [?] === Plugin: OpenCL PE Plugin
MSG: [?] === | PEs: 0
MSG: [?] === | Worker Threads: 0
MSG: [?] =========================================================
max_threads (8) != num_threads (4)
MSG: [?] ============ Nanos++ Final Execution Summary ============
MSG: [?] === Application ended in 0 seconds
MSG: [?] === 4 tasks have been executed
MSG: [?] =========================================================
This causes a number of tests in Mercurium testsuite to fail.