OpenPFC  0.1.4
Phase Field Crystal simulation framework
Loading...
Searching...
No Matches
communicator.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2025 VTT Technical Research Centre of Finland Ltd
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
33#ifndef PFC_MPI_COMMUNICATOR_HPP
34#define PFC_MPI_COMMUNICATOR_HPP
35
36#include <memory>
37#include <mpi.h>
38
39namespace pfc {
40namespace mpi {
41
43
44public:
46 operator MPI_Comm() const;
47 int rank() const;
48 int size() const;
49
50protected:
51 std::shared_ptr<MPI_Comm> comm_ptr;
52};
53
54inline communicator::communicator() { comm_ptr.reset(new MPI_Comm(MPI_COMM_WORLD)); }
55
56inline communicator::operator MPI_Comm() const {
57 if (comm_ptr)
58 return *comm_ptr;
59 else
60 return MPI_COMM_NULL;
61}
62
63inline int communicator::size() const {
64 int size_;
65 MPI_Comm_size(MPI_Comm(*this), &size_);
66 return size_;
67}
68
69inline int communicator::rank() const {
70 int rank_;
71 MPI_Comm_rank(MPI_Comm(*this), &rank_);
72 return rank_;
73}
74
75} // namespace mpi
76} // namespace pfc
77
78#endif // PFC_MPI_COMMUNICATOR_HPP
Definition communicator.hpp:42
Represents the global simulation domain (the "world").
Definition world.hpp:91