BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
cl_Communicator.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
12#ifndef BELFEM_CL_COMMUNICATOR_HPP
13#define BELFEM_CL_COMMUNICATOR_HPP
14
15#include <string>
16#ifdef BELFEM_MPI
17#include <mpi.h>
18#define COMM_TYPE MPI_Comm
19#else
20#define COMM_TYPE int
21#endif
22
23#include <random>
24#include "typedefs.hpp"
25
26#include "cl_Cell.hpp"
27
28
29namespace belfem
30{
31//------------------------------------------------------------------------------
32
34 {
35 index_t mIndex ;
36
37 public:
38
40
42
43 virtual void
44 free();
45
47 index() const ;
48 };
49
51
52//------------------------------------------------------------------------------
60 {
61 std::string mExecutablePath;
62 std::string mWorkDir;
63 std::string mArgumentString = "";
64
65 Cell<COMM_TYPE> mComms;
66
67 proc_t mCommRank = gNoOwner ;
68 proc_t mSize = gNoOwner ;
69 proc_t mNodeSize = 1 ;
70 Cell< string > mArguments ;
71
72 int mMaxTag ;
73
74 std::mt19937 mRandom;
75
77
78//------------------------------------------------------------------------------
79 public:
80//------------------------------------------------------------------------------
81
83
84//------------------------------------------------------------------------------
85
87 int argc, char ** argv );
88
89//------------------------------------------------------------------------------
90
92
93//------------------------------------------------------------------------------
94
95 Communicator( const Communicator & ) = delete;
96 Communicator & operator=( const Communicator & ) = delete;
97 Communicator( Communicator && ) = delete;
99
100//------------------------------------------------------------------------------
101
102 void
103 init( int & argc, char ** & argv );
104
105//-----------------------------------------------------------------------------
106
107 int
108 finalize();
109
110//-----------------------------------------------------------------------------
111
112 COMM_TYPE &
113 world();
114
115//-----------------------------------------------------------------------------
116
117 const std::string &
118 exec_path();
119
120//-----------------------------------------------------------------------------
121
122 const std::string &
123 workdir();
124
125//-----------------------------------------------------------------------------
126
127 const std::string &
129//-----------------------------------------------------------------------------
130
132 arguments();
133
134//-----------------------------------------------------------------------------
135
141 void
142 set_arguments( const string & aArguments );
143
144//-----------------------------------------------------------------------------
145
146 proc_t
147 rank() const;
148
149//-----------------------------------------------------------------------------
150
151 proc_t
152 size() const;
153
154//-----------------------------------------------------------------------------
155
159 proc_t
160 node_size() const;
161
162//-----------------------------------------------------------------------------
163
164 inline std::mt19937 &
166 {
167 return mRandom ;
168 }
169
170 inline int
171 max_tag() const
172 {
173 return mMaxTag ;
174 }
175
176 inline
178 objects();
179
180
181 private:
182
183 int
184 init_thread( int & argc, char ** & argv );
185
186 void
187 set_globals();
188 };
189//------------------------------------------------------------------------------
190
191 inline proc_t
193 {
194 return mCommRank ;
195 }
196
197//-----------------------------------------------------------------------------
198
199 inline proc_t
201 {
202 return mSize ;
203 }
204
205//-----------------------------------------------------------------------------
206
207 inline proc_t
209 {
210 return mNodeSize ;
211 }
212
215 {
216 return mObjects ;
217 }
218
219//-----------------------------------------------------------------------------
220}
221
222// Externally Defined Global Communicator
224
225//------------------------------------------------------------------------------
226// comm_abort is declared HERE rather than in commtools.hpp so that core's
227// assert.cpp can reach it: commtools.hpp pulls cl_Vector/cl_Matrix from
228// linalg, which is not on the core module's include path, while this header
229// already is ( assert.cpp includes it today ). commtools.hpp includes this
230// header, so every commtools consumer sees the declaration as before.
231// Definition: commtools.cpp.
232//------------------------------------------------------------------------------
233
234namespace belfem
235{
258 [[noreturn]] void
259 comm_abort( const int aErrorCode = 1 );
260}
261
262
263#endif //BELFEM_CL_COMMUNICATOR_HPP
belfem::Communicator gComm
Definition belfem.cpp:35
#define COMM_TYPE
Definition cl_Communicator.hpp:20
Cell is a wrapper around the standard vector.
Definition cl_Cell.hpp:42
Definition cl_Communicator.hpp:34
virtual void free()
Definition cl_Communicator.cpp:385
CommunicationObject()
Definition cl_Communicator.cpp:373
index_t index() const
Definition cl_Communicator.cpp:391
Global MPI communicator manager.
Definition cl_Communicator.hpp:60
void set_arguments(const string &aArguments)
overrides the argument string assembled by init(); no framework caller today ( the Arguments-object c...
Definition cl_Communicator.cpp:287
int finalize()
Definition cl_Communicator.cpp:295
proc_t node_size() const
returns the number of MPI ranks on this node
Definition cl_Communicator.hpp:208
COMM_TYPE & world()
Definition cl_Communicator.cpp:249
Communicator()
Definition cl_Communicator.hpp:82
int max_tag() const
Definition cl_Communicator.hpp:171
Communicator(Communicator &&)=delete
proc_t rank() const
Definition cl_Communicator.hpp:192
Communicator(const Communicator &)=delete
Cell< CommunicationObject * > & objects()
Definition cl_Communicator.hpp:214
proc_t size() const
Definition cl_Communicator.hpp:200
const std::string & workdir()
Definition cl_Communicator.cpp:264
Communicator & operator=(Communicator &&)=delete
std::mt19937 & random()
Definition cl_Communicator.hpp:165
const std::string & exec_path()
Definition cl_Communicator.cpp:257
void init(int &argc, char **&argv)
Definition cl_Communicator.cpp:96
Cell< std::string > & arguments()
Definition cl_Communicator.cpp:271
Communicator & operator=(const Communicator &)=delete
const std::string & argument_string()
Definition cl_Communicator.cpp:279
USER GUIDES:
Definition cl_Capacitor.cpp:16
int proc_t
Definition commtypes.hpp:29
void comm_abort(const int aErrorCode=1)
Kill the whole job.
Definition commtools.cpp:67
constexpr proc_t gNoOwner
Definition typedefs.hpp:59
uint32_t index_t
Definition typedefs.hpp:52