芙蓉妹妹 - 云代码空间
——
#include<stdio.h> #include"mpi.h" int main(int argc, char **argv){ MPI_Comm comm = MPI_COMM_WORLD; int size ,rank; MPI_Status status; char str[100]; MPI_Init(&argc,&argv); MPI_Comm_size(comm,&size); MPI_Comm_rank(comm,&rank); if(rank == 0){ strcpy(str,"hello world"); printf("Process 0 send [%s] to process 1.\n",str); MPI_Send(str,strlen(str)+1,MPI_CHAR,1,99,comm); //发送的地址,消息长度,消息数据类型,接收进程号,消息标志,通信域 } else if (rank == 1){ MPI_Recv(str,100,MPI_CHAR,0,99,comm,&status); //存储消息的地址,接收的数量,消息数据类型,发送进程号,消息标志,通信域,接收状态 printf("Process 1 received message [%s] from Process 0.\n",str); } MPI_Finalize(); return 0; }