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