Open MPI logo

Open MPI User's Mailing List Archives

  |   Home   |   Support   |   FAQ   |   all Open MPI User's mailing list

Subject: [OMPI users] Confused on simple MPI/OpenMP program
From: Ed Blosch (eblosch_at_[hidden])
Date: 2013-04-03 22:35:40

Consider this Fortran program snippet:

program test

  ! everybody except rank=0 exits.
  call mpi_init(ierr)
  call mpi_comm_rank(MPI_COMM_WORLD,irank,ierr)
  if (irank /= 0) then
    call mpi_finalize(ierr)

  ! rank 0 tries to set number of OpenMP threads to 4
  call omp_set_num_threads(4)
  nthreads = omp_get_max_threads()
  print*, "nthreads = ", nthreads

  call mpi_finalize(ierr)

end program test

It is compiled like this: 'mpif90 -o test -O2 -openmp test.f90' (Intel

When I run it like this: mpirun -np 2 ./test

The output is: "nthreads = 0"

Does that make sense? I was expecting 4.

If I comment out the MPI lines and run the program serially (but still
compiled with mpif90), then I get the expected output value 4.

I'm sure I must be overlooking something basic here. Please enlighten me.
Does this have anything to do with how I've configured OpenMPI?