📅  最后修改于: 2023-12-03 14:44:24.477000             🧑  作者: Mango
MPI Send is a function used in Message Passing Interface (MPI) programming to send messages to another process in a parallel computing environment. It is a blocking operation, meaning that the sender must wait until the message has been received by the recipient before continuing.
int MPI_Send(void* message, int count, MPI_Datatype datatype, int destination, int tag, MPI_Comm communicator)
#include <mpi.h>
#include <stdio.h>
int main(int argc, char** argv) {
int rank, size;
int message = 42;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);
if (rank == 0) {
MPI_Send(&message, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
printf("Sent message %d from rank 0 to rank 1.\n", message);
} else if (rank == 1) {
MPI_Recv(&message, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Received message %d at rank 1.\n", message);
}
MPI_Finalize();
return 0;
}
This program demonstrates sending a message from rank 0 to rank 1 using MPI_Send and MPI_Recv. The message is an integer with the value 42. The sender waits for the recipient to receive the message before continuing.
MPI Send is a key function in MPI programming for sending messages between processes. It is a blocking operation that waits for the recipient to receive the message before continuing. Understanding how to use MPI Send is essential for developing MPI programs that achieve high performance in parallel computing environments.