| 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 |
#include <math.h> |
| 11 |
|
| 12 |
int coloring2D(int mypid, int ndx) { |
| 13 |
// INPUT: mypid is the MPI id of the processor |
| 14 |
// INPUT: ndx is the nuber of domains along x-direction |
| 15 |
// INPUT: ndy is the nuber of domains along y-direction |
| 16 |
// OUTPUT: color label associated with the current MPI processor (=subdomain) |
| 17 |
|
| 18 |
// detect the row of the domain grid where the current subdomain is located |
| 19 |
int grid_row = std::ceil(static_cast<double>(mypid) / ndx); |
| 20 |
|
| 21 |
// detect the y-coordinate in the domain grid associated with the current subdomain |
| 22 |
int ypos = grid_row % 3; |
| 23 |
int xpos; |
| 24 |
int color = -1; |
| 25 |
|
| 26 |
// detect the x-coordinate in the domain grid associated with current subdomain |
| 27 |
if (0 != mypid % ndx) |
| 28 |
xpos = static_cast<int>(mypid - std::floor(static_cast<double>(mypid) / ndx) * ndx) % 3; |
| 29 |
else |
| 30 |
xpos = (mypid - ((ypos - 1) * ndx)) % 3; |
| 31 |
|
| 32 |
// use x and y coordinates to determine the color of the current subdomain |
| 33 |
if (xpos > 0 && ypos > 0) |
| 34 |
color = (ypos - 1) * 3 + xpos; |
| 35 |
else if (xpos > 0 && ypos == 0) |
| 36 |
color = 6 + xpos; |
| 37 |
else if (xpos == 0 && ypos > 0) |
| 38 |
color = ypos * 3; |
| 39 |
else |
| 40 |
color = 9; |
| 41 |
|
| 42 |
// TEUCHOS_TEST_FOR_EXCEPT( color < 1 ); |
| 43 |
return color - 1; |
| 44 |
} |
| 45 |
|
| 46 |
int coloring3D(int mypid, int ndx, int ndy) { |
| 47 |
// INPUT: mypid is the MPI id of the processor |
| 48 |
// INPUT: ndx is the nuber of domains along x-direction |
| 49 |
// INPUT: ndy is the nuber of domains along y-direction |
| 50 |
// OUTPUT: color label associated with the current MPI processor (=subdomain) |
| 51 |
|
| 52 |
// detect the plane of the domain grid where the current subdomain resides |
| 53 |
int grid_plane = std::ceil(static_cast<double>(mypid) / (ndx * ndy)); |
| 54 |
|
| 55 |
// On the given plane, find the local id of the current subdomain |
| 56 |
int plane_id = mypid % (ndx * ndy); |
| 57 |
|
| 58 |
// detect the row on the current two-dimensional grid where the current subdomain is located |
| 59 |
int plane_row = std::ceil(static_cast<double>(plane_id) / ndx); |
| 60 |
|
| 61 |
// detect the y-coordinate on the given plane associated with the current subdomain |
| 62 |
int ypos = plane_row % 3; |
| 63 |
int xpos; |
| 64 |
int label_plane; |
| 65 |
int color = -1; |
| 66 |
|
| 67 |
// detect the x-coordinate on the given plane associated with the current subdomain |
| 68 |
if (0 != plane_id % ndx) |
| 69 |
xpos = static_cast<int>(mypid - std::floor(static_cast<double>(plane_id) / ndx) * ndx) % 3; |
| 70 |
else |
| 71 |
xpos = (plane_id - ((ypos - 1) * ndx)) % 3; |
| 72 |
|
| 73 |
// find a two-dimensional coloring to give to the current subdomain according to its position |
| 74 |
// in the plane where it resides |
| 75 |
if (xpos > 0 && ypos > 0) |
| 76 |
label_plane = (ypos - 1) * 3 + xpos; |
| 77 |
else if (xpos > 0 && ypos == 0) |
| 78 |
label_plane = 6 + xpos; |
| 79 |
else if (xpos == 0 && ypos > 0) |
| 80 |
label_plane = ypos * 3; |
| 81 |
else |
| 82 |
label_plane = 9; |
| 83 |
|
| 84 |
// use the two-dimensional coloring to determine the three-dimensional coloring |
| 85 |
if (grid_plane % 3 == 1) |
| 86 |
color = label_plane; |
| 87 |
|
| 88 |
else if (grid_plane % 3 == 2) |
| 89 |
color = 9 + label_plane; |
| 90 |
|
| 91 |
else if (grid_plane % 3 == 0) |
| 92 |
color = 18 + label_plane; |
| 93 |
|
| 94 |
// TEUCHOS_TEST_FOR_EXCEPT( color < 1 ); |
| 95 |
return color - 1; |
| 96 |
} |