-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMPI5Comm23.cpp
More file actions
46 lines (39 loc) · 906 Bytes
/
MPI5Comm23.cpp
File metadata and controls
46 lines (39 loc) · 906 Bytes
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
36
37
38
39
40
41
42
43
44
45
46
#include "pt4.h"
#include "mpi.h"
void Solve()
{
Task("MPI5Comm23");
int flag;
MPI_Initialized(&flag);
if (flag == 0)
return;
int rank, size;
MPI_Comm_size(MPI_COMM_WORLD, &size);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
int m = 0, n = 0, x = 0, y = 0;
if (rank == 0)
{
pt >> m;
pt >> n;
}
MPI_Bcast(&m, 1, MPI_INT, 0, MPI_COMM_WORLD);
MPI_Bcast(&n, 1, MPI_INT, 0, MPI_COMM_WORLD);
if (rank < m * n)
{
pt >> x;
pt >> y;
}
MPI_Comm comm_cart;
int dims[2] = { m, n };
int periods[2] = { 1, 0 };
MPI_Cart_create(MPI_COMM_WORLD, 2, dims, periods, 0, &comm_cart);
if (comm_cart != MPI_COMM_NULL)
{
int coords[] = { x, y };
int rank = 0;
if (MPI_Cart_rank(comm_cart, coords, &rank))
pt << -1;
else
pt << rank;
}
}