OPAL (Object Oriented Parallel Accelerator Library)  2.2.0
OPAL
CommCreator.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
2 /***************************************************************************
3  *
4  * The IPPL Framework
5  *
6  * This program was prepared by PSI.
7  * All rights in the program are reserved by PSI.
8  * Neither PSI nor the author(s)
9  * makes any warranty, express or implied, or assumes any liability or
10  * responsibility for the use of this software
11  *
12  * Visit www.amas.web.psi for more details
13  *
14  ***************************************************************************/
15 
16 // -*- C++ -*-
17 /***************************************************************************
18  *
19  * The IPPL Framework
20  *
21  *
22  * Visit http://people.web.psi.ch/adelmann/ for more details
23  *
24  ***************************************************************************/
25 
26 // include files
27 #include "Message/CommCreator.h"
28 #include "Message/Communicate.h"
29 
30 
31 // include files for specific communication libraries
32 
33 
34 #if defined(IPPL_MPI)
35 #include "Message/CommMPI.h"
36 #endif
37 
38 #if defined(IPPL_SHMEMPI)
39 #include "Message/CommSHMEMPI.h"
40 #endif
41 
42 #if defined(IPPL_PM)
43 #include "Message/CommPM.h"
44 #endif
45 
46 #include <cstring>
47 
48 // static data for this file
49 static const char *CommLibraryNames[CommCreator::COMMLIBRARIES] =
50  { "pm", "mpi", "shmempi","serial" };
51 
52 static const char *CommLibraryList = "pm, mpi, shmempi, or serial";
53 
54 
56 // return the name of the Nth library
58 {
59 
60  if (n >= 0 && n < COMMLIBRARIES)
61  return CommLibraryNames[n];
62  else
63  return 0;
64 }
65 
66 
68 // return a list of all the libraries, as a single string
70 {
71 
72  return CommLibraryList;
73 }
74 
75 
78 {
79 
80  if (cm == PM)
81  {
82 #ifdef IPPL_PM
83  return true;
84 #endif
85  }
86  else if (cm == MPI)
87  {
88 #ifdef IPPL_MPI
89  return true;
90 #endif
91  }
92  else if (cm == SHMEMPI)
93  {
94 #ifdef IPPL_SHMEMPI
95  return true;
96 #endif
97  }
98  else if (cm == SERIAL) {
99  return true;
100  }
101  return false;
102 }
103 
104 
106 // return the index of the given named library, or (-1) if not found
107 int CommCreator::libindex(const char *nm)
108 {
109 
110  for (int i=0; i < COMMLIBRARIES; ++i)
111  {
112  if (strcmp(nm, getLibraryName(i)) == 0)
113  return i;
114  }
115 
116  // if here, it was not found
117  return (-1);
118 }
119 
120 
122 // create a new Communicate object. Arguments = type, argc, argv, num nodes,
123 // whether to do initialization or not (ignored by some libs).
124 // If the type code is illegal, or the comm library is not supported,
125 // return 0.
126 Communicate *CommCreator::create(int cm, int& argc, char**& argv, int nodes,
127  bool doinit, MPI_Comm mpicomm)
128 {
129 
130  Communicate *comm = 0;
131 
132  // to avoid warning message
133  if (doinit) { }
134 
135  if (cm == PM)
136  {
137 #ifdef IPPL_PM
138  comm = new CommPM(argc, argv, nodes);
139 #endif
140  }
141  else if (cm == MPI)
142  {
143 #ifdef IPPL_MPI
144  comm = new CommMPI(argc, argv, nodes, doinit, mpicomm);
145 #endif
146  }
147  else if (cm == SHMEMPI)
148  {
149 #ifdef IPPL_SHMEMPI
150  comm = new CommSHMEMPI(argc, argv, nodes);
151 #endif
152  }
153  else if (cm == SERIAL)
154  {
155  // just make a dummy comm object, which does nothing
156  comm = new Communicate(argc, argv, nodes);
157  }
158  // return the Communicate object
159  return comm;
160 }
static const char * getLibraryName(int)
Definition: CommCreator.cpp:57
Definition: CommPM.h:25
static Communicate * create(int, int &, char **&, int=(-1), bool=true, MPI_Comm mpicomm=MPI_COMM_WORLD)
static const char * getAllLibraryNames()
Definition: CommCreator.cpp:69
static int libindex(const char *)
static bool supported(int)
Definition: CommCreator.cpp:77