41 #ifdef IPPL_PRINTDEBUG
56 char *tempstring =
new char[strlen(s) + 1];
57 strcpy(tempstring, s);
59 char* tokenp = strtok(tempstring, tok);
62 tokenp = strtok(0, tok);
68 slist =
new string[num];
70 strcpy(tempstring, s);
71 tokenp = strtok(tempstring, tok);
73 slist[num++] = tokenp;
74 tokenp = strtok(0, tok);
89 : NumSMPs(0), FileSMPs(0), MySMP(0), ConfigOK(false) {
95 ERRORMSG(
"Null base filename in DiscConfig constructor." <<
endl);
111 while (smpiter != smpend) {
112 if ((*smpiter)->BaseFileNum > 0)
113 delete [] (*smpiter)->BaseFileName;
120 while (nodeiter != nodeend)
121 delete (*nodeiter++);
130 unsigned int nodesmp =
NodeList[node]->SMPIndex;
134 unsigned int numnodes =
SMPList[nodesmp]->NodeList.size();
157 const string& machine) {
163 if (s.length() == 0 || machine.length() == 0)
168 char *sptrbase = (
char*) scpy.c_str();
171 if (s.length() > 2 && s[0] ==
'.' && s[1] ==
'/')
175 char *sptr = sptrbase;
176 while (*sptr !=
'\0') {
181 if (sptr != sptrbase) {
190 while (*tok1 !=
'(' && *tok1 !=
'\0') ++tok1;
191 while (*tok2 !=
')' && *tok2 !=
'\0') ++tok2;
192 if (*tok1 ==
'\0' || *tok2 ==
'\0' || *tok2 <= *tok1) {
193 ERRORMSG(
"Unbalanced parenthesis in DiscConfig config file in line ");
201 string token(tok1 + 1);
204 }
else if (token ==
"node" || token ==
"n" || token ==
"N") {
210 char *env = getenv(token.c_str());
214 ERRORMSG(
"Unknown wildcard name '" << token.c_str()<<
"' in line ");
223 sptr = sptrbase = tok2 + 1;
228 if (sptr != sptrbase)
242 const string& machine,
264 for (
unsigned int sptr=0; sptr < smpd->
BaseFileNum; ++sptr) {
265 if (strcmp(basename.c_str(), (smpd->
BaseFileName[sptr]).c_str()) == 0) {
266 WARNMSG(
"DiscConfig: Duplicate configuration file entry '" << basename);
267 WARNMSG(
"' for host " << machine <<
" ... second one ignored." <<
endl);
277 WARNMSG(
"DiscConfig: Cannot write to more than one file per");
278 WARNMSG(
" SMP. Only the first file listed for host '");
305 const int bufferSize = 1024;
306 char bufferstore[bufferSize];
311 string NodeNameItems;
313 CDCDBG(
string dbgmsgname(
"DC:parse_config:"));
334 if (gethostname(name, 1023) != 0) {
335 WARNMSG(
"DiscConfig: Could not get hostname. Using localhost." <<
endl);
336 strcpy(name,
"localhost");
338 NodeNameItems =
name;
340 CDCDBG(dbgmsg <<
" My hostname is " << NodeNameItems <<
endl);
362 if ((inC = fopen(
ConfigFile.c_str(),
"r")) != 0) {
364 while (fgets(bufferstore, bufferSize, inC) != 0) {
365 CDCDBG(dbgmsg <<
"Read config line '" << bufferstore <<
"'." <<
endl);
367 buffer = bufferstore;
368 while (*buffer ==
' ' || *buffer ==
'\t' || *buffer ==
'\n')
370 if (*buffer ==
'#' || *buffer ==
'\0')
372 ConfigItems += buffer;
380 if (ConfigItems.length() == 0) {
381 CDCDBG(dbgmsg <<
"Using default DiscConfig configuration '* .'" <<
endl);
388 NodeNameItems +=
" 0";
390 while (unreceived-- > 0) {
397 sprintf(name,
" %s %d", nodename.c_str(), node);
398 NodeNameItems +=
name;
403 if (Ippl::getNodes() > 1) {
407 CDCDBG(dbgmsg <<
" Broadcasting config info " << ConfigItems <<
endl);
408 CDCDBG(dbgmsg <<
" Broadcasting node names " << NodeNameItems <<
endl);
415 CDCDBG(dbgmsg <<
" My ConfigItems = " << ConfigItems <<
endl);
418 CDCDBG(dbgmsg <<
" Parsed config line list into " << conflinenum);
420 for (
int is=0; is < conflinenum; ++is) {
421 CDCDBG(dbgmsg <<
" Examining confline " << is <<
" = '");
422 CDCDBG(dbgmsg << conflines[is] <<
"'." <<
endl);
427 CDCDBG(dbgmsg <<
" Parsed config line " << is <<
" into " << ntok);
428 CDCDBG(dbgmsg <<
" words:");
429 for (
int ntok2=0; ntok2 < ntok; ++ntok2) {
430 CDCDBG(dbgmsg <<
" '" << tokens[ntok2] <<
"'");
434 ERRORMSG(
"Wrong number of parameters in DiscConfig config file ");
438 CDCDBG(dbgmsg <<
"Looking at tokens '" << tokens[0].c_str());
439 CDCDBG(dbgmsg <<
"' '" << tokens[1].c_str() <<
"'." <<
endl);
441 if (tokens[1].c_str()[tokens[1].length() - 1] !=
'/')
443 tokens[1] += BaseFile;
444 if (tokens[0] ==
"*") {
446 CDCDBG(dbgmsg <<
" ... Wildcard token." <<
endl);
447 WildCard = tokens[1];
451 CDCDBG(dbgmsg <<
" ... SMP info token." <<
endl);
454 if (smpiter !=
SMPMap.end())
455 smpd = (*smpiter).second;
470 if (
SMPMap.size() < 1 && WildCard.length() == 0) {
471 ERRORMSG(
"No hostname/directory pairs found in DiscConfig config file ");
478 CDCDBG(dbgmsg <<
" My NodeNameItems = " << NodeNameItems <<
endl);
480 #ifdef IPPL_PRINTDEBUG
482 CDCDBG(dbgmsg <<
" Parsed node name list into " << nodenamenum);
489 CDCDBG(dbgmsg <<
" converting to node from nodestring '");
490 CDCDBG(dbgmsg << nodenames[2*in + 1] <<
"'" <<
endl);
491 CDCDBG(dbgmsg <<
" converting to node from nodename '");
492 CDCDBG(dbgmsg << nodenames[2*in] <<
"'" <<
endl);
493 int node = atoi(nodenames[2*in + 1].c_str());
494 string machine = nodenames[2*in];
499 if (smpiter !=
SMPMap.end()) {
501 CDCDBG(dbgmsg <<
" SMP " << machine <<
" found in SMPMap." <<
endl);
502 smpdata = (*smpiter).second;
507 CDCDBG(dbgmsg <<
" SMP " << machine <<
" not found in SMPMap." <<
endl);
521 int firstSMPWithFiles = (-1);
522 CDCDBG(dbgmsg <<
"Assigning numbers to " <<
SMPMap.size()<<
" SMP's"<<
endl);
524 for (smpa =
SMPMap.begin() ; smpa !=
SMPMap.end(); ++smpa) {
526 SMPData *smpdata = (*smpa).second;
533 if (firstSMPWithFiles < 0 && smpdata->BaseFileNum > 0)
534 firstSMPWithFiles = smpdata->
SMPIndex;
545 ERRORMSG(
"' was listed in the config file\n");
553 for ( ; nodea != smpdata->
NodeList.end(); ++nodea)
566 for (smpa =
SMPMap.begin() ; smpa !=
SMPMap.end(); ++smpa) {
567 SMPData *smpdata = (*smpa).second;
571 SMPList[firstSMPWithFiles]->InformSMPList.push_back(smpdata->
SMPIndex);
594 msg <<
"DiscConfig SMP Summary:" <<
endl;
595 for (
unsigned int smp=0; smp <
numSMPs(); ++smp) {
599 msg <<
" FileList =";
600 for (
unsigned int fl=0; fl <
getNumFiles(smp); ++fl)
603 msg <<
" OtherSMPList =";
607 msg <<
" NodeList =";
614 msg <<
"DiscConfig Node Summary:" <<
endl;
const std::string & getConfigFile() const
static void abort(const char *=0, int exitcode=(-1))
std::string replace_wildcards(const std::string &s, const std::string &machine)
static int dc_tokenize_string(const char *s, const char *tok, std::string *&)
const std::string & getSMPHost() const
unsigned int getNumSMPNodes() const
unsigned int fileSMPs() const
int next_tag(int t, int s=1000)
unsigned int getNumOtherSMP() const
DiscConfig(const char *, const char *, bool)
void add_SMP_directory(SMPData *&, const std::string &s, const std::string &m, bool)
void printDebug(Inform &)
unsigned int pNodesPerSMP(unsigned int node) const
std::vector< NodeData * > NodeList
virtual int broadcast_others(Message *, int, bool delmsg=true)
unsigned int numSMPs() const
unsigned int mySMP() const
unsigned int getOtherSMP(unsigned int sn) const
unsigned int getSMPNode(unsigned int n) const
std::pair< Key, T > value_type
std::vector< SMPData * > SMPList
#define DF_MAKE_HOST_MAP_TAG
std::string * BaseFileName
void getMessage(Message &m, T &t)
unsigned int getNumNodes() const
const std::string & getNodeHost(unsigned int n) const
const std::string & getFilename(unsigned int fn) const
std::string::iterator iterator
void putMessage(Message &m, const T &t)
unsigned int getSMPBox0() const
vmap< std::string, SMPData * > SMPMap
rep_type::iterator iterator
Message * receive_block(int &node, int &tag)
unsigned int getNodeSMPIndex(unsigned int n) const
static Communicate * Comm
bool send(Message *, int node, int tag, bool delmsg=true)
unsigned int getNumFiles() const
std::vector< int > NodeList
std::string BaseFileNameStringList
bool parse_config(const char *, bool)
Inform & endl(Inform &inf)