forked from AmbaPant/mantid
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCommunicator.cpp
70 lines (58 loc) · 2.04 KB
/
Communicator.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Mantid Repository : https://github.com/mantidproject/mantid
//
// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
// NScD Oak Ridge National Laboratory, European Spallation Source,
// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
// SPDX - License - Identifier: GPL - 3.0 +
#include <utility>
#include "MantidParallel/Communicator.h"
#ifdef MPI_EXPERIMENTAL
#include <boost/mpi/environment.hpp>
#endif
namespace Mantid::Parallel {
#ifdef MPI_EXPERIMENTAL
boost::mpi::environment environment;
#endif
#ifdef MPI_EXPERIMENTAL
Communicator::Communicator(const boost::mpi::communicator &comm) : m_communicator(comm) {}
#endif
Communicator::Communicator(std::shared_ptr<detail::ThreadingBackend> backend, const int rank)
: m_backend(std::move(backend)), m_rank(rank) {}
int Communicator::rank() const {
if (m_backend)
return m_rank;
#ifdef MPI_EXPERIMENTAL
return m_communicator.rank();
#endif
return 0;
}
int Communicator::size() const {
if (m_backend)
return m_backend->size();
#ifdef MPI_EXPERIMENTAL
return m_communicator.size();
#endif
return 1;
}
#ifdef MPI_EXPERIMENTAL
/// For internal use only. Casts the Communicator to the underlying
/// boost::mpi::communicator object.
Communicator::operator const boost::mpi::communicator &() const { return m_communicator; }
#endif
/// For internal use only. Returns true if the communicator has a
/// ThreadingBackend.
bool Communicator::hasBackend() const { return static_cast<bool>(m_backend); }
/// For internal use only. Returns the ThreadingBackend or throws an exception
/// if not available.
detail::ThreadingBackend &Communicator::backend() const {
if (!m_backend)
#ifndef MPI_EXPERIMENTAL
throw std::runtime_error("Parallel::Communicator without backend in non-MPI build.");
#else
throw std::runtime_error("Parallel::Communicator without backend in MPI "
"build. Check hasBackend() before accessing the "
"backend.");
#endif
return *m_backend;
}
} // namespace Mantid::Parallel