void t10(int argumentcount, char* argumentvector[]) {
MPI_Init(&argumentcount, &argumentvector);
int rank, num_process;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &num_process);
// Read the local value of the process
// local_value will hold a specific int for process 0, and another for process 1
int a = 1;
int b;
if (rank == 0) {
std::cout << "num_process=" << num_process << "\n";
std::cout << "rank=" << rank << "\n";
}
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0) {
// Here, enter the code for the first process :
// 1- Send the value to process 1
for (int i = 1; i < num_process;++i)
MPI_Send(&a, 1, MPI_INT, i, 0, MPI_COMM_WORLD);
//MPI_Send(&a, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
}
else if (rank > 0) {
// Here enter the code for the second process :
// 1- Receive the value from process 0 (in other_value)
MPI_Recv(&b, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
std::cout <<"rank=" << rank << ", b=" << b << "\n";
}
MPI_Finalize();
}
C++ MPI_Send MPI_Recv 一个数
于 2024-08-19 13:33:29 首次发布