atlas
Partitioner.h
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 <string>
14 
15 #include "atlas/library/config.h"
16 #include "atlas/util/Config.h"
17 #include "atlas/util/Object.h"
18 
19 namespace atlas {
20 class Grid;
21 class Mesh;
22 class FunctionSpace;
23 namespace grid {
24 class Distribution;
25 } // namespace grid
26 } // namespace atlas
27 
28 namespace atlas {
29 namespace grid {
30 namespace detail {
31 namespace partitioner {
32 
33 class Partitioner : public util::Object {
34 public:
35  using Grid = atlas::Grid;
36 
37 public:
38  Partitioner();
39  Partitioner( const idx_t nb_partitions );
40  virtual ~Partitioner();
41 
42  virtual void partition( const Grid& grid, int part[] ) const = 0;
43 
44  virtual Distribution partition( const Grid& grid ) const;
45 
46  idx_t nb_partitions() const;
47 
48  virtual std::string type() const = 0;
49 
50 private:
51  idx_t nb_partitions_;
52 };
53 
54 // ------------------------------------------------------------------
55 
57 public:
58  using Grid = Partitioner::Grid;
59 
60 public:
65  static Partitioner* build( const std::string& );
66  static Partitioner* build( const std::string&, const idx_t nb_partitions );
67  static Partitioner* build( const std::string&, const idx_t nb_partitions, const eckit::Parametrisation& );
68 
72  static void list( std::ostream& );
73  static bool has( const std::string& name );
74 
75 private:
76  std::string name_;
77  virtual Partitioner* make() = 0;
78  virtual Partitioner* make( const idx_t nb_partitions ) = 0;
79  virtual Partitioner* make( const idx_t nb_partitions, const eckit::Parametrisation& ) = 0;
80 
81 protected:
82  PartitionerFactory( const std::string& );
83  virtual ~PartitionerFactory();
84 };
85 
86 // ------------------------------------------------------------------
87 
88 template <class T>
90  virtual Partitioner* make() { return new T(); }
91 
92  virtual Partitioner* make( const idx_t nb_partitions ) { return new T( nb_partitions ); }
93  virtual Partitioner* make( const idx_t nb_partitions, const eckit::Parametrisation& config ) {
94  return new T( nb_partitions, config );
95  }
96 
97 public:
98  PartitionerBuilder( const std::string& name ) : PartitionerFactory( name ) {}
99 };
100 
101 // ------------------------------------------------------------------
102 
104 public:
105  static Partitioner* build( const std::string& type, const Mesh& partitioned );
106  static Partitioner* build( const std::string& type, const FunctionSpace& partitioned );
107 };
108 
109 // ------------------------------------------------------------------
110 
111 } // namespace partitioner
112 } // namespace detail
113 } // namespace grid
114 } // namespace atlas
Definition: Distribution.h:31
Definition: Mesh.h:55
Definition: Object.h:18
Most general grid container.
Definition: Grid.h:64
Contains all atlas classes and methods.
Definition: atlas-grids.cc:33
long idx_t
Integer type for indices in connectivity tables.
Definition: config.h:42
Definition: FunctionSpace.h:39