OPAL (Object Oriented Parallel Accelerator Library) 2022.1
OPAL
DiscConfig.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 DISC_CONFIG_H
12#define DISC_CONFIG_H
13
14/***************************************************************************
15 * DiscConfig is a utility class which will read in a configuration file
16 * for use by classes such as DiscField that read or write parallel data
17 * files. It should be given a config file name, which will be parsed by
18 * the constructor; the config file should have the format:
19 *
20 * # comment line(s), starting with '#'
21 * machine1 directory1-1
22 * machine2 directory2-1
23 * machine2 directory2-2
24 *
25 * Instead of an SMP machine name, you can specify '*', which acts as a
26 * default line for all machines which are not listed elsewhere in the config
27 * file. There are also some allowed variables in the directory names,
28 * which have the form '$(varname)'. Allowed variables are
29 * $(n) ... the node ID, from 0 ... (total nodes - 1)
30 * $(*) ... the SMP machine name
31 * $(ENV) ... the value of environment variable 'ENV'
32 * Examples of using these kinds of wildcards
33 *
34 * ######################################################################
35 * # a sample config file with wildcards and variables
36 *
37 * # first, a wildcard, for the directory /scratch/<username>/<hostname>
38 * * /scratch/$(USER)/$(*)
39 *
40 * # specific host commands
41 * host3 /usr/local/data/host3/dir1
42 * host3 /usr/local/data/host3/dir2
43 * host4 /tmp/dir3/$(n)
44 * #
45 * ######################################################################
46 *
47 * Machines may be listed more than once; they may also be omitted (that is,
48 * the config file may be read by a job running on several different SMP's,
49 * where the config file contains listings for only some of the SMP's).
50 *
51 ***************************************************************************/
52
53// include files
54#include "Utility/vmap.h"
55#include "Utility/Inform.h"
56
57
59
60public:
61 // Constructor: read in and parse the given config file. We must know
62 // whether the configuration file is being used to read or write data.
63 DiscConfig(const char *, const char *, bool);
64
65 // Destructor.
67
68 //
69 // general accessor functions
70 //
71
72 // did everything in the config file parse OK?
73 bool ok() const { return ConfigOK; }
74
75 // return the name of our config file
76 const std::string &getConfigFile() const { return ConfigFile; }
77
78 // return the number of SMP's there are, in total, and the number
79 // of SMP 'filesets' which will be read or written.
80 unsigned int numSMPs() const { return NumSMPs; }
81 unsigned int fileSMPs() const { return FileSMPs; }
82 unsigned int mySMP() const { return MySMP; }
83
84 //
85 // SMP accessor functions
86 //
87
88 // return the SMP index for the SMP with the given name, or for my own
89 unsigned int getSMPIndex() const { return MySMP; }
90 unsigned int getSMPIndex(const std::string &smpname) const {
91 return SMPMap[smpname]->SMPIndex;
92 }
93
94 // return the host name of the Nth SMP
95 const std::string &getSMPHost() const { return getSMPHost(MySMP); }
96 const std::string &getSMPHost(unsigned int smp) const {
97 return SMPList[smp]->HostName;
98 }
99
100 // return the number of nodes in the Nth SMP
101 unsigned int getNumSMPNodes() const { return getNumSMPNodes(MySMP); }
102 unsigned int getNumSMPNodes(unsigned int smp) const {
103 return SMPList[smp]->NodeList.size();
104 }
105
106 // return the mth node ID for the Nth SMP
107 unsigned int getSMPNode(unsigned int n) const { return getSMPNode(MySMP,n);}
108 unsigned int getSMPNode(unsigned int smp, unsigned int n) const {
109 return SMPList[smp]->NodeList[n];
110 }
111
112 // return the Box0 node of the Nth SMP
113 unsigned int getSMPBox0() const { return getSMPBox0(MySMP); }
114 unsigned int getSMPBox0(unsigned int smp) const {
115 return SMPList[smp]->Box0Node;
116 }
117
118 // return the number of filesets being read/written on the Nth smp
119 unsigned int getNumFiles() const { return getNumFiles(MySMP); }
120 unsigned int getNumFiles(unsigned int smp) const {
121 return SMPList[smp]->BaseFileNum;
122 }
123
124 // return the base name of the mth fileset on the Nth smp
125 const std::string &getFilename(unsigned int fn) const {
126 return getFilename(MySMP, fn);
127 }
128 const std::string &getFilename(unsigned int smp, unsigned int fn) const {
129 return SMPList[smp]->BaseFileName[fn];
130 }
131
132 // return the number of SMP's which depend on getting info from the Nth SMP
133 unsigned int getNumOtherSMP() const { return getNumOtherSMP(MySMP); }
134 unsigned int getNumOtherSMP(unsigned int smp) const {
135 return SMPList[smp]->InformSMPList.size();
136 }
137
138 // return the index of the mth SMP which depends on info from the Nth SMP
139 unsigned int getOtherSMP(unsigned int sn) const {
140 return getOtherSMP(MySMP, sn);
141 }
142 unsigned int getOtherSMP(unsigned int smp, unsigned int sn) const {
143 return SMPList[smp]->InformSMPList[sn];
144 }
145
146 //
147 // Node accessor functions
148 //
149
150 // compute how many physical nodes there are on the same SMP as that w/node
151 unsigned int pNodesPerSMP(unsigned int node) const;
152
153 // return the total number of nodes
154 unsigned int getNumNodes() const { return NodeList.size(); }
155
156 // return the SMP index for the Nth node
157 unsigned int getNodeSMPIndex(unsigned int n) const {
158 return NodeList[n]->SMPIndex;
159 }
160
161 // return the hostname for the Nth node
162 const std::string &getNodeHost(unsigned int n) const {
163 return NodeList[n]->HostName;
164 }
165
166
167 //
168 // utility functions
169 //
170
171 // a simple routine to take an input string and a list of token separators,
172 // and return the number of tokens plus fill in a new array of strings
173 // with the words. We had a nicer way to do this with a vector of strings,
174 // but a #*#^@($ bug in KCC requires this workaround.
175 static int dc_tokenize_string(const char *s, const char *tok, std::string *&);
176
177 // print out debugging information to the given Inform stream
178 void printDebug(Inform &);
179
180private:
181 // Data needed for each SMP being used to read/write data.
182 // Note that BaseFileNameStringList is being used here to store
183 // a list of names only for use in constructing the BaseFileName list;
184 // due to a bug in the use of vector<string> with KCC (debug only),
185 // we cannot use the much more useful vector<string> to store the
186 // fileset directory names. Sigh.
187 struct SMPData {
188 std::string HostName;
189 std::string * BaseFileName;
191 std::vector<int> NodeList;
192 std::vector<int> InformSMPList;
193 unsigned int Box0Node;
194 unsigned int SMPIndex;
195 unsigned int BaseFileNum;
196 };
197
198 // Data needed for each pnode
199 struct NodeData {
200 std::string HostName;
201 unsigned int SMPIndex;
202 };
203
204 // The name of the configuration file
205 std::string ConfigFile;
206
207 // the number of SMP boxes found during setup and in the files,
208 // and which SMP this node is on (0 ... NumSMPs - 1)
209 unsigned int NumSMPs;
210 unsigned int FileSMPs;
211 unsigned int MySMP;
212
213 // was the configuration file read successfully? If not, we cannot
214 // do any read/write operations.
216
217 // data for each SMP, and for each physical node. These are built
218 // when the config file is parsed and the system is analyzed.
219 // vmap: key = hostname for SMP, value = SMPData structure
221 std::vector<SMPData *> SMPList;
222 std::vector<NodeData *> NodeList;
223
224 // take a string with configuration filename wildcards, and substitute
225 // in the specific values.
226 // The first argument is the original string with wildcards (listed below),
227 // and the second is the machine name to use when substituting in the
228 // machine name.
229 // Return a new string with the changes in place.
230 std::string replace_wildcards(const std::string& s, const std::string& machine);
231
232 // take the information about the directory and hostname for a given
233 // SMP, and add it to the list of directories for that SMP. Make sure
234 // the directory is not repeated. If it is, issue a warning and continue.
235 // Must be told if we're writing a file (otherwise, we're reading)
236 void add_SMP_directory(SMPData *&, const std::string& s, const std::string& m, bool);
237
238 // parse the IO configuration file and store the information. Must be
239 // told if we're writing a file (otherwise, we're reading)
240 bool parse_config(const char *, bool);
241};
242
243#endif // DISC_CONFIG_H
244
245/***************************************************************************
246 * $RCSfile: DiscConfig.h,v $ $Author: adelmann $
247 * $Revision: 1.1.1.1 $ $Date: 2003/01/23 07:40:33 $
248 * IPPL_VERSION_ID: $Id: DiscConfig.h,v 1.1.1.1 2003/01/23 07:40:33 adelmann Exp $
249 ***************************************************************************/
unsigned int getNodeSMPIndex(unsigned int n) const
Definition: DiscConfig.h:157
unsigned int getSMPNode(unsigned int smp, unsigned int n) const
Definition: DiscConfig.h:108
unsigned int getSMPBox0(unsigned int smp) const
Definition: DiscConfig.h:114
unsigned int getSMPIndex(const std::string &smpname) const
Definition: DiscConfig.h:90
unsigned int getOtherSMP(unsigned int sn) const
Definition: DiscConfig.h:139
std::vector< SMPData * > SMPList
Definition: DiscConfig.h:221
std::string replace_wildcards(const std::string &s, const std::string &machine)
Definition: DiscConfig.cpp:150
vmap< std::string, SMPData * > SMPMap
Definition: DiscConfig.h:220
const std::string & getConfigFile() const
Definition: DiscConfig.h:76
unsigned int getSMPBox0() const
Definition: DiscConfig.h:113
unsigned int getNumNodes() const
Definition: DiscConfig.h:154
bool ok() const
Definition: DiscConfig.h:73
unsigned int fileSMPs() const
Definition: DiscConfig.h:81
unsigned int getNumOtherSMP() const
Definition: DiscConfig.h:133
unsigned int getNumFiles(unsigned int smp) const
Definition: DiscConfig.h:120
unsigned int numSMPs() const
Definition: DiscConfig.h:80
std::vector< NodeData * > NodeList
Definition: DiscConfig.h:222
unsigned int getSMPNode(unsigned int n) const
Definition: DiscConfig.h:107
unsigned int getSMPIndex() const
Definition: DiscConfig.h:89
const std::string & getSMPHost() const
Definition: DiscConfig.h:95
unsigned int getNumSMPNodes() const
Definition: DiscConfig.h:101
unsigned int getNumSMPNodes(unsigned int smp) const
Definition: DiscConfig.h:102
const std::string & getFilename(unsigned int fn) const
Definition: DiscConfig.h:125
unsigned int MySMP
Definition: DiscConfig.h:211
unsigned int FileSMPs
Definition: DiscConfig.h:210
unsigned int mySMP() const
Definition: DiscConfig.h:82
bool ConfigOK
Definition: DiscConfig.h:215
std::string ConfigFile
Definition: DiscConfig.h:205
const std::string & getFilename(unsigned int smp, unsigned int fn) const
Definition: DiscConfig.h:128
const std::string & getSMPHost(unsigned int smp) const
Definition: DiscConfig.h:96
void add_SMP_directory(SMPData *&, const std::string &s, const std::string &m, bool)
Definition: DiscConfig.cpp:234
unsigned int getNumOtherSMP(unsigned int smp) const
Definition: DiscConfig.h:134
void printDebug(Inform &)
Definition: DiscConfig.cpp:533
const std::string & getNodeHost(unsigned int n) const
Definition: DiscConfig.h:162
DiscConfig(const char *, const char *, bool)
Definition: DiscConfig.cpp:81
static int dc_tokenize_string(const char *s, const char *tok, std::string *&)
Definition: DiscConfig.cpp:46
unsigned int getNumFiles() const
Definition: DiscConfig.h:119
bool parse_config(const char *, bool)
Definition: DiscConfig.cpp:297
unsigned int NumSMPs
Definition: DiscConfig.h:209
unsigned int getOtherSMP(unsigned int smp, unsigned int sn) const
Definition: DiscConfig.h:142
unsigned int pNodesPerSMP(unsigned int node) const
Definition: DiscConfig.cpp:123
std::string BaseFileNameStringList
Definition: DiscConfig.h:190
std::string * BaseFileName
Definition: DiscConfig.h:189
unsigned int SMPIndex
Definition: DiscConfig.h:194
std::string HostName
Definition: DiscConfig.h:188
std::vector< int > InformSMPList
Definition: DiscConfig.h:192
std::vector< int > NodeList
Definition: DiscConfig.h:191
unsigned int BaseFileNum
Definition: DiscConfig.h:195
unsigned int Box0Node
Definition: DiscConfig.h:193
std::string HostName
Definition: DiscConfig.h:200
unsigned int SMPIndex
Definition: DiscConfig.h:201
Definition: Inform.h:42
Definition: vmap.h:59