Loading [MathJax]/extensions/tex2jax.js
IODA
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ReplicaOfGeneralDistribution.h
Go to the documentation of this file.
1 /*
2  * (C) Crown copyright 2021, Met Office
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  */
7 
8 #ifndef DISTRIBUTION_REPLICAOFGENERALDISTRIBUTION_H_
9 #define DISTRIBUTION_REPLICAOFGENERALDISTRIBUTION_H_
10 
11 #include <unordered_set>
12 #include <vector>
13 
14 #include "ioda/distribution/Distribution.h"
15 
16 namespace ioda {
17 
19  public:
20  ReplicaOfGeneralDistribution(const eckit::mpi::Comm & comm,
21  std::shared_ptr<const Distribution> masterDist,
22  const std::vector<std::size_t> &masterRecordNumbers);
24 
25  void assignRecord(const std::size_t RecNum, const std::size_t LocNum,
26  const eckit::geometry::Point2 & point) override;
27  bool isMyRecord(std::size_t RecNum) const override;
28  void computePatchLocs() override;
29  void patchObs(std::vector<bool> &) const override;
30 
31  void min(int & x) const override;
32  void min(std::size_t & x) const override;
33  void min(float & x) const override;
34  void min(double & x) const override;
35  void min(std::vector<int> & x) const override;
36  void min(std::vector<std::size_t> & x) const override;
37  void min(std::vector<float> & x) const override;
38  void min(std::vector<double> & x) const override;
39 
40  void max(int & x) const override;
41  void max(std::size_t & x) const override;
42  void max(float & x) const override;
43  void max(double & x) const override;
44  void max(std::vector<int> & x) const override;
45  void max(std::vector<std::size_t> & x) const override;
46  void max(std::vector<float> & x) const override;
47  void max(std::vector<double> & x) const override;
48 
49  void allGatherv(std::vector<size_t> &x) const override;
50  void allGatherv(std::vector<int> &x) const override;
51  void allGatherv(std::vector<float> &x) const override;
52  void allGatherv(std::vector<double> &x) const override;
53  void allGatherv(std::vector<util::DateTime> &x) const override;
54  void allGatherv(std::vector<std::string> &x) const override;
55 
56  size_t globalUniqueConsecutiveLocationIndex(size_t loc) const override;
57 
58  std::string name() const override { return "ReplicaOfGeneralDistribution"; }
59 
60  private:
61  template <typename T>
62  void minImpl(T & x) const;
63 
64  template <typename T>
65  void maxImpl(T & x) const;
66 
67  template <typename T>
68  void reductionImpl(T & x, eckit::mpi::Operation::Code op) const;
69 
70  template <typename T>
71  void reductionImpl(std::vector<T> & x, eckit::mpi::Operation::Code op) const;
72 
73  std::unique_ptr<Accumulator<int>>
74  createAccumulatorImpl(int init) const override;
75  std::unique_ptr<Accumulator<std::size_t>>
76  createAccumulatorImpl(std::size_t init) const override;
77  std::unique_ptr<Accumulator<float>>
78  createAccumulatorImpl(float init) const override;
79  std::unique_ptr<Accumulator<double>>
80  createAccumulatorImpl(double init) const override;
81  std::unique_ptr<Accumulator<std::vector<int>>>
82  createAccumulatorImpl(const std::vector<int> &init) const override;
83  std::unique_ptr<Accumulator<std::vector<std::size_t>>>
84  createAccumulatorImpl(const std::vector<std::size_t> &init) const override;
85  std::unique_ptr<Accumulator<std::vector<float>>>
86  createAccumulatorImpl(const std::vector<float> &init) const override;
87  std::unique_ptr<Accumulator<std::vector<double>>>
88  createAccumulatorImpl(const std::vector<double> &init) const override;
89 
90  template <typename T>
91  std::unique_ptr<Accumulator<T>> createAccumulatorImplT(const T &init) const;
92 
93  template <typename T>
94  void allGathervImpl(std::vector<T> &x) const;
95 
97  const std::vector<std::pair<double, int>> &dist_and_lidx_glb);
98 
99  std::shared_ptr<const Distribution> masterDist_;
100  std::size_t numMasterLocs_;
101  std::unordered_set<std::size_t> masterPatchRecords_;
102 
103  std::unordered_set<std::size_t> myRecords_;
104  std::vector<std::size_t> myGlobalLocs_;
105  std::vector<bool> isMyPatchObs_;
106  // Maps indices of locations held on this PE to corresponding elements of vectors
107  // produced by allGatherv()
109 };
110 
111 } // namespace ioda
112 
113 #endif // DISTRIBUTION_REPLICAOFGENERALDISTRIBUTION_H_
class for distributing obs across multiple process elements
ReplicaOfGeneralDistribution(const eckit::mpi::Comm &comm, std::shared_ptr< const Distribution > masterDist, const std::vector< std::size_t > &masterRecordNumbers)
std::unordered_set< std::size_t > myRecords_
void assignRecord(const std::size_t RecNum, const std::size_t LocNum, const eckit::geometry::Point2 &point) override
If the record RecNum has not yet been assigned to a PE, assigns it to the appropriate PE.
bool isMyRecord(std::size_t RecNum) const override
Returns true if record RecNum has been assigned to the calling PE during a previous call to assignRec...
void min(int &x) const override
Calculates the global minimum (over all locations on all PEs) of a location-dependent quantity.
void reductionImpl(T &x, eckit::mpi::Operation::Code op) const
void allGatherv(std::vector< size_t > &x) const override
Gather observation data from all processes and deliver the combined data to all processes.
void computePatchLocs() override
If necessary, identifies locations of "patch obs", i.e.
size_t globalUniqueConsecutiveLocationIndex(size_t loc) const override
Map the index of a location held on the calling process to the index of the corresponding element of ...
void allGathervImpl(std::vector< T > &x) const
std::unordered_set< std::size_t > masterPatchRecords_
void patchObs(std::vector< bool > &) const override
Sets each element of the provided vector to true if the corresponding location is a "patch obs",...
void computeGlobalUniqueConsecutiveLocIndices(const std::vector< std::pair< double, int >> &dist_and_lidx_glb)
std::unique_ptr< Accumulator< int > > createAccumulatorImpl(int init) const override
Create an object that can be used to calculate the sum of a location-dependent quantity over location...
std::unique_ptr< Accumulator< T > > createAccumulatorImplT(const T &init) const
std::shared_ptr< const Distribution > masterDist_
void max(int &x) const override
Calculates the global maximum (over all locations on all PEs) of a location-dependent quantity.