1. Sending and Receiving Message
Sender Process
Receiver Process
2. Communication Envelope
Data
Envelope
MPI Data Type
1. MPI_Send()
Data
Envelope
2. MPI_Recv()
Data
MPI_Send()
의 count보다 MPI_Recv()
의 count가 적을 경우, 에러 발생 & truncateEnvelope
MPI_Send()
와 tag가 동일해야 함Status
3. Example
C code
#include <stdio.h>
#include "mpi.h"
int main(void)
{
int rank, i. count;
float data[100], value[200];
MPI_Status status;
MPI_Init(NULL, NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank==1){
for(i=0; i<100; ++i) data[i]=i;
MPI_Send(data,100,MPI_FLOAT, 0, 55, MPI_COMM_WORLD);
}
else {
MPI_Recv(value, 200, MPI_FLOAT, 1, 55, MPI_COMM_WORLD, &status);
printf("P:%d Got data from processor %d\n", rank, status.MPI_SOURCE);
MPI_Get_count(&status, MPI_FLOAT, &count);
printf("P:%d Got %d elements\n",rank, count);
printf("P:%d value[5]=%f\n", rank, value[5]);
}
MPI_Finalize();
return 0;
}
MPI_Send(data,100,MPI_FLOAT, 0, 55, MPI_COMM_WORLD)
: data 배열의 요소 100개 모두 rank 0 process에 전송else if(rank ==0)
으로 지정해주어야 함Result