scatter.c_职场#include<stdio.h>
scatter.c_职场#include<mpi.h>
scatter.c_职场
scatter.c_职场#define SIZE 4
scatter.c_职场
scatter.c_职场int main(int argc, char *argv[]){
scatter.c_职场  int numTasks, rank, sendCount, recvCount, source;
scatter.c_职场  float sendBuf[SIZE][SIZE] = {
scatter.c_职场    {1.0, 2.0, 3.0, 4.0},
scatter.c_职场    {5.0, 6.0, 7.0, 8.0},
scatter.c_职场    {9.0, 10.0, 11.0, 12.0},
scatter.c_职场    {13.0, 14,0, 15.0, 16.0} };
scatter.c_职场    
scatter.c_职场  float recvBuf[SIZE];
scatter.c_职场
scatter.c_职场  MPI_Init(&argc, &argv);
scatter.c_职场  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
scatter.c_职场  MPI_Comm_size(MPI_COMM_WORLD, &numTasks);
scatter.c_职场
scatter.c_职场  if(numTasks == SIZE){
scatter.c_职场    source = 1;
scatter.c_职场    sendCount = SIZE;
scatter.c_职场    recvCount = SIZE;
scatter.c_职场    
scatter.c_职场    MPI_Scatter(sendBuf, sendCount, MPI_FLOAT, recvBuf,    
scatter.c_职场             recvCount, MPI_FLOAT, source, MPI_COMM_WORLD);
scatter.c_职场
scatter.c_职场    printf("rank = %d, Results: %f %f %f %f\n", rank,
scatter.c_职场             recvBuf[0], recvBuf[1], recvBuf[2], recvBuf[3]);
scatter.c_职场  }else{
scatter.c_职场    printf("Must specify %d processors. Terminating.\n", SIZE);
scatter.c_职场  }
scatter.c_职场
scatter.c_职场              MPI_Finalize();
scatter.c_职场  return 0;
scatter.c_职场}