进程0向进程1发送值: 42
进程0向进程2发送值: 42
进程0向进程3发送值: 42
进程0向进程4发送值: 42
进程0向进程5发送值: 42
进程1收到的数据是: 42
进程2收到的数据是: 42
进程3收到的数据是: 42
进程5收到的数据是: 42
进程4收到的数据是: 42
#include <mpi.h>
#include <stdio.h>int main(int argc, char** argv) {int process_Rank, size_Of_Cluster, message_Item;MPI_Init(&argc, &argv);MPI_Comm_size(MPI_COMM_WORLD, &size_Of_Cluster);MPI_Comm_rank(MPI_COMM_WORLD, &process_Rank);if (process_Rank == 0) {message_Item = 42;for (int i = 1; i < size_Of_Cluster; i++) {MPI_Send(&message_Item, 1, MPI_INT, i, 1, MPI_COMM_WORLD);printf("进程0向进程%d发送值: %d\n", i, message_Item);}} else {MPI_Recv(&message_Item, 1, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUS_IGNORE);printf("进程%d收到的数据是: %d\n", process_Rank, message_Item);}MPI_Barrier(MPI_COMM_WORLD);MPI_Finalize();return 0;
}