19 fprintf(
ioQQQ,
" ************************************************** GRID_DELIMIT" );
27 int main(
int argc,
char *argv[] )
40 int nCPU = 1, nRANK = 0;
58 exit_status =
cdMain( argc, (
const char**)argv );
86 const char** mpi_argv =
new const char*[argc+2];
89 for(
int i=0; i < argc; ++i )
90 mpi_argv[i] = argv[i];
91 mpi_argv[argc] =
"-g";
92 mpi_argv[argc+1] = jobName.c_str();
99 exit_status =
max( retval, exit_status );
119 for(
long n=1; n <
cpu.
i().
nCPU(); ++n )
122 oss <<
".err" << setfill(
'0') << setw(2) << n;
124 FILE *io =
open_data( slave_output.c_str(),
"a" );
125 bool lgEmpty = ( ftell(io) == 0 );
128 remove( slave_output.c_str() );
142 long int NumberWarnings,
185 for( i=1; i < argc; i++ )
188 if( *s !=
'-' || s[1] ==
'\0' )
192 fprintf(
ioQQQ,
"%s: only one input file argument allowed\n", argv[0] );
198 fprintf(
ioQQQ,
"%s %s: read/write from subdirectories is not supported\n",
199 argv[0], infile.c_str() );
205 fprintf(
ioQQQ,
"%s: input filename `%s' not found\n", argv[0], infile.c_str() );
209 size_t suffindex = infile.find_last_of(
".");
210 if (suffindex != string::npos)
211 infile = infile.substr(0,suffindex);
212 pprefix = rprefix = infile.c_str();
217 while( s != NULL && *(++s) )
234 if( ++i == argc || argv[i][0] ==
'-' )
243 fprintf(
ioQQQ,
"%s -%c %s: writing in subdirectories is not supported\n",
244 argv[0], *s, prefix );
267 fprintf(
ioQQQ,
"%s: argument %d, `%s': flag -%c not understood\n",
268 argv[0], i, argv[i], *s );
273 fprintf(
ioQQQ,
" Cloudy reads the input from the file example.in\n" );
274 fprintf(
ioQQQ,
" and writes the output to the file example.out.\n" );
275 fprintf(
ioQQQ,
" Additionally, all file names in SAVE commands are\n" );
276 fprintf(
ioQQQ,
" prepended with the string \"example\", e.g. the\n" );
277 fprintf(
ioQQQ,
" output of SAVE DR \".dr\" will be in example.dr.\n" );
279 fprintf(
ioQQQ,
" This does the same as the -p switch, except that\n" );
280 fprintf(
ioQQQ,
" the names used in SAVE commands are not altered.\n" );
282 fprintf(
ioQQQ,
" This switch is used internally in MPI grid runs.\n" );
283 fprintf(
ioQQQ,
" Normal users should not use this switch.\n" );
285 fprintf(
ioQQQ,
" This switch is used in debugging. It causes the\n" );
286 fprintf(
ioQQQ,
" code to crash rather than exit gracefully after\n" );
287 fprintf(
ioQQQ,
" a failed assert. This flag is deprecated.\n" );
307 string InName = Base +
".in";
310 OutName = Base +
".out";
314 oss <<
".err" << setfill(
'0') << setw(2) <<
cpu.
i().
nRANK();
315 OutName = Base + oss.str();
317 cdInput( InName.c_str(),
"r" );
333 if( chLine[0] ==
'\n' || chLine[0] ==
'\r' ||
334 ( chLine[0] ==
' ' && chLine[23] !=
'*' ) ||
335 (strncmp( chLine ,
"***" , 3 )==0 ) )
341 bool lgEscape=
false, lgQuoted=
false;
342 for (
char *s=chLine; *s !=
'\0'; ++s)
344 if (lgQuoted && *s ==
'\\')
349 if ( *s ==
'\"' && !lgEscape )
351 lgQuoted = !lgQuoted;
353 else if ( *s ==
'_' && !lgQuoted )
358 else if ( (*s ==
'[' || *s ==
']') && !lgQuoted )
369 if( strncmp(chLine,
" * ",25) == 0 )
372 nread =
cdRead( chLine+25 );
388 fprintf(
ioQQQ,
" Warning: limit to number of lines exceeded, %i\n", nread);
396 fprintf(
ioQQQ,
" Please use the style \"mpirun -n np /path/to/cloudy.exe -r input\" when doing grid\n"
397 " or optimizer runs. See http://trac.nublado.org/wiki/RunCode for more information.\n" );
399 fprintf(
ioQQQ,
" Please use the style \"/path/to/cloudy.exe -r input\" when doing grid\n"
400 " or optimizer runs. See http://trac.nublado.org/wiki/RunCode for more information.\n" );
433 ostringstream finalMsg;
435 finalMsg <<
" Cloudy ends: " <<
nzone <<
" zone";
439 finalMsg <<
", " <<
iteration <<
" iteration";
444 finalMsg <<
", ABORT DISASTER PROBLEM";
446 if( NumberWarnings > 0 )
448 finalMsg <<
", " << NumberWarnings <<
" warning";
449 if( NumberWarnings > 1 )
455 if( NumberCautions > 0 )
457 finalMsg <<
", " << NumberCautions <<
" caution";
458 if( NumberCautions > 1 )
469 finalMsg <<
"BOTCHED MONITORS!!!";
474 if( NumberTempFailures+NumberPresFailures+NumberIonFailures+NumberNeFailures > 0 )
476 finalMsg <<
". Failures: " << NumberTempFailures <<
" thermal, ";
477 finalMsg << NumberPresFailures <<
" pressure, ";
478 finalMsg << NumberIonFailures <<
" ionization, ";
479 finalMsg << NumberNeFailures <<
" electron density";
486 finalMsg <<
". (single thread)";
490 finalMsg <<
". (" <<
cpu.
i().
used_nCPU() <<
" forked threads)";
497 finalMsg <<
" Max memory used " <<
cdMemory() <<
"kB.";
503 finalMsg <<
" ExecTime(s) " << fixed << setprecision(2) <<
cdExecTime();
513 lgEarly_exit =
false;
521 fprintf(
ioQQQ,
" DISASTER - A memory allocation has failed. Most likely your computer "
522 "ran out of memory.\n Try monitoring the memory use of your run. Bailing out...\n" );
525 catch( out_of_range& e )
527 fprintf(
ioQQQ,
" DISASTER - An out_of_range exception was caught, what() = %s. Bailing out...\n",
531 catch( domain_error& e )
533 fprintf(
ioQQQ,
" DISASTER - A vectorized math routine threw a domain_error. Bailing out...\n" );
547 if( e.
sig() == SIGINT || e.
sig() == SIGQUIT )
549 fprintf(
ioQQQ,
" User interrupt request. Bailing out...\n" );
552 else if( e.
sig() == SIGTERM )
554 fprintf(
ioQQQ,
" Termination request. Bailing out...\n" );
557 else if( e.
sig() == SIGILL )
559 fprintf(
ioQQQ,
" DISASTER - An illegal instruction was found. Bailing out...\n" );
562 else if( e.
sig() == SIGFPE )
564 fprintf(
ioQQQ,
" DISASTER - A floating point exception occurred. Bailing out...\n" );
567 else if( e.
sig() == SIGSEGV )
569 fprintf(
ioQQQ,
" DISASTER - A segmentation violation occurred. Bailing out...\n" );
573 else if( e.
sig() == SIGBUS )
575 fprintf(
ioQQQ,
" DISASTER - A bus error occurred. Bailing out...\n" );
581 fprintf(
ioQQQ,
" DISASTER - A signal %d was caught. Bailing out...\n", e.
sig() );
593 oss <<
" [Stop in " << e.
routine();
594 oss <<
" at " << e.
file() <<
":" << e.
line();
596 oss <<
", Cloudy exited OK]";
598 oss <<
", something went wrong]";
610 if( exit_status ==
ES_FAILURE && !lgEarly_exit )
615 if( NumberWarnings > 0 )
623 catch( std::exception& e )
625 fprintf(
ioQQQ,
" DISASTER - An unknown exception was caught, what() = %s. Bailing out...\n",
632 fprintf(
ioQQQ,
" DISASTER - An unknown exception was caught. Bailing out...\n" );
#define MPI_Comm_size(Y, Z)
const char * file() const
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
void set_used_nCPU(long n)
void finalize(exit_type exit_status)
exit_type exit_status() const
NORETURN void TotalInsanity(void)
const char * file() const
const char * routine() const
void cdInput(const char *filename, const char *mode)
void setAssertAbort(bool val)
int cdRead(const char *chInputLine)
exit_type cdMain(int argc, const char *argv[])
void cdOutput(const char *filename, const char *mode)
void GridGatherInCloudy(void)
const int INPUT_LINE_LENGTH
int main(int argc, char *argv[])
void MyAssert(const char *file, int line, const char *comment)
const char * comment() const
void print_delimiter(long nOptimiz)
#define DEBUG_ENTRY(funcname)
void set_signal_handlers()
void set_MPISingleRankMode(bool mode)
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)
#define MPI_Comm_rank(Y, Z)
int fprintf(const Output &stream, const char *format,...)
char * read_whole_line(char *chLine, int nChar, FILE *ioIN)
string GridPointPrefix(int n)
void SetSaveHeaderNeeded(bool lgVal)
void cdPrepareExit(exit_type)
char chDirSeparator() const
bool lgMPISingleRankMode() const