-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMPIUtil.cpp
More file actions
65 lines (49 loc) · 1.58 KB
/
MPIUtil.cpp
File metadata and controls
65 lines (49 loc) · 1.58 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include "MPIUtil.h"
/** Default/Main constructor */
MPIUtil::MPIUtil() {
MPI_Comm_size(MPI_COMM_WORLD, &np);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
nps.realloc(DIM);
for (int l = 0; l < DIM; ++l) {
nps[l] = 0; // TODO: Must be 0 before sending to MPI_Dims_create
}
MPI_Dims_create(np, DIM, nps.data());
int periods[DIM];
for (int l = 0; l < DIM; ++l) {
periods[l] = 1;
}
MPI_Cart_create(MPI_COMM_WORLD, DIM, nps.data(), periods, 1, &cartComm);
coords.realloc(DIM);
MPI_Cart_coords(cartComm, rank, DIM, coords.data());
neighbors.realloc(N_FACES);
for (int l = 0; l < DIM; ++l) {
// Gives the address of where to send and receive MPI calls
MPI_Cart_shift(cartComm, l, 1, &neighbors(2*l), &neighbors(2*l+1));
}
tags.realloc(N_FACES);
for (int iF = 0; iF < N_FACES; ++iF) {
tags(iF) = ((iF % 2) == 0 ? iF+1 : iF-1);
}
}
/** Initialize MPI_FACE for use in further MPI sends/recvs */
void MPIUtil::initDatatype(int nodesPerFace) {
MPI_Type_contiguous(nodesPerFace, MPI_DOUBLE, &MPI_FACE);
MPI_Type_commit(&MPI_FACE);
}
/* Map MPI faces to the first MPIUtil::N_FACES faces in 3D */
void MPIUtil::initFaces(int meshDim) {
faceMap.realloc(N_FACES);
for (int l = 0; l < N_FACES; ++l) {
faceMap(l) = meshDim - N_FACES + l;
}
}
/** MPI helper function to print out a string */
void MPIUtil::printString(const std::string& toPrint) const {
for (int ir = 0; ir < np; ++ir) {
MPI_Barrier(cartComm);
if (rank == ir) {
std::cout << rank << ": " << toPrint << std::endl;
}
}
MPI_Barrier(cartComm);
}