ESPResSo
Extensible Simulation Package for Research on Soft Matter Systems
Loading...
Searching...
No Matches
all_compare.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017-2026 The ESPResSo project
3 *
4 * This file is part of ESPResSo.
5 *
6 * ESPResSo is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * ESPResSo is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef UTILS_MPI_ALL_COMPARED_HPP
21#define UTILS_MPI_ALL_COMPARED_HPP
22
23#include <functional>
24
25#include <boost/mpi/collectives/all_reduce.hpp>
26#include <boost/mpi/collectives/broadcast.hpp>
27
28namespace Utils {
29namespace Mpi {
30
31/**
32 * @brief Compare values on all nodes.
33 *
34 * @param comm The communicator to operate on.
35 * @param value the value to compare.
36 *
37 * @tparam T the type of value.
38 *
39 * Returns true iff all ranks in comm called
40 * the function with the same value.
41 * T has to be serializeable.
42 */
43template <typename T>
44bool all_compare(boost::mpi::communicator const &comm, T const &value) {
45 T root_value{};
46
47 /* Arbitrary pick the value on rank 0, and broadcast it */
48 if (comm.rank() == 0) {
49 root_value = value;
50 }
51
52 boost::mpi::broadcast(comm, root_value, 0);
53
54 bool is_same = false;
55 boost::mpi::all_reduce(comm, value == root_value, is_same,
56 std::logical_and<bool>());
57
58 return is_same;
59}
60} // namespace Mpi
61} // namespace Utils
62
63#endif
cudaStream_t stream[1]
CUDA streams for parallel computing on CPU and GPU.
bool all_compare(boost::mpi::communicator const &comm, T const &value)
Compare values on all nodes.