| 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 "DistributionImpl.h" |
| 12 |
|
| 13 |
#include <algorithm> |
| 14 |
|
| 15 |
#include "atlas/grid/Distribution.h" |
| 16 |
#include "atlas/grid/Grid.h" |
| 17 |
#include "atlas/grid/Partitioner.h" |
| 18 |
#include "atlas/grid/detail/distribution/DistributionArray.h" |
| 19 |
#include "atlas/runtime/Exception.h" |
| 20 |
|
| 21 |
namespace atlas { |
| 22 |
namespace grid { |
| 23 |
|
| 24 |
DistributionImpl* atlas__GridDistribution__new(idx_t size, int part[], int part0) { |
| 25 |
return new detail::distribution::DistributionArray(0, size, part, part0); |
| 26 |
} |
| 27 |
|
| 28 |
void atlas__GridDistribution__delete(DistributionImpl* This) { |
| 29 |
delete This; |
| 30 |
} |
| 31 |
|
| 32 |
void atlas__GridDistribution__nb_pts(DistributionImpl* This, idx_t nb_pts[]) { |
| 33 |
const auto& nb_pts_ = This->nb_pts(); |
| 34 |
std::copy(nb_pts_.begin(), nb_pts_.end(), &nb_pts[0]); |
| 35 |
} |
| 36 |
|
| 37 |
idx_t atlas__atlas__GridDistribution__nb_partitions(DistributionImpl* This) { |
| 38 |
return This->nb_partitions(); |
| 39 |
} |
| 40 |
|
| 41 |
int atlas__GridDistribution__partition_int32(DistributionImpl* dist, int i) { |
| 42 |
return dist->partition(i); |
| 43 |
} |
| 44 |
|
| 45 |
int atlas__GridDistribution__partition_int64(DistributionImpl* dist, long i) { |
| 46 |
return dist->partition(i); |
| 47 |
} |
| 48 |
|
| 49 |
DistributionImpl* atlas__GridDistribution__new__Grid_Config(const detail::grid::Grid* grid, |
| 50 |
const eckit::Parametrisation* config) { |
| 51 |
ATLAS_ASSERT(grid != nullptr, "grid is an invalid pointer"); |
| 52 |
ATLAS_ASSERT(config != nullptr, "config is an invalid pointer"); |
| 53 |
DistributionImpl* distribution; |
| 54 |
{ |
| 55 |
Distribution d{Grid{grid}, *config}; |
| 56 |
distribution = d.get(); |
| 57 |
distribution->attach(); |
| 58 |
} |
| 59 |
distribution->detach(); |
| 60 |
return distribution; |
| 61 |
} |
| 62 |
|
| 63 |
DistributionImpl* atlas__GridDistribution__new__Grid_Partitioner(const detail::grid::Grid* grid, |
| 64 |
const detail::partitioner::Partitioner* partitioner) { |
| 65 |
ATLAS_ASSERT(grid != nullptr, "grid is an invalid pointer"); |
| 66 |
ATLAS_ASSERT(partitioner != nullptr, "partitioner is an invalid pointer"); |
| 67 |
DistributionImpl* distribution; |
| 68 |
{ |
| 69 |
Distribution d{Grid{grid}, Partitioner{partitioner}}; |
| 70 |
distribution = d.get(); |
| 71 |
distribution->attach(); |
| 72 |
} |
| 73 |
distribution->detach(); |
| 74 |
return distribution; |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
} // namespace grid |
| 79 |
} // namespace atlas |