TIMPI
timpi_init.h
Go to the documentation of this file.
1 // The TIMPI Message-Passing Parallelism Library.
2 // Copyright (C) 2002-2025 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef TIMPI_INIT_H
21 #define TIMPI_INIT_H
22 
23 
24 // Local includes
25 #include "timpi/timpi_config.h"
26 
27 #include "timpi/semipermanent.h"
28 
29 // C/C++ includes
30 
31 #ifdef TIMPI_HAVE_MPI
32 # include "timpi/ignore_warnings.h"
33 # include <mpi.h>
34 # include "timpi/restore_warnings.h"
35 #endif // #ifdef TIMPI_HAVE_MPI
36 
37 #include <memory>
38 
39 namespace TIMPI
40 {
41 
42 // Forward declarations
43  class Communicator;
44 
57 class TIMPIInit
58 {
59 public:
60 #ifdef TIMPI_HAVE_MPI
61 
78  TIMPIInit(int argc, const char * const * argv,
79  int mpi_thread_requested=0,
80  bool handle_mpi_errors=false,
81  MPI_Comm COMM_WORLD_IN=MPI_COMM_WORLD);
82 #else
83  TIMPIInit(int argc, const char * const * argv,
84  int mpi_thread_requested=0,
85  bool handle_mpi_errors=false);
86 #endif
87 
92  virtual ~TIMPIInit();
93 
100  const Communicator & comm() const { return *_comm; }
101 
102  Communicator & comm() { return *_comm; }
103 
104 private:
105  std::unique_ptr<Communicator> _comm;
106 
107  // unique_ptr so we can free it *before* we MPI_Finalize
108  std::unique_ptr<SemiPermanent::Ref> _ref;
109 
110 #ifdef TIMPI_HAVE_MPI
112 
113  MPI_Errhandler my_errhandler;
115 #endif
116 };
117 
118 
119 } // namespace TIMPI
120 
121 #endif // TIMPI_INIT_H
TIMPIInit(int argc, const char *const *argv, int mpi_thread_requested=0, bool handle_mpi_errors=false, MPI_Comm COMM_WORLD_IN=MPI_COMM_WORLD)
Initialize the library for use, with the command line options provided.
Definition: timpi_init.C:41
std::unique_ptr< SemiPermanent::Ref > _ref
Definition: timpi_init.h:108
The TIMPIInit class, when constructed, initializes any dependent libraries (e.g.
Definition: timpi_init.h:57
Encapsulates the MPI_Comm object.
Definition: communicator.h:108
bool i_initialized_mpi
Definition: timpi_init.h:111
Communicator & comm()
Definition: timpi_init.h:102
virtual ~TIMPIInit()
Destructor.
Definition: timpi_init.C:133
MPI_Errhandler my_errhandler
Definition: timpi_init.h:113
std::unique_ptr< Communicator > _comm
Definition: timpi_init.h:105
const Communicator & comm() const
Returns the Communicator created by this object, which will be a compatibility shim if MPI is not ena...
Definition: timpi_init.h:100