I have a program on C that uses both MPI and OpenMP. In order to compile such program on Windows system I have downloaded and installed a gcc compiler provided by MinGW. Using this compiler I can compile and execute C programs with OpenMP using the key -fopenmp
for gcc. Such programs run without problems. In order to compile and execute C programs with MPI I have downloaded and installed MPICH2. Now I can compile and run such programs without problems, specifying additional parameters for gcc, provided by MinGW. But when I want to compile and run a program that uses both OpenMP and MPI I have a problem. I specified both keys -fopenmp
and keys for MPI program for gcc compiler. Compilator didn't give me any error. I tried to launch my program by mpiexec
, provided by MPICH2. My program didn't want to work (It was a HelloWorld program and it didn't print anything to output). Please help me to compile and launch such programs correctly.
Here is my HelloWorld program, that doesn't produce any output.
#include <stdio.h>
#include <mpi.h>
int main(int argc, char ** argv)
{
int thnum, thtotal;
int pid, np;
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD,&pid);
MPI_Comm_size(MPI_COMM_WORLD,&np);
printf("Sequental %d out of %d!\n",pid,np);
MPI_Barrier(MPI_COMM_WORLD);
#pragma omp parallel private(thnum,thtotal)
{
thnum = omp_get_thread_num();
thtotal = omp_get_num_threads();
printf("parallel: %d out of %d from proc %d out of %d\n",thnum,thtotal,pid,np);
}
MPI_Barrier(MPI_COMM_WORLD);
MPI_Finalize();
return 0;
}
Dimitri :
You can use the mpicc compiler with the -openmp option. For example, \n\nmpicc -openmp hello.c -o hello\n",
2012-10-09T08:42:31
Hristo Iliev :
This might not be the root cause of your problem, but the MPI standard mandates that threaded programs use MPI_Init_thread() instead of MPI_Init(). In your case there are no MPI calls from within the parallel region so threading level of MPI_THREAD_FUNNELED should suffice. You should replace the call to MPI_Init() with:\n\nint provided;\n\nMPI_Init_thread(&argc, &argv, MPI_THREAD_FUNNELED, &provided);\nif (provided < MPI_THREAD_FUNNELED)\n{\n MPI_Abort(MPI_COMM_WORLD, 1);\n return 1; // Usually not reached\n}\n\n\nAlthough some MPI libraries might not advertise threading support (provided as returned is MPI_THREAD_SINGLE) they still work fine with hybrid OpenMP/MPI codes if one does not make MPI calls from within parallel regions.",
2012-10-10T09:50:54