Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "mpi.h"
- using namespace std;
- int main(int argc, char **argv) {
- setlocale(LC_ALL, "rus");
- int rank, size;
- MPI_Init(&argc, &argv);
- MPI_Comm_rank(MPI_COMM_WORLD, &rank);
- MPI_Comm_size(MPI_COMM_WORLD, &size);
- if (size == 1) {
- cout << "Число потоков должно быть строго больше 1" << endl;
- MPI_Finalize();
- return 0;
- }
- int message = rank;
- MPI_Status status;
- if (!(rank % 2)) {
- if (rank < size - 1)
- MPI_Send(&message, 1, MPI_INT, rank + 1, 0, MPI_COMM_WORLD);
- } else {
- MPI_Recv(&message, 1, MPI_INT, rank - 1, 0, MPI_COMM_WORLD, &status);
- cout << "Сообщение " << message << " принято от " << rank - 1 <<
- "-го потока" << endl;
- }
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement