Debian Codegraph @

src/atlas/grid/detail/partitioner/CheckerboardPartitioner.h

raw
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 #pragma once
12
13 #include <vector>
14 #include <array>
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 CheckerboardPartitioner : public Partitioner {
24 public:
25 CheckerboardPartitioner();
26
27 // CheckerboardPartitioner(int N); // N is the number of parts (aka MPI tasks)
28 CheckerboardPartitioner(int N, const eckit::Parametrisation&);
29
30 CheckerboardPartitioner(int N, int nbands);
31 CheckerboardPartitioner(int N, int nbands, bool checkerboard);
32
33 CheckerboardPartitioner(const eckit::Parametrisation&);
34
35 // Node struct that holds the x and y indices (for global, it's longitude and
36 // latitude in millidegrees (integers))
37 // This structure is used in sorting algorithms, and uses less memory than
38 // if x and y were in double precision.
39 struct NodeInt {
40 int x, y;
41 int n;
42 };
43
44 virtual std::string type() const { return "checkerboard"; }
45
46 std::array<int,2> checkerboardDimensions(const Grid&);
47
48 private:
49 struct Checkerboard {
50 idx_t nbands; // number of bands
51 idx_t nx, ny; // grid dimensions
52 };
53
54 Checkerboard checkerboard(const Grid&) const;
55
56 // Doesn't matter if nodes[] is in degrees or radians, as a sorting
57 // algorithm is used internally
58 void partition(const Checkerboard& cb, int nb_nodes, NodeInt nodes[], int part[]) const;
59
60 using Partitioner::partition;
61 virtual void partition(const Grid&, int part[]) const;
62
63 void check() const;
64
65 private:
66 idx_t nbands_ = 0; // number of bands from configuration
67 bool regular_ = false;
68 bool split_x_ = true;
69 bool split_y_ = true;
70 bool checkerboard_ = true; // exact (true) or approximate (false) checkerboard
71 };
72
73 } // namespace partitioner
74 } // namespace detail
75 } // namespace grid
76 } // namespace atlas