OPAL (Object Oriented Parallel Accelerator Library) 2022.1
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 "Message/CommCreator.h"
27#include "Message/Communicate.h"
28#include "Message/CommMPI.h"
29
30#include <cstring>
31
32// static data for this file
33static const char *CommLibraryNames[CommCreator::COMMLIBRARIES] =
34 { "mpi", "serial" };
35
36static const char *CommLibraryList = "mpi or serial";
37
38
40// return the name of the Nth library
42{
43
44 if (n >= 0 && n < COMMLIBRARIES)
45 return CommLibraryNames[n];
46 else
47 return 0;
48}
49
50
52// return a list of all the libraries, as a single string
54{
55
56 return CommLibraryList;
57}
58
59
62{
63
64 if (cm == MPI) {
65 return true;
66 }
67 else if (cm == SERIAL) {
68 return true;
69 }
70 return false;
71}
72
73
75// return the index of the given named library, or (-1) if not found
76int CommCreator::libindex(const char *nm)
77{
78
79 for (int i=0; i < COMMLIBRARIES; ++i)
80 {
81 if (strcmp(nm, getLibraryName(i)) == 0)
82 return i;
83 }
84
85 // if here, it was not found
86 return (-1);
87}
88
89
91// create a new Communicate object. Arguments = type, argc, argv, num nodes,
92// whether to do initialization or not (ignored by some libs).
93// If the type code is illegal, or the comm library is not supported,
94// return 0.
95Communicate *CommCreator::create(int cm, int& argc, char**& argv, int nodes,
96 bool doinit, MPI_Comm mpicomm)
97{
98
99 Communicate *comm = 0;
100
101 // to avoid warning message
102 if (doinit) { }
103
104 if (cm == MPI)
105 {
106 comm = new CommMPI(argc, argv, nodes, doinit, mpicomm);
107 }
108 else if (cm == SERIAL)
109 {
110 // just make a dummy comm object, which does nothing
111 comm = new Communicate(argc, argv, nodes);
112 }
113 // return the Communicate object
114 return comm;
115}
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 int libindex(const char *)
Definition: CommCreator.cpp:76
static Communicate * create(int, int &, char **&, int=(-1), bool=true, MPI_Comm mpicomm=MPI_COMM_WORLD)
Definition: CommCreator.cpp:95