| 1 |
/* |
| 2 |
* (C) Crown Copyright Met Office 2021 |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <array> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
#include "atlas/grid/detail/partitioner/Partitioner.h" |
| 17 |
|
| 18 |
namespace atlas { |
| 19 |
namespace grid { |
| 20 |
namespace detail { |
| 21 |
namespace partitioner { |
| 22 |
|
| 23 |
class CubedSpherePartitioner : public Partitioner { |
| 24 |
public: |
| 25 |
CubedSpherePartitioner(); |
| 26 |
|
| 27 |
CubedSpherePartitioner(int N); // N is the number of parts (aka MPI tasks) |
| 28 |
CubedSpherePartitioner(int N, const eckit::Parametrisation&); |
| 29 |
CubedSpherePartitioner(const eckit::Parametrisation&); |
| 30 |
|
| 31 |
CubedSpherePartitioner(const int N, const std::vector<int>& globalProcStartPE, |
| 32 |
const std::vector<int>& globalProcEndPE, const std::vector<int>& nprocx, |
| 33 |
const std::vector<int>& nprocy); |
| 34 |
|
| 35 |
CubedSpherePartitioner(const int N, const bool regularGrid); |
| 36 |
|
| 37 |
|
| 38 |
// Cell struct that holds the x and y and t indices |
| 39 |
// This could be replaced using the tij iterator that is part of the grid class |
| 40 |
struct CellInt { |
| 41 |
int x, y, t; |
| 42 |
int n; |
| 43 |
}; |
| 44 |
|
| 45 |
struct CubedSphere { |
| 46 |
std::array<atlas::idx_t, 6> nproc; |
| 47 |
std::array<atlas::idx_t, 6> nprocx; // number of PEs in the x direction of xy space on each tile. |
| 48 |
std::array<atlas::idx_t, 6> nprocy; // number of PEs in the y direction of xy space on each tile. |
| 49 |
std::array<atlas::idx_t, 6> globalProcStartPE; // lowest global mpi rank on each tile; |
| 50 |
std::array<atlas::idx_t, 6> globalProcEndPE; // final global mpi rank on each tile; |
| 51 |
// note that mpi ranks on each tile are vary contiguously from globalProcStartPE to |
| 52 |
// globalProcEndPE. |
| 53 |
|
| 54 |
// grid dimensions on each tile - for all cell-centered grids they will be same. |
| 55 |
std::array<atlas::idx_t, 6> nx; |
| 56 |
std::array<atlas::idx_t, 6> ny; |
| 57 |
|
| 58 |
// these are the offsets in the x and y directions |
| 59 |
// they are allocated in "void partition(CubedSphere& cb, int nb_nodes, CellInt nodes[], int part[] );" |
| 60 |
std::vector<std::vector<atlas::idx_t>> xoffset; |
| 61 |
std::vector<std::vector<atlas::idx_t>> yoffset; |
| 62 |
|
| 63 |
// the two variables below are for now the main options |
| 64 |
// in the future this will be extended |
| 65 |
std::array<atlas::idx_t, 6> startingCornerOnTile; |
| 66 |
// for now bottom left corner (0) default. |
| 67 |
// Could be configurable to top left (1), top right(2) bottom right(3) |
| 68 |
|
| 69 |
std::array<atlas::idx_t, 6> xFirst; // if 1 then x is leading index - if 0 y is leading index; |
| 70 |
|
| 71 |
CubedSphere() { |
| 72 |
nprocx = std::array<atlas::idx_t, 6>{1, 1, 1, 1, 1, 1}; |
| 73 |
nprocy = std::array<atlas::idx_t, 6>{1, 1, 1, 1, 1, 1}; |
| 74 |
startingCornerOnTile = std::array<atlas::idx_t, 6>{0, 0, 0, 0, 0, 0}; |
| 75 |
xFirst = std::array<atlas::idx_t, 6>{1, 1, 1, 1, 1, 1}; |
| 76 |
} |
| 77 |
}; |
| 78 |
|
| 79 |
CubedSphere cubedsphere(const Grid&) const; |
| 80 |
|
| 81 |
void partition(CubedSphere& cb, const int nb_nodes, const CellInt nodes[], int part[]) const; |
| 82 |
|
| 83 |
virtual std::string type() const { return "cubedsphere"; } |
| 84 |
|
| 85 |
private: |
| 86 |
using Partitioner::partition; |
| 87 |
virtual void partition(const Grid&, int part[]) const; |
| 88 |
|
| 89 |
void check() const; |
| 90 |
|
| 91 |
private: |
| 92 |
std::vector<atlas::idx_t> globalProcStartPE_{0, 0, 0, 0, 0, 0}; |
| 93 |
std::vector<atlas::idx_t> globalProcEndPE_{0, 0, 0, 0, 0, 0}; |
| 94 |
std::vector<atlas::idx_t> nprocx_{1, 1, 1, 1, 1, 1}; // number of ranks in x direction on each tile |
| 95 |
std::vector<atlas::idx_t> nprocy_{1, 1, 1, 1, 1, 1}; // number of ranks in x direction on each tile |
| 96 |
bool regular_ = true; // regular algorithm for partitioning. |
| 97 |
}; |
| 98 |
|
| 99 |
} // namespace partitioner |
| 100 |
} // namespace detail |
| 101 |
} // namespace grid |
| 102 |
} // namespace atlas |