christophe petit wrote:
i'm studying the parallelized version of a solving 2D heat equation
code in order to understand cartesian topology and the famous
"MPI_CART_SHIFT".
Here's my problem at this part of the code :
-------------------------------------------------------------------------------------------------------------------------------------------
call MPI_INIT(infompi)
comm = MPI_COMM_WORLD
call MPI_COMM_SIZE(comm,nproc,infompi)
call MPI_COMM_RANK(comm,me,infompi)
!
......
! Create 2D cartesian grid
periods(:) = .false.
ndims = 2
dims(1)=x_domains
dims(2)=y_domains
CALL MPI_CART_CREATE(MPI_COMM_WORLD, ndims, dims, periods, &
reorganisation,comm2d,infompi)
!
! Identify neighbors
!
NeighBor(:) = MPI_PROC_NULL
! Left/West and right/Est neigbors
CALL MPI_CART_SHIFT(comm2d,0,1,NeighBor(W),NeighBor(E),infompi)
print *,'rank=', me
print *, 'here first mpi_cart_shift : neighbor(w)=',NeighBor(W)
print *, 'here first mpi_cart_shift : neighbor(e)=',NeighBor(E)
...
-------------------------------------------------------------------------------------------------------------------------------------------
with x_domains=y_domains=2
and i get at the execution :" mpirun -np 4 ./explicitPar"
rank= 0
here first mpi_cart_shift : neighbor(w)= -1
here first mpi_cart_shift : neighbor(e)= 2
rank= 3
here first mpi_cart_shift : neighbor(w)= 1
here first mpi_cart_shift : neighbor(e)= -1
rank= 2
here first mpi_cart_shift : neighbor(w)= 0
here first mpi_cart_shift : neighbor(e)= -1
rank= 1
here first mpi_cart_shift : neighbor(w)= -1
here first mpi_cart_shift : neighbor(e)= 3
I saw that if the rank is out of the topology and wihtout periodicity,
the rank should be equal to MPI_UNDEFINED whis is assigned to -32766
in "mpif.h" . So, why have i got the value "-1" ?
On my Macbook pro, i get the value "-2".
It seems to me the man page says MPI_PROC_NULL may be returned, and in
OMPI that looks like -2. Can you try the following:
% cat x.f90
include "mpif.h"
integer comm, dims(2)
logical periods(2)
call MPI_INIT(ier)
ndims = 2
dims(1)=2; periods(1) = .false.
dims(2)=2; periods(2) = .false.
CALL MPI_CART_CREATE(MPI_COMM_WORLD, ndims, dims, periods, .false.,
comm, ier)
CALL MPI_CART_SHIFT(comm, 0, 1, iwest, ieast, ier)
write(6,*) iwest, ieast, MPI_PROC_NULL
call MPI_Finalize(ier)
end
% mpif90 x.f90
% mpirun -n 4 ./a.out
1 -2 -2
-2 2 -2
-2 3 -2
0 -2 -2