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 );
89 const char** mpi_argv =
new const char*[argc+2];
92 for(
int i=0; i < argc; ++i )
93 mpi_argv[i] = argv[i];
94 mpi_argv[argc] =
"-g";
95 mpi_argv[argc+1] = jobName.c_str();
100 retval =
cdMain( argc+2, mpi_argv );
102 exit_status =
max( retval, exit_status );
122 (void)
cdMain( argc, (
const char**)argv );
132 for(
long n=1; n <
cpu.
i().
nCPU(); ++n )
135 oss <<
".err" << setfill(
'0') << setw(2) << n;
137 FILE *io =
open_data( slave_output.c_str(),
"a" );
138 bool lgEmpty = ( ftell(io) == 0 );
141 remove( slave_output.c_str() );
155 long int NumberWarnings,
175 char *outfile = NULL;
193 for( i=1; i < argc; i++ )
196 if( *s !=
'-' || s[1] ==
'\0' )
200 fprintf(
ioQQQ,
"%s: only one input file argument allowed\n", argv[0] );
206 fprintf(
ioQQQ,
"%s %s: read/write from subdirectories is not supported\n",
207 argv[0], infile.c_str() );
215 fprintf(
ioQQQ,
" input file \"%s\" not found\n", infile.c_str() );
219 size_t suffindex = infile.find_last_of(
".");
220 if (suffindex != string::npos)
221 infile = infile.substr(0,suffindex);
222 pprefix = rprefix = infile.c_str();
228 while( s != NULL && *(++s) )
245 if( ++i == argc || argv[i][0] ==
'-' )
254 fprintf(
ioQQQ,
"%s -%c %s: writing in subdirectories is not supported\n",
255 argv[0], *s, prefix );
278 fprintf(
ioQQQ,
"%s: argument %d, `%s': flag -%c not understood\n",
279 argv[0], i, argv[i], *s );
285 fprintf(
ioQQQ,
" Cloudy reads the input from the file example.in\n" );
286 fprintf(
ioQQQ,
" and writes the output to the file example.out.\n" );
287 fprintf(
ioQQQ,
" Additionally, all file names in SAVE commands are\n" );
288 fprintf(
ioQQQ,
" prepended with the string \"example\", e.g. the\n" );
289 fprintf(
ioQQQ,
" output of SAVE DR \".dr\" will be in example.dr.\n" );
291 fprintf(
ioQQQ,
" This does the same as the -p switch, except that\n" );
292 fprintf(
ioQQQ,
" the names used in SAVE commands are not altered.\n" );
294 fprintf(
ioQQQ,
" This switch is used internally in MPI grid runs.\n" );
295 fprintf(
ioQQQ,
" Normal users should not use this switch.\n" );
297 fprintf(
ioQQQ,
" This switch is used in debugging. It causes the\n" );
298 fprintf(
ioQQQ,
" code to crash rather than exit gracefully after\n" );
299 fprintf(
ioQQQ,
" a failed assert. This flag is deprecated.\n" );
327 outfile =
new char[Base.length()+8];
328 string OutName( Base +
".XXXXXX" );
329 strcpy( outfile, OutName.c_str() );
330 int fd = mkstemp( outfile );
331 cdOutput( outfile, fdopen(fd,
"w") );
340 oss <<
".err" << setfill(
'0') << setw(2) <<
cpu.
i().
nRANK();
352 bool lgReadingOutput = ( strncmp(chLine,
" * ",25) == 0 );
353 char* chLocal = lgReadingOutput ? chLine+25 : chLine;
375 fprintf(
ioQQQ,
" Please use the style \"mpirun -n np /path/to/cloudy.exe -r input\" when doing grid\n"
376 " or optimizer runs. See http://trac.nublado.org/wiki/RunCode for more information.\n" );
378 fprintf(
ioQQQ,
" Please use the style \"/path/to/cloudy.exe -r input\" when doing grid\n"
379 " or optimizer runs. See http://trac.nublado.org/wiki/RunCode for more information.\n" );
412 ostringstream finalMsg;
414 finalMsg <<
" Cloudy ends: " <<
nzone <<
" zone";
418 finalMsg <<
", " <<
iteration <<
" iteration";
423 finalMsg <<
", ABORT DISASTER PROBLEM";
425 if( NumberWarnings > 0 )
427 finalMsg <<
", " << NumberWarnings <<
" warning";
428 if( NumberWarnings > 1 )
434 if( NumberCautions > 0 )
436 finalMsg <<
", " << NumberCautions <<
" caution";
437 if( NumberCautions > 1 )
448 finalMsg <<
"BOTCHED MONITORS!!!";
453 if( NumberTempFailures+NumberPresFailures+NumberIonFailures+NumberNeFailures > 0 )
455 finalMsg <<
". Failures: " << NumberTempFailures <<
" thermal, ";
456 finalMsg << NumberPresFailures <<
" pressure, ";
457 finalMsg << NumberIonFailures <<
" ionization, ";
458 finalMsg << NumberNeFailures <<
" electron density";
465 finalMsg <<
". (single thread)";
469 finalMsg <<
". (" <<
cpu.
i().
used_nCPU() <<
" forked threads)";
476 finalMsg <<
" Max memory used " <<
cdMemory() <<
"kB.";
482 finalMsg <<
" ExecTime(s) " << fixed << setprecision(2) <<
cdExecTime();
492 lgEarly_exit =
false;
500 fprintf(
ioQQQ,
" DISASTER - A memory allocation has failed. Most likely your computer "
501 "ran out of memory.\n Try monitoring the memory use of your run. Bailing out...\n" );
504 catch( out_of_range& e )
506 fprintf(
ioQQQ,
" DISASTER - An out_of_range exception was caught, what() = %s. Bailing out...\n",
510 catch( domain_error& e )
512 fprintf(
ioQQQ,
" DISASTER - A vectorized math routine threw a domain_error. Bailing out...\n" );
526 if( e.
sig() == SIGINT || e.
sig() == SIGQUIT )
528 fprintf(
ioQQQ,
" User interrupt request. Bailing out...\n" );
531 else if( e.
sig() == SIGTERM )
533 fprintf(
ioQQQ,
" Termination request. Bailing out...\n" );
536 else if( e.
sig() == SIGILL )
538 fprintf(
ioQQQ,
" DISASTER - An illegal instruction was found. Bailing out...\n" );
541 else if( e.
sig() == SIGFPE )
543 fprintf(
ioQQQ,
" DISASTER - A floating point exception occurred. Bailing out...\n" );
546 else if( e.
sig() == SIGSEGV )
548 fprintf(
ioQQQ,
" DISASTER - A segmentation violation occurred. Bailing out...\n" );
552 else if( e.
sig() == SIGBUS )
554 fprintf(
ioQQQ,
" DISASTER - A bus error occurred. Bailing out...\n" );
560 fprintf(
ioQQQ,
" DISASTER - A signal %d was caught. Bailing out...\n", e.
sig() );
572 oss <<
" [Stop in " << e.
routine();
573 oss <<
" at " << e.
file() <<
":" << e.
line();
575 oss <<
", Cloudy exited OK]";
577 oss <<
", something went wrong]";
589 if( exit_status ==
ES_FAILURE && !lgEarly_exit )
594 if( NumberWarnings > 0 )
602 catch( std::exception& e )
604 fprintf(
ioQQQ,
" DISASTER - An unknown exception was caught, what() = %s. Bailing out...\n",
611 fprintf(
ioQQQ,
" DISASTER - An unknown exception was caught. Bailing out...\n" );
620 if( outfile != NULL )
#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 setAssertAbort(bool val)
int cdRead(const char *chInputLine)
void cdInput(const string &filename, const char *mode)
exit_type cdMain(int argc, const char *argv[])
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 cdOutput(const string &filename, const char *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