2
votes

I've been having trouble getting the basic mpi_cart_create() function in Fortran working.

The following code

  program main
  USE mpi
  implicit none
  integer :: old_comm, new_comm, ndims, ierr
  integer, DIMENSION(1) :: dim_size
  logical ::  reorder
  logical, DIMENSION(1) :: periods

  call MPI_INIT(ierr)
  old_comm = MPI_COMM_WORLD
  ndims = 1            
  dim_size(1) = 4   
  periods(1) = .true.  
  reorder = .true.
  call MPI_CART_CREATE(old_comm, ndims, dim_size, periods, reorder, new_comm, ierr)
  call MPI_Finalize(ierr)

  end program

Compiled with

mpif90 mpitest.f90

Yields, during runtime,

An error occurred in MPI_Cart_create

on communicator MPI_COMM_WORLD

MPI_ERR_OTHER: known error not in list

MPI_ERRORS_ARE_FATAL: your MPI job will now abort

This seems simple, but does anyone recognize the issue?

EDIT: I updated the code (I was a bit hasty in cutting the code down before, thanks for opinting these out) to correct the problems noted below. I think I probably messed up the MPI installation though, since the code will run when compiled with

 (when using `use mpi`)
 mpif90 mpitest3.f90
 mpirun  -np 4  ./a.out

OR

 (when using `include "mpif.h"`)
 mpifort mpitest.f90 
 orterun  -np 4  ./a.out

If I try to compile with mpifort with the use mpi statement I get

PI_CART_CREATE(old_comm, ndims, dim_size, periods, reorder, new_comm, ierr)

Error: There is no specific subroutine for the generic 'mpi_cart_create' at (1)

And if I mix the compiler and run call (e.g. compile with mpif90 and run with orterun) I get

Fatal error in PMPI_Cart_create: Invalid argument, error stack: PMPI_Cart_create(315).....: MPI_Cart_create(MPI_COMM_WORLD, ndims=1, dims=0x7fff26671130, periods=0x1c6e300, reorder=1, comm_cart=0x7fff26671124) failed MPIR_Cart_create_impl(191): MPIR_Cart_create(55)......: Size of the communicator (1) is smaller than the size of the Cartesian topology (4)

Even though the documentation for openmpi states the commands (at least orterun and mpirun) should be synonymous.

1

1 Answers

3
votes

Your issue is that you have both Open MPI and MPICH (or another MPICH-based implementation) installed. mpifort is the generic Fortran compiler wrapper in Open MPI and it seems that it picks module files from MPICH, thus the error when compiling the code with use mpi. Your mpirun definitely comes from MPICH and it cannot properly launch Open MPI executables. The same is true for orterun that comes from Open MPI and it cannot properly launch MPICH executables. In both cases the executables become singletons and each process has its own MPI_COMM_WORLD of size 1, therefore it is not possible to create a Cartesian virtual topology with 4 ranks.

The solution is to first purge from the system all MPI implementations and then to install both runtime and development packets from the same implementation, e.g. Open MPI.