Loading...
Searching...
No Matches
UPstreamCommunicator.C
Go to the documentation of this file.
1/*---------------------------------------------------------------------------*\
2 ========= |
3 \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4 \\ / O peration |
5 \\ / A nd | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2024-2025 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "UPstream.H"
29#include "PstreamGlobals.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
34:
35 UPstream::Communicator(MPI_COMM_NULL)
36{}
37
38
39// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
40
41Foam::UPstream::Communicator
43{
44 MPI_Comm mpiComm = MPI_COMM_NULL;
45
46 if (communicator < 0)
47 {
48 // Default/short-cut : world-comm
50 }
51
53 {
55 }
56 else
57 {
59 << "Illegal communicator " << communicator << nl
60 << "Should be within range [-1,"
62 << ')' << endl;
63 }
64
65 return UPstream::Communicator(mpiComm);
66}
67
68
69// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
70
72{
73 return MPI_COMM_NULL != PstreamUtils::Cast::to_mpi(*this);
74}
75
76
78{
79 *this = UPstream::Communicator(MPI_COMM_NULL);
80}
81
82
84{
85 int val = 0;
86
87 MPI_Comm comm = PstreamUtils::Cast::to_mpi(*this);
88
89 if (MPI_COMM_SELF == comm)
90 {
91 return 1;
92 }
93 else if
94 (
95 (MPI_COMM_NULL == comm)
96 || (MPI_SUCCESS != MPI_Comm_size(comm, &val))
97 )
98 {
99 val = 0;
100 }
101
102 return val;
103}
104
105
106// ************************************************************************* //
void reset() noexcept
Reset to default constructed value (MPI_COMM_NULL).
bool good() const noexcept
True if not equal to MPI_COMM_NULL.
Communicator() noexcept
Default construct as MPI_COMM_NULL.
int size() const
The number of ranks associated with the communicator.
static Communicator lookup(int communicator=-1)
Transcribe internally indexed communicator to wrapped value.
Wrapper for internally indexed communicator label. Always invokes UPstream::allocateCommunicatorCompo...
Definition UPstream.H:2546
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Definition UPstream.H:1069
#define WarningInFunction
Report a warning using Foam::Warning.
DynamicList< MPI_Comm > MPICommunicators_
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition Ostream.H:519
const direction noexcept
Definition scalarImpl.H:265
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50
static Type to_mpi(UPstream::Communicator arg) noexcept
Cast UPstream::Communicator to MPI_Comm.