我遇到了一個問題,標誌-Dparallel(我們在代碼中使用它來啓用並行部分)。當我使用它時,我不再獲得更多的OpenMP線程。mpicc/openmp標誌-Dparallel有什麼影響?
備註:我們正在運行MPI/OpenMP混合代碼。
短代碼例如:
#include <stdio.h>
#include "mpi.h"
#ifdef _OPENMP
#include <omp.h>
#else
#define omp_get_num_threads() 0
#define omp_get_thread_num() 0
#endif
int main(int argc, char **argv)
{
int nthreads, thread_id;
int rank, size, provided;
MPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided); /* starts MPI */
MPI_Comm_rank (MPI_COMM_WORLD, &rank); /* get current process id */
MPI_Comm_size (MPI_COMM_WORLD, &size); /* get number of processes */
#pragma omp parallel private(nthreads, thread_id)
{
nthreads = omp_get_num_threads();
thread_id = omp_get_thread_num();
if (thread_id == 0)
printf("This is rank %d with %d threads.\n", rank,nthreads);
}
MPI_Finalize();
return 0;
}
如果我與編譯它的輸出顯示:
$ mpirun -np 2 ./example
This is rank 1 with 6 threads.
This is rank 0 with 6 threads.
正如所預期的。
如果我使用的標誌-Dparallel
(整行:mpicc -Dparallel -o example_parallel -fopenmp example.c
)
輸出說:
$ mpirun -np 2 ./example_parallel
This is rank 0 with 1 threads.
This is rank 1 with 1 threads.
爲什麼-Dparallel
限制了OpenMP的Threadfs爲1?我在哪裏可以找到這方面的文件?
爲完整起見:
- 的mpirun(開放MPI)1.4.1
- GCC(Ubuntu的4.4.3-4ubuntu5.1)4.4.3
EDIT(也許解決方案):我只是testet編譯它使用:
mpicc -Dparallel=parallel -o example_parallel -fopenmp example.c
它按預期工作。所以我想--D並行只是混淆了#pragma omp parallel
。我對嗎?
你說得對。謝謝。 「並行=並行」不是解決方案,而是證明這是問題。 – redimp