| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 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 |
#include <sstream> |
| 12 |
|
| 13 |
#include "atlas/array.h" |
| 14 |
#include "atlas/grid/Grid.h" |
| 15 |
#include "atlas/grid/detail/partitioner/EqualRegionsPartitioner.h" |
| 16 |
#include "atlas/grid/detail/partitioner/TransPartitioner.h" |
| 17 |
#include "atlas/option/TransOptions.h" |
| 18 |
#include "atlas/parallel/mpi/mpi.h" |
| 19 |
#include "atlas/runtime/Exception.h" |
| 20 |
#include "atlas/runtime/Trace.h" |
| 21 |
#include "atlas/trans/ifs/TransIFS.h" |
| 22 |
|
| 23 |
namespace atlas { |
| 24 |
namespace grid { |
| 25 |
namespace detail { |
| 26 |
namespace partitioner { |
| 27 |
|
| 28 |
TransPartitioner::TransPartitioner(): Partitioner() { |
| 29 |
} |
| 30 |
|
| 31 |
TransPartitioner::TransPartitioner(const eckit::Parametrisation& config): Partitioner(config) { |
| 32 |
} |
| 33 |
|
| 34 |
TransPartitioner::TransPartitioner(const idx_t N, const eckit::Parametrisation& config): Partitioner(N,config) { |
| 35 |
} |
| 36 |
|
| 37 |
TransPartitioner::~TransPartitioner() = default; |
| 38 |
|
| 39 |
void TransPartitioner::partition(const Grid& grid, int part[]) const { |
| 40 |
ATLAS_TRACE("TransPartitioner::partition"); |
| 41 |
|
| 42 |
StructuredGrid g(grid); |
| 43 |
if (not g) { |
| 44 |
throw_Exception("Grid is not a grid::Structured type. Cannot partition using IFS trans", Here()); |
| 45 |
} |
| 46 |
|
| 47 |
trans::TransIFS t(grid, option::split_y(split_y_)); |
| 48 |
if (nb_partitions() != idx_t(t.nproc())) { |
| 49 |
std::stringstream msg; |
| 50 |
msg << "Requested to partition grid with TransPartitioner in " << nb_partitions() |
| 51 |
<< " partitions, but " |
| 52 |
"the internal Trans library could only be set-up for " |
| 53 |
<< t.nproc() |
| 54 |
<< " partitions " |
| 55 |
"(equal to number of MPI tasks in communicator)."; |
| 56 |
throw_Exception(msg.str(), Here()); |
| 57 |
} |
| 58 |
|
| 59 |
int nlonmax = g.nxmax(); |
| 60 |
|
| 61 |
array::LocalView<int, 1> nloen = t.nloen(); |
| 62 |
array::LocalView<int, 1> n_regions = t.n_regions(); |
| 63 |
array::LocalView<int, 1> nfrstlat = t.nfrstlat(); |
| 64 |
array::LocalView<int, 1> nlstlat = t.nlstlat(); |
| 65 |
array::LocalView<int, 1> nptrfrstlat = t.nptrfrstlat(); |
| 66 |
array::LocalView<int, 2> nsta = t.nsta(); |
| 67 |
array::LocalView<int, 2> nonl = t.nonl(); |
| 68 |
|
| 69 |
int i(0); |
| 70 |
int maxind(0); |
| 71 |
std::vector<int> iglobal(t.ndgl() * nlonmax, -1); |
| 72 |
|
| 73 |
for (int jgl = 0; jgl < t.ndgl(); ++jgl) { |
| 74 |
for (int jl = 0; jl < nloen(jgl); ++jl) { |
| 75 |
++i; |
| 76 |
iglobal[jgl * nlonmax + jl] = i; |
| 77 |
maxind = std::max(maxind, jgl * nlonmax + jl); |
| 78 |
} |
| 79 |
} |
| 80 |
int iproc(0); |
| 81 |
for (int ja = 0; ja < t.n_regions_NS(); ++ja) { |
| 82 |
for (int jb = 0; jb < n_regions(ja); ++jb) { |
| 83 |
for (int jgl = nfrstlat(ja) - 1; jgl < nlstlat(ja); ++jgl) { |
| 84 |
int igl = nptrfrstlat(ja) + jgl - nfrstlat(ja); |
| 85 |
for (int jl = nsta(jb, igl) - 1; jl < nsta(jb, igl) + nonl(jb, igl) - 1; ++jl) { |
| 86 |
idx_t ind = iglobal[jgl * nlonmax + jl] - 1; |
| 87 |
if (ind >= grid.size()) { |
| 88 |
throw_OutOfRange("part", ind, grid.size(), Here()); |
| 89 |
} |
| 90 |
part[ind] = iproc; |
| 91 |
} |
| 92 |
} |
| 93 |
++iproc; |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
} // namespace partitioner |
| 99 |
} // namespace detail |
| 100 |
} // namespace grid |
| 101 |
} // namespace atlas |
| 102 |
|
| 103 |
namespace { |
| 104 |
atlas::grid::detail::partitioner::PartitionerBuilder<atlas::grid::detail::partitioner::TransPartitioner> __ecTrans( |
| 105 |
"ectrans"); |
| 106 |
atlas::grid::detail::partitioner::PartitionerBuilder<atlas::grid::detail::partitioner::TransPartitioner> __Trans( |
| 107 |
"trans"); |
| 108 |
atlas::grid::detail::partitioner::PartitionerBuilder<atlas::grid::detail::partitioner::TransPartitioner> __TransIFS( |
| 109 |
"ifs"); |
| 110 |
} // namespace |