芙蓉妹妹 - 云代码空间
——
#include <stdio.h> #include "mpi.h" #include <malloc.h> int main(int argc, char ** argv){ int rank,size,rbuf[3],sbuf[3],i,j; MPI_Comm comm = MPI_COMM_WORLD; MPI_Status status;bu MPI_Init(&argc,&argv); MPI_Comm_size(comm, &size); MPI_Comm_rank(comm, &rank); printf("Process %d Befor change:\n",rank); for(i = 0;i< 3;i++){ sbuf[i] = rank*10 + i; printf(" %d",sbuf[i]); } putchar('\n'); MPI_Alltoall(sbuf,1,MPI_INT,rbuf,1,MPI_INT,comm); printf("Process %d After change:\n",rank); for(i = 0;i< 3;i++) printf(" %d",rbuf[i]); putchar('\n'); MPI_Barrier(comm); MPI_Finalize(); return 0; }