| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
void createBrickMap1D(int numGlobalElements, std::vector<int>& ind, Teuchos::RCP<const Teuchos::Comm<int> > comm) { |
| 11 |
// INPUT: numGlobalElements = number of finite difference nodes along x |
| 12 |
// INPUT: ind = vector containing indices of the rows owned by the current MPI processor |
| 13 |
// INPUT: comm = MPI communicator (MPI_COMM_WORLD) |
| 14 |
|
| 15 |
int mypid = comm->getRank(); |
| 16 |
|
| 17 |
ind.reserve(static_cast<int>(numGlobalElements / (comm->getSize() - 1) + 1)); |
| 18 |
if (mypid != 0 && mypid != comm->getSize() - 1) |
| 19 |
for (int i = 0; i <= (static_cast<int>(numGlobalElements / (comm->getSize() - 1))) - 1; ++i) |
| 20 |
ind.emplace_back((mypid - 1) * static_cast<int>(numGlobalElements / (comm->getSize() - 1)) + i); |
| 21 |
|
| 22 |
if (mypid == comm->getSize() - 1) |
| 23 |
for (int i = (mypid - 1) * static_cast<int>(numGlobalElements / (comm->getSize() - 1)); i != numGlobalElements; ++i) |
| 24 |
ind.emplace_back(i); |
| 25 |
} |
| 26 |
|
| 27 |
void createBrickMap2D(int nx, int brick_sizex, int brick_sizey, std::vector<int>& ind, Teuchos::RCP<const Teuchos::Comm<int> > comm) { |
| 28 |
// INPUT: nx = number of finite difference nodes along x |
| 29 |
// INPUT: brick_sizex = size of a brick aggregate along x-direction |
| 30 |
// INPUT: brick_sizey = size of a brick aggregate along y-direction |
| 31 |
// INPUT: ind = vector containing indices of the rows owned by the current MPI processor |
| 32 |
// INPUT: comm = MPI communicator (MPI_COMM_WORLD) |
| 33 |
|
| 34 |
int mypid = comm->getRank(); |
| 35 |
|
| 36 |
ind.reserve(brick_sizex * brick_sizey); |
| 37 |
|
| 38 |
int ndx = nx / brick_sizex; |
| 39 |
|
| 40 |
if (mypid != 0) { |
| 41 |
int grid_row = std::ceil(static_cast<double>(mypid) / ndx); |
| 42 |
int ypos = grid_row; |
| 43 |
int xpos; |
| 44 |
|
| 45 |
if (0 != mypid % ndx) |
| 46 |
xpos = mypid % ndx; |
| 47 |
else |
| 48 |
xpos = ndx; |
| 49 |
|
| 50 |
int preliminary = nx * brick_sizey * (ypos - 1); |
| 51 |
|
| 52 |
for (int row = 0; row < brick_sizey; ++row) |
| 53 |
for (int col = brick_sizex * (xpos - 1) + 1; col <= brick_sizex * xpos; ++col) |
| 54 |
ind.emplace_back(preliminary + row * nx + col - 1); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
void createBrickMap3D(int nx, int ny, int brick_sizex, int brick_sizey, int brick_sizez, std::vector<int>& ind, Teuchos::RCP<const Teuchos::Comm<int> > comm) { |
| 59 |
// INPUT: nx = number of finite difference nodes along x |
| 60 |
// INPUT: ny = number of finite difference nodes along y |
| 61 |
// INPUT: brick_sizex = size of a brick aggregate along x-direction |
| 62 |
// INPUT: brick_sizey = size of a brick aggregate along y-direction |
| 63 |
// INPUT: ind = vector containing indices of the rows owned by the current MPI processor |
| 64 |
// INPUT: comm = MPI communicator (MPI_COMM_WORLD) |
| 65 |
|
| 66 |
int mypid = comm->getRank(); |
| 67 |
|
| 68 |
ind.reserve(brick_sizex * brick_sizey * brick_sizez); |
| 69 |
|
| 70 |
// determine the number of subdomains along x and y directions |
| 71 |
int ndx = nx / brick_sizex; |
| 72 |
int ndy = ny / brick_sizey; |
| 73 |
|
| 74 |
if (mypid != 0) { |
| 75 |
int grid_plane = std::ceil(static_cast<double>(mypid) / (ndx * ndy)); |
| 76 |
int plane_id = mypid % (ndx * ndy); |
| 77 |
|
| 78 |
if (0 == plane_id) |
| 79 |
plane_id = ndx * ndy; |
| 80 |
|
| 81 |
int plane_row = std::ceil(static_cast<double>(plane_id) / ndx); |
| 82 |
int ypos = plane_row; |
| 83 |
int xpos; |
| 84 |
|
| 85 |
if (0 != plane_id % ndx) |
| 86 |
xpos = plane_id % ndx; |
| 87 |
else |
| 88 |
xpos = ndx; |
| 89 |
|
| 90 |
int preliminary = nx * ny * brick_sizez * (grid_plane - 1) + nx * brick_sizey * (ypos - 1); |
| 91 |
|
| 92 |
for (int l = 0; l < brick_sizez; ++l) |
| 93 |
for (int row = 0; row < brick_sizey; ++row) |
| 94 |
for (int col = brick_sizex * (xpos - 1) + 1; col <= brick_sizex * xpos; ++col) |
| 95 |
ind.emplace_back(preliminary + l * nx * ny + row * nx + col - 1); |
| 96 |
} |
| 97 |
} |