UFO
src/ufo/utils/ParallelObsDistribution.h
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2020 Met Office UK
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 UFO_UTILS_PARALLELOBSDISTRIBUTION_H_
9 #define UFO_UTILS_PARALLELOBSDISTRIBUTION_H_
10 
11 #include <string>
12 #include <vector>
13 
14 #include "ioda/ObsSpace.h"
15 
16 namespace ufo {
17 
18 /// \brief Describes how observations in an ObsSpace are distributed across MPI processes.
20  public:
21  /// \brief Construct an object describing the distribution of observations in \p obsspace across
22  /// MPI processes.
23  explicit ParallelObsDistribution(const ioda::ObsSpace &obsspace);
24 
25  /// \brief Return the total number of observations held by all MPI processes.
26  size_t globalObsCount() const { return globalObsCount_; }
27 
28  /// \brief Return a vector whose ith element is the number of observations held by the MPI process
29  /// with rank i.
30  ///
31  /// The returned vector can be passed to the \c recvcounts parameter of
32  /// eckit::mpi::Comm::allGatherv().
33  const std::vector<int> &localObsCounts() const { return localObsCounts_; }
34 
35  /// \brief Return a vector whose ith element is the total number of observations held by the MPI
36  /// processes with ranks less than i.
37  ///
38  /// The returned vector can be passed to the \c recvcounts parameter of
39  /// eckit::mpi::Comm::displs().
40  const std::vector<int> &localObsIdDisplacements() const { return localObsIdDisplacements_; }
41 
42  private:
44  std::vector<int> localObsCounts_;
45  std::vector<int> localObsIdDisplacements_;
46 };
47 
48 /// \brief Return a vector containing the values of variable \c variable@group for all observations
49 /// held by process 0, then all observations held by process 1 etc.
50 ///
51 /// \tparam T
52 /// Type of the variable values. Must be int, float, double or util::DateTime,
53 /// otherwise a linking error will occur.
54 ///
55 /// \related ParallelObsDistribution
56 template <typename T>
57 std::vector<T> getGlobalVariableValues(const ioda::ObsSpace &obsspace,
58  const ParallelObsDistribution &obsDistribution,
59  const std::string &variable,
60  const std::string &group);
61 
62 } // namespace ufo
63 
64 #endif // UFO_UTILS_PARALLELOBSDISTRIBUTION_H_
ufo::ParallelObsDistribution::ParallelObsDistribution
ParallelObsDistribution(const ioda::ObsSpace &obsspace)
Construct an object describing the distribution of observations in obsspace across MPI processes.
Definition: ParallelObsDistribution.cc:13
ufo::ParallelObsDistribution
Describes how observations in an ObsSpace are distributed across MPI processes.
Definition: src/ufo/utils/ParallelObsDistribution.h:19
ufo::ParallelObsDistribution::globalObsCount
size_t globalObsCount() const
Return the total number of observations held by all MPI processes.
Definition: src/ufo/utils/ParallelObsDistribution.h:26
ufo::getGlobalVariableValues
std::vector< T > getGlobalVariableValues(const ioda::ObsSpace &obsspace, const ParallelObsDistribution &obsDistribution, const std::string &variable, const std::string &group)
Definition: ParallelObsDistribution.cc:30
ufo::ParallelObsDistribution::localObsIdDisplacements_
std::vector< int > localObsIdDisplacements_
Definition: src/ufo/utils/ParallelObsDistribution.h:45
ufo
Definition: RunCRTM.h:27
ufo::ParallelObsDistribution::localObsCounts
const std::vector< int > & localObsCounts() const
Return a vector whose ith element is the number of observations held by the MPI process with rank i.
Definition: src/ufo/utils/ParallelObsDistribution.h:33
ufo::ParallelObsDistribution::localObsIdDisplacements
const std::vector< int > & localObsIdDisplacements() const
Return a vector whose ith element is the total number of observations held by the MPI processes with ...
Definition: src/ufo/utils/ParallelObsDistribution.h:40
ufo::ParallelObsDistribution::globalObsCount_
size_t globalObsCount_
Definition: src/ufo/utils/ParallelObsDistribution.h:43
ufo::ParallelObsDistribution::localObsCounts_
std::vector< int > localObsCounts_
Definition: src/ufo/utils/ParallelObsDistribution.h:44