28int main(
int argc,
char *argv[] )
36 MPI::Init( argc, argv );
43 cpu.i().set_signal_handlers();
48 exit_status =
cdMain( argc, (
const char**)argv );
58 grid.lgGridDone =
false;
61 cpu.i().set_MPISingleRankMode(
true );
69 const char** mpi_argv =
new const char*[argc+2];
72 for(
int i=0; i < argc; ++i )
73 mpi_argv[i] = argv[i];
74 mpi_argv[argc] =
"-g";
75 mpi_argv[argc+1] = jobName.c_str();
79 exit_status =
max( retval, exit_status );
88 grid.lgGridDone =
true;
93 if(
cpu.i().lgMaster() )
98 if(
cpu.i().lgMPI() &&
cpu.i().lgMaster() )
100 for(
long n=1; n <
cpu.i().nCPU(); ++n )
103 oss <<
".err" << setfill(
'0') << setw(2) << n;
104 string slave_output =
save.chRedirectPrefix + oss.str();
106 bool lgEmpty = ( ftell(io) == 0 );
109 remove( slave_output.c_str() );
113 if(
cpu.i().lgMPI() )
123 long int NumberWarnings,
166 for( i=1; i < argc; i++ )
169 if( *s !=
'-' || s[1] ==
'\0' )
173 fprintf(
ioQQQ,
"%s: only one input file argument allowed\n", argv[0] );
177 if( infile.find(
cpu.i().chDirSeparator() ) != string::npos )
179 fprintf(
ioQQQ,
"%s %s: read/write from subdirectories is not supported\n",
180 argv[0], infile.c_str() );
183 FILE *fp = fopen(infile.c_str(),
"r");
186 fprintf(
ioQQQ,
"%s: input filename `%s' not found\n", argv[0], infile.c_str() );
190 size_t suffindex = infile.find_last_of(
".");
191 if (suffindex != string::npos)
192 infile = infile.substr(0,suffindex);
193 pprefix = rprefix = infile.c_str();
198 while( s != NULL && *(++s) )
204 cpu.i().setAssertAbort(
true );
215 if( ++i == argc || argv[i][0] ==
'-' )
217 fprintf(
ioQQQ,
"%s: no argument given for -%c flag\n",
222 if( strchr(prefix,
cpu.i().chDirSeparator()) != NULL )
224 fprintf(
ioQQQ,
"%s -%c %s: writing in subdirectories is not supported\n",
225 argv[0], *s, prefix );
248 fprintf(
ioQQQ,
"%s: argument %d, `%s': flag -%c not understood\n",
249 argv[0], i, argv[i], *s );
252 fprintf(
ioQQQ,
"\nSupported flags are:\n\n" );
253 fprintf(
ioQQQ,
"-p example\n" );
254 fprintf(
ioQQQ,
" Cloudy reads the input from the file example.in\n" );
255 fprintf(
ioQQQ,
" and writes the output to the file example.out.\n" );
256 fprintf(
ioQQQ,
" Additionally, all file names in SAVE commands are\n" );
257 fprintf(
ioQQQ,
" prepended with the string \"example\", e.g. the\n" );
258 fprintf(
ioQQQ,
" output of SAVE DR \".dr\" will be in example.dr.\n" );
259 fprintf(
ioQQQ,
"-r example\n" );
260 fprintf(
ioQQQ,
" This does the same as the -p switch, except that\n" );
261 fprintf(
ioQQQ,
" the names used in SAVE commands are not altered.\n" );
262 fprintf(
ioQQQ,
"-g example\n" );
263 fprintf(
ioQQQ,
" This switch is used internally in MPI grid runs.\n" );
264 fprintf(
ioQQQ,
" Normal users should not use this switch.\n" );
265 fprintf(
ioQQQ,
"-a\n" );
266 fprintf(
ioQQQ,
" This switch is used in debugging. It causes the\n" );
267 fprintf(
ioQQQ,
" code to crash rather than exit gracefully after\n" );
268 fprintf(
ioQQQ,
" a failed assert. This flag is deprecated.\n" );
269 fprintf(
ioQQQ,
"-h\n" );
270 fprintf(
ioQQQ,
" Print this message.\n" );
280 save.chGridPrefix = gprefix;
281 save.chFilenamePrefix = pprefix;
282 save.chRedirectPrefix = rprefix;
287 string Base =
save.chGridPrefix +
save.chRedirectPrefix;
288 string InName = Base +
".in";
290 if(
cpu.i().lgMPI_talk() )
291 OutName = Base +
".out";
295 oss <<
".err" << setfill(
'0') << setw(2) <<
cpu.i().nRANK();
296 OutName = Base + oss.str();
298 cdInput( InName.c_str(),
"r" );
315 if( chLine[0] ==
'\n' || chLine[0] ==
'\r' ||
316 ( chLine[0] ==
' ' && chLine[23] !=
'*' ) ||
317 (strncmp( chLine ,
"***" , 3 )==0 ) )
324 if( (chChar =
strchr_s(chLine ,
'\"' ) ) ==NULL )
327 while( (chChar =
strchr_s(chLine ,
'_' ) ) !=NULL )
330 input.lgUnderscoreFound =
true;
338 while( (chChar =
strchr_s(chLine ,
'[' ) ) !=NULL )
341 input.lgBracketFound =
true;
344 while( (chChar =
strchr_s(chLine ,
']' ) ) !=NULL )
347 input.lgBracketFound =
true;
353 if( strncmp(chLine,
" * ",25) == 0 )
356 nread =
cdRead( chLine+25 );
372 fprintf(
ioQQQ,
" Warning: limit to number of lines exceeded, %i\n", nread);
375 if( (
cpu.i().lgMPI() ||
optimize.lgVaryOn ) &&
save.chRedirectPrefix.empty() )
377 if(
cpu.i().lgMaster() )
379 if(
cpu.i().lgMPI() )
380 fprintf(
ioQQQ,
" Please use the style \"mpirun -n np /path/to/cloudy.exe -r input\" when doing grid\n"
381 "or optimizer runs. See http://trac.nublado.org/wiki/RunCode for more information.\n" );
383 fprintf(
ioQQQ,
" Please use the style \"/path/to/cloudy.exe -r input\" when doing grid\n"
384 "or optimizer runs. See http://trac.nublado.org/wiki/RunCode for more information.\n" );
417 ostringstream finalMsg;
419 finalMsg <<
" Cloudy ends: " <<
nzone <<
" zone";
423 finalMsg <<
", " <<
iteration <<
" iteration";
428 finalMsg <<
", ABORT DISASTER PROBLEM";
430 if( NumberWarnings > 0 )
432 finalMsg <<
", " << NumberWarnings <<
" warning";
433 if( NumberWarnings > 1 )
439 if( NumberCautions > 0 )
441 finalMsg <<
", " << NumberCautions <<
" caution";
442 if( NumberCautions > 1 )
453 finalMsg <<
"BOTCHED MONITORS!!!";
458 if( NumberTempFailures+NumberPresFailures+NumberIonFailures+NumberNeFailures > 0 )
460 finalMsg <<
". Failures: " << NumberTempFailures <<
" thermal, ";
461 finalMsg << NumberPresFailures <<
" pressure, ";
462 finalMsg << NumberIonFailures <<
" ionization, ";
463 finalMsg << NumberNeFailures <<
" electron density";
468 if(
prt.lgPrintTime )
473 finalMsg <<
". ExecTime(s) " << fixed << setprecision(2) <<
cdExecTime();
477 fprintf(
ioQQQ,
"%s\n", finalMsg.str().c_str() );
479 lgEarly_exit =
false;
487 fprintf(
ioQQQ,
" DISASTER - A memory allocation has failed. Most likely your computer "
488 "ran out of memory.\n Try monitoring the memory use of your run. Bailing out...\n" );
491 catch( out_of_range& e )
493 fprintf(
ioQQQ,
" DISASTER - An out_of_range exception was caught, what() = %s. Bailing out...\n",
499 MyAssert( e.file(), e.line() , e.comment() );
507 if( e.sig() == SIGINT || e.sig() == SIGQUIT )
509 fprintf(
ioQQQ,
" User interrupt request. Bailing out...\n" );
512 else if( e.sig() == SIGTERM )
514 fprintf(
ioQQQ,
" Termination request. Bailing out...\n" );
517 else if( e.sig() == SIGILL )
519 fprintf(
ioQQQ,
" DISASTER - An illegal instruction was found. Bailing out...\n" );
522 else if( e.sig() == SIGFPE )
524 fprintf(
ioQQQ,
" DISASTER - A floating point exception occurred. Bailing out...\n" );
527 else if( e.sig() == SIGSEGV )
529 fprintf(
ioQQQ,
" DISASTER - A segmentation violation occurred. Bailing out...\n" );
533 else if( e.sig() == SIGBUS )
535 fprintf(
ioQQQ,
" DISASTER - A bus error occurred. Bailing out...\n" );
541 fprintf(
ioQQQ,
" DISASTER - A signal %d was caught. Bailing out...\n", e.sig() );
553 oss <<
" [Stop in " << e.routine();
554 oss <<
" at " << e.file() <<
":" << e.line();
555 if( e.exit_status() == 0 )
556 oss <<
", Cloudy exited OK]";
558 oss <<
", something went wrong]";
559 fprintf(
ioQQQ,
"%s\n", oss.str().c_str() );
561 exit_status = e.exit_status();
562 if( exit_status ==
ES_FAILURE && !lgEarly_exit )
567 if( NumberWarnings > 0 )
575 catch( std::exception& e )
577 fprintf(
ioQQQ,
" DISASTER - An unknown exception was caught, what() = %s. Bailing out...\n",
584 fprintf(
ioQQQ,
" DISASTER - An unknown exception was caught. Bailing out...\n" );
588 if(
called.lgTalk &&
cpu.i().lgMPISingleRankMode() )
void cdNwcns(bool *lgAbort_ret, long int *NumberWarnings, long int *NumberCautions, long int *NumberNotes, long int *NumberSurprises, long int *NumberTempFailures, long int *NumberPresFailures, long int *NumberIonFailures, long int *NumberNeFailures)
void print_delimiter(long nOptimiz)
exit_type cdMain(int argc, const char *argv[])