OPAL (Object Oriented Parallel Accelerator Library)  2021.1.99
OPAL
CommCreator.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  *
7  * Visit http://people.web.psi.ch/adelmann/ for more details
8  *
9  ***************************************************************************/
10 
11 #ifndef COMM_CREATOR_H
12 #define COMM_CREATOR_H
13 
14 /***********************************************************************
15  *
16  * CommCreator is a factory class which is used to create specific
17  * subclasses of the base class Communicate. To create a new library-
18  * specific Communicate, the user can either instantiate such a class
19  * directly, or they can call the static method
20  * CommCreator::create(CommCreator::CreateMethod, int argc, char *argv[],
21  * int nodes)
22  *
23  ***********************************************************************/
24 
25 #include <mpi.h>
26 
27 // forward declarations
28 class Communicate;
29 
30 
31 // class definition
33 {
34 
35 public:
36 
37  // enumeration of communication libraries
38  enum { MPI, SERIAL, COMMLIBRARIES };
39 
40 public:
41  // constructor and destructor
44 
45  //
46  // informative methods
47  //
48 
49  // return the number of libraries available
50  static int getNumLibraries()
51  {
52  return COMMLIBRARIES;
53  }
54 
55  // return the name of the Nth library
56  static const char *getLibraryName(int);
57 
58  // return a list of all the libraries, as a single string
59  static const char *getAllLibraryNames();
60 
61  // is the given comm library available here?
62  static bool supported(int);
63  static bool supported(const char *nm)
64  {
65  return supported(libindex(nm));
66  }
67 
68  // is the given comm library name one we recognize?
69  static bool known(const char *nm)
70  {
71  return (libindex(nm) >= 0);
72  }
73 
74  //
75  // Communicate create methods
76  //
77 
78  // create a new Communicate object. Arguments = type, argc, argv, num nodes,
79  // do init
80  static Communicate *create(int, int&, char** &, int = (-1), bool = true,
81  MPI_Comm mpicomm = MPI_COMM_WORLD);
82 
83  // same as above, but specifying the type as a string instead of an int
84  static Communicate *create(const char *nm, int& argc, char **& argv,
85  int nodes= (-1), bool doinit = true,
86  MPI_Comm mpicomm = MPI_COMM_WORLD)
87  {
88  return create(libindex(nm), argc, argv, nodes, doinit, mpicomm);
89  }
90 
91 private:
92  // return the index of the given named library, or (-1) if not found
93  static int libindex(const char *);
94 };
95 
96 #endif // COMM_CREATOR_H
static const char * getLibraryName(int)
Definition: CommCreator.cpp:41
static const char * getAllLibraryNames()
Definition: CommCreator.cpp:53
static bool supported(int)
Definition: CommCreator.cpp:61
static Communicate * create(const char *nm, int &argc, char **&argv, int nodes=(-1), bool doinit=true, MPI_Comm mpicomm=MPI_COMM_WORLD)
Definition: CommCreator.h:84
static int getNumLibraries()
Definition: CommCreator.h:50
static int libindex(const char *)
Definition: CommCreator.cpp:76
static bool supported(const char *nm)
Definition: CommCreator.h:63
static Communicate * create(int, int &, char **&, int=(-1), bool=true, MPI_Comm mpicomm=MPI_COMM_WORLD)
Definition: CommCreator.cpp:95
static bool known(const char *nm)
Definition: CommCreator.h:69