Hello, Your syntax defining 'a' is not correct. This code works correctly.
program test use mpi integer :: ierr, myrank, a(2) = 0 call MPI_Init(ierr) call MPI_Comm_rank(MPI_COMM_WORLD,myrank,ierr) if (myrank == 0) then a(1) = 1 a(2) = 2 else a(1) = 3 a(2) = 4 endif call MPI_Allreduce(MPI_IN_PLACE,a,2,MPI_INTEGER,MPI_SUM,MPI_COMM_WORLD,ierr) write(*,*) myrank, a(:) call MPI_Finalize(ierr) end program test mpif90 test.f90 mpirun -np 2 a.out 0 4 6 1 4 6 T. Rosmond On Fri, 2013-09-06 at 21:27 -0400, Hugo Gagnon wrote: > Hello, > > I'm trying to run this bit of code: > > program test > use mpi > integer :: ierr, myrank, a(2) = 0 > call MPI_Init(ierr) > call MPI_Comm_rank(MPI_COMM_WORLD,myrank,ierr) > if (myrank == 0) a(1) = 1; a(2) = 2 > if (myrank == 1) a(1) = 3; a(2) = 4 > call > MPI_Allreduce(MPI_IN_PLACE,a,2,MPI_INTEGER,MPI_SUM,MPI_COMM_WORLD,ierr) > write(*,*) myrank, a(:) > call MPI_Finalize(ierr) > end program test > > but the output is not what I'd expect: > > $ openmpif90 test.f90 > $ openmpirun -np 2 a.out > 0 0 0 > 1 0 0 > > I tried a version without MPI_IN_PLACE and the call to MPI_Allreduce > works fine in that case. Am I doing something wrong with MPI_IN_PLACE? > I'm using OpenMPI 1.6.5 compiled with gcc 4.8.1 on Mac OS 10.8. > > Thanks,