| 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 |
|
| 12 |
#include "BandsPartitioner.h" |
| 13 |
|
| 14 |
#include <cstdint> |
| 15 |
|
| 16 |
#include "atlas/grid/StructuredGrid.h" |
| 17 |
#include "atlas/grid/detail/distribution/BandsDistribution.h" |
| 18 |
#include "atlas/runtime/Exception.h" |
| 19 |
|
| 20 |
namespace atlas { |
| 21 |
namespace grid { |
| 22 |
namespace detail { |
| 23 |
namespace partitioner { |
| 24 |
|
| 25 |
size_t BandsPartitioner::blocksize(const Grid& grid) const { |
| 26 |
if (blocksize_ == BLOCKSIZE_NX) { |
| 27 |
if (auto regular = RegularGrid(grid)) { |
| 28 |
return regular.nx(); |
| 29 |
} |
| 30 |
return 1; |
| 31 |
} |
| 32 |
ATLAS_ASSERT(blocksize_ > 0); |
| 33 |
return size_t(blocksize_); |
| 34 |
} |
| 35 |
|
| 36 |
BandsPartitioner::BandsPartitioner( const eckit::Parametrisation& config): Partitioner(config), blocksize_{1} {} |
| 37 |
|
| 38 |
BandsPartitioner::BandsPartitioner(int N, int blocksize, const eckit::Parametrisation& config): Partitioner(N, config), blocksize_(blocksize) {} |
| 39 |
|
| 40 |
Distribution BandsPartitioner::partition(const Partitioner::Grid& grid) const { |
| 41 |
if (not distribution::BandsDistribution<int32_t>::detectOverflow(grid.size(), nb_partitions(), blocksize((grid)))) { |
| 42 |
return Distribution{ |
| 43 |
new distribution::BandsDistribution<int32_t>{grid, nb_partitions(), type(), blocksize(grid)}}; |
| 44 |
} |
| 45 |
else { |
| 46 |
return Distribution{ |
| 47 |
new distribution::BandsDistribution<int64_t>{grid, nb_partitions(), type(), blocksize(grid)}}; |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
void BandsPartitioner::partition(const Partitioner::Grid& grid, int part[]) const { |
| 52 |
gidx_t gridsize = grid.size(); |
| 53 |
if (not distribution::BandsDistribution<int32_t>::detectOverflow(grid.size(), nb_partitions(), blocksize((grid)))) { |
| 54 |
distribution::BandsDistribution<int32_t> distribution{grid, nb_partitions(), type(), blocksize(grid)}; |
| 55 |
for (gidx_t n = 0; n < gridsize; ++n) { |
| 56 |
part[n] = distribution.function(n); |
| 57 |
} |
| 58 |
} |
| 59 |
else { |
| 60 |
distribution::BandsDistribution<int64_t> distribution{grid, nb_partitions(), type(), blocksize(grid)}; |
| 61 |
for (gidx_t n = 0; n < gridsize; ++n) { |
| 62 |
part[n] = distribution.function(n); |
| 63 |
} |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
} // namespace partitioner |
| 68 |
} // namespace detail |
| 69 |
} // namespace grid |
| 70 |
} // namespace atlas |
| 71 |
|
| 72 |
namespace { |
| 73 |
atlas::grid::detail::partitioner::PartitionerBuilder<atlas::grid::detail::partitioner::BandsPartitioner> __Bands( |
| 74 |
atlas::grid::detail::partitioner::BandsPartitioner::static_type()); |
| 75 |
} |