Sorry there was a mistake in that code, stypes and rtypes should be of type MPI_Datatype not integer however the result is the same.
*** An error occurred in MPI_Alltoallw *** reported by process [204406785,1] *** on communicator MPI_COMM_WORLD *** MPI_ERR_TYPE: invalid datatype On Tue, Jan 12, 2016 at 7:55 PM, Jim Edwards <jedwa...@ucar.edu> wrote: > Maybe the example is too simple. Here is another one which > when run on two tasks sends two integers from each task to > task 0. Task 1 receives nothing. This works with mpich and impi > but fails with openmpi. > > #include <stdio.h> > #include <mpi.h> > > my_mpi_test(int rank, int ntasks) > { > MPI_Datatype stype, rtype; > int sbuf[2]; > int rbuf[4]; > > int slen[ntasks], sdisp[ntasks], stypes[ntasks], rlen[ntasks], > rdisp[ntasks], rtypes[ntasks]; > sbuf[0]=rank; > sbuf[1]=ntasks+rank; > slen[0]=2; > slen[1]=0; > stypes[0]=MPI_INT; > stypes[1]=MPI_DATATYPE_NULL; > sdisp[0]=0; > sdisp[1]=4; > if(rank==0){ > rlen[0]=2; > rlen[1]=2; > rtypes[0]=MPI_INT; > rtypes[1]=MPI_INT; > rdisp[0]=0; > rdisp[1]=8; > > }else{ > rlen[0]=0; > rlen[1]=0; > rtypes[0]=MPI_DATATYPE_NULL; > rtypes[1]=MPI_DATATYPE_NULL; > rdisp[0]=0; > rdisp[1]=0; > } > > MPI_Alltoallw(sbuf, slen, sdisp, stypes, rbuf, rlen, rdisp, rtypes, > MPI_COMM_WORLD); > if(rank==0){ > printf("%d %d %d %d\n",rbuf[0],rbuf[1],rbuf[2],rbuf[3]); > } > > int main(int argc, char **argv) > { > int rank, ntasks; > > MPI_Init(&argc, &argv); > > MPI_Comm_rank(MPI_COMM_WORLD,&rank); > MPI_Comm_size(MPI_COMM_WORLD, &ntasks); > > printf("rank %d ntasks %d\n",rank, ntasks); > > my_mpi_test(rank,ntasks); > > > MPI_Finalize(); > } > > > > -- Jim Edwards CESM Software Engineer National Center for Atmospheric Research Boulder, CO