-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTask_16.cpp
35 lines (28 loc) · 1.16 KB
/
Task_16.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include "mpi.h"
int main(int argc, char **argv)
{
int rank, size, rank1;
MPI_Init(&argc, &argv);
MPI_Comm comm_revs;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_split(MPI_COMM_WORLD, 1, size - rank, &comm_revs);
MPI_Comm_rank(comm_revs, &rank1);
printf("color = %d; key = %d; rank = %d; rank1 = %d\n", 1, size - rank, rank, rank1);
MPI_Comm_free(&comm_revs);
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0) printf("---------------------------------------\n");
MPI_Comm_split(MPI_COMM_WORLD, rank % 2, size - rank, &comm_revs);
MPI_Comm_rank(comm_revs, &rank1);
printf("color = %d; key = %d; rank = %d; rank1 = %d\n", rank % 2, size - rank, rank, rank1);
MPI_Comm_free(&comm_revs);
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0) printf("---------------------------------------\n");
MPI_Comm_split(MPI_COMM_WORLD, rank % 3, size - rank, &comm_revs);
MPI_Comm_rank(comm_revs, &rank1);
printf("color = %d; key = %d; rank = %d; rank1 = %d\n", rank % 3, size - rank, rank, rank1);
MPI_Comm_free(&comm_revs);
MPI_Barrier(MPI_COMM_WORLD);
if (rank == 0) printf("---------------------------------------\n");
MPI_Finalize();
}