IODA
RoundRobin.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2017-2019 UCAR
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 #include "ioda/distribution/RoundRobin.h"
9 
10 #include <algorithm>
11 #include <iostream>
12 #include <numeric>
13 #include <set>
14 
15 #include "oops/util/Logger.h"
16 
17 namespace ioda {
18 // -----------------------------------------------------------------------------
19 RoundRobin::RoundRobin(const eckit::mpi::Comm & Comm) : Distribution(Comm) {
20  oops::Log::trace() << "RoundRobin constructed" << std::endl;
21 }
22 
23 // -----------------------------------------------------------------------------
25  oops::Log::trace() << "RoundRobin destructed" << std::endl;
26 }
27 
28 // -----------------------------------------------------------------------------
29 /*!
30  * \brief Round-robin selector
31  *
32  * \details This method distributes observations according to a round-robin scheme.
33  * The round-robin scheme simply selects all locations where the modulus of
34  * the record number relative to the number of process elements equals
35  * the rank of the process element we are running on. This does a good job
36  * of distributing the observations evenly across processors which optimizes
37  * the load balancing.
38  *
39  * \param[in] RecNum Record number, checked if belongs on this process element
40  */
41 bool RoundRobin::isMyRecord(std::size_t RecNum) const {
42  return (RecNum % comm_.size() == comm_.rank());
43 }
44 
45 // -----------------------------------------------------------------------------
46 
47 } // namespace ioda
ioda::Distribution
class for distributing obs across multiple process elements
Definition: src/distribution/Distribution.h:30
ioda
Definition: IodaUtils.cc:13
ioda::Distribution::comm_
const eckit::mpi::Comm & comm_
Local MPI communicator.
Definition: src/distribution/Distribution.h:40
ioda::RoundRobin::~RoundRobin
~RoundRobin()
Definition: RoundRobin.cc:24
ioda::RoundRobin::isMyRecord
bool isMyRecord(std::size_t RecNum) const override
Round-robin selector.
Definition: RoundRobin.cc:41
ioda::RoundRobin::RoundRobin
RoundRobin(const eckit::mpi::Comm &Comm)
Definition: RoundRobin.cc:19