MCSclimate / MCT

Model Coupling Tookit
Other
43 stars 18 forks source link

Bug in irecv for derived datatypes #53

Closed jedwards4b closed 6 years ago

jedwards4b commented 6 years ago

The following demonstrates a bug in using mpi derived types in the receive buffer, this is showing up when running (cesm) cam-se using mpi-serial. @gold2718 reported to pio, but it's an mpi-serial bug. Run using mpi on a single processor the result is: -1 0 -1 1 -1 2 -1 3

however with mpi-serial the derived type is not respected and you get 0 1 2 3 -1 -1 -1 -1

#include <stdio.h>
#include <mpi.h>

int main(int argc, char **argv)
{
  int mpierr;
  int blocksize=1;
  int len=4;
  int displace[len];
  MPI_Datatype mtype;
  int sbuf[8];
  int rbuf[8];
  int i;
  MPI_Request rcvid;
  MPI_Status status;

  mpierr = MPI_Init(&argc, &argv);

  for (i=0;i<8;i++){
    sbuf[i] = i;
  }
  for (i=0;i<8;i++){
    rbuf[i] = -1;
  }
  for (i=0;i<len;i++)
    displace[i]=1+i*2;

  mpierr = MPI_Type_create_indexed_block(len, blocksize, displace,
                     MPI_INT, &mtype);
  mpierr = MPI_Type_commit(&mtype);

  mpierr = MPI_Irecv(rbuf, 1, mtype,
             0, 1, MPI_COMM_WORLD, &rcvid);
  mpierr = MPI_Send(sbuf, 4, MPI_INT,
            0, 1, MPI_COMM_WORLD);

  mpierr = MPI_Wait(&rcvid, &status);

  for (i=0;i<8;i++)
    printf(" %d",rbuf[i]);
  printf("\n");

  mpierr = MPI_Finalize();

}
gold2718 commented 6 years ago

Moved to MCSclimate/mpi-serial#11