"hello world" C program using hybrid of OpenMP and MPI -


i'm trying "hello world" program uses both openmp , mpi working. started example here

http://www.slac.stanford.edu/comp/unix/farm/mpi_and_openmp.html

but can't reproduce output. here's exact source using:

#include <stdio.h> #include <mpi.h> #include <omp.h>  int main(int argc, char *argv[]) {   int numprocs, rank, namelen;   char processor_name[mpi_max_processor_name];   int iam = 0, np = 1;    mpi_init(&argc, &argv);   mpi_comm_size(mpi_comm_world, &numprocs);   mpi_comm_rank(mpi_comm_world, &rank);   mpi_get_processor_name(processor_name, &namelen);    //omp_set_num_threads(4);  #pragma omp parallel default(shared) private(iam, np)   {     np = omp_get_num_threads();     iam = omp_get_thread_num();     printf("hello thread %d out of %d process %d out of %d on %s\n",            iam, np, rank, numprocs, processor_name);   }    mpi_finalize(); } 

i using dual-processor xeon workstation (2x6 cores) running ubuntu 12.10. have no trouble getting programs use mpi or openmp (but not both) work.

i compiled source above using command

mpicc -fopenmp hello.c -o hello 

then ran using

export omp_num_threads=4 mpirun ./hello -np 2 -x omp_num_threads 

here output getting:

hello thread 0 out of 4 process 0 out of 1 on steinbergt5600linux hello thread 2 out of 4 process 0 out of 1 on steinbergt5600linux hello thread 1 out of 4 process 0 out of 1 on steinbergt5600linux hello thread 3 out of 4 process 0 out of 1 on steinbergt5600linux 

i should, according example, getting this:

hello thread 0 out of 4 process 0 out of 2 on steinbergt5600linux hello thread 2 out of 4 process 0 out of 2 on steinbergt5600linux hello thread 1 out of 4 process 0 out of 2 on steinbergt5600linux hello thread 3 out of 4 process 0 out of 2 on steinbergt5600linux hello thread 0 out of 4 process 1 out of 2 on steinbergt5600linux hello thread 2 out of 4 process 1 out of 2 on steinbergt5600linux hello thread 1 out of 4 process 1 out of 2 on steinbergt5600linux hello thread 3 out of 4 process 1 out of 2 on steinbergt5600linux 

can give me hint i'm doing wrong? far can tell reproducing example in link above.

you're specifying program name first argument mpirun, rest of arguments being ignored (notably: -np 2). thus, -np, got whatever system wide default value.

change:

mpirun ./hello -np 2 -x omp_num_threads 

into:

mpirun -np 2 -x omp_num_threads ./hello 

side note: tested on machine. default -np here 3. on machine, appear default 1


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -