MPI通信,的确存在通信的启动时间。 #include "mpi.h" #include <stdio.h> #include <stdlib.h> #include <time.h> #include <string.h> int main(int argc, char **argv) { int i, myid, other, numprocs; double start, end; MPI_Status status; MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &myid); MPI_Comm_size(MPI_COMM_WORLD, &numprocs); int N = 1024; int *buf = (int *)malloc(sizeof(int) * (N + 1)); if (buf == NULL) printf("Not enouth memory!/n"); for (i = 0; i < N; i++){ buf[i] = myid + i; } if(myid == 0) other = 1; if(myid == 1) other = 0; start = MPI_Wtime(); if(myid == 0) MPI_Send(buf, N, MPI_INT, other, 99, MPI_COMM_WORLD); else MPI_Recv(buf, N, MPI_INT, other, 99, MPI_COMM_WORLD, &status); end = MPI_Wtime(); if(myid == 1) printf("case 1: %f/n", end - start); start = MPI_Wtime(); i = N; while (i--) { if(myid == 0) MPI_Send(&buf[i], 1, MPI_INT, other, 99, MPI_COMM_WORLD); else MPI_Recv(&buf[i], 1, MPI_INT, other, 99, MPI_COMM_WORLD, &status); } end = MPI_Wtime(); if(myid == 1) printf("case 2: %f/n", end - start); free(buf); buf = NULL; //printf("process %d freeing memory.../n",myid); MPI_Finalize(); } result: [root@c0108 zlt]# mpicc comm.c -o comm [root@c0108 zlt]# mpiexec -n 2 ./comm case 1: 0.002562 case 2: 0.004875