9 #if defined(__unix) || defined(__APPLE__)
11 #include <sys/types.h>
16 #define fork() TotalInsanityAsStub<pid_t>()
17 #define wait(X) TotalInsanityAsStub<pid_t>()
24 static const long NFS_SUPER_MAGIC = 0x6969L;
25 static const long SMB_SUPER_MAGIC = 0x517BL;
26 static const long AUTOFS_SUPER_MAGIC = 0x0187L;
28 static const long FUSE_SUPER_MAGIC = 0x65735546L;
50 return TotalInsanityAsStub<int>();
76 for(
unsigned int i=0; i < nJobs; ++i )
83 srand(
unsigned( time(NULL) ) );
91 for(
unsigned int i=1; i <
p_ncpu; ++i )
120 for(
unsigned int i=1; i <
p_ncpu; ++i )
146 vector<long> bound( nCPU+1, stride );
148 for(
long i=1; i <= remainder; ++i )
151 for(
long i=1; i <= nCPU; ++i )
152 bound[i] += bound[i-1];
163 if( j >= bound[nRANK] && j < bound[nRANK+1] )
166 remove( in_name.c_str() );
178 if( j >= bound[nRANK] && j < bound[nRANK+1] )
196 remove( gridnam.c_str() );
199 FILE *dest =
open_data( fnam.c_str(),
"ab" );
203 fseek( dest, 0, SEEK_END );
204 ASSERT( ftell(dest)%2880 == 0 );
213 FILE *dest =
open_data( fnam.c_str(),
"ab" );
221 rename( fnam.c_str(), gridnam.c_str() );
232 fprintf(
ioQQQ,
"PROBLEM - an internal error occurred while post-processing the grid output\n" );
238 const vector<long>& bound)
253 if( output_handle == NULL )
256 for(
long j=0; j < nfiles; ++j )
260 remove( gridnam.c_str() );
262 fclose( output_handle );
267 const vector<long>& bound)
272 for(
long j=0; j < nfiles; ++j )
280 fseek( fh, 0, SEEK_END );
281 mySize +=
static_cast<MPI_Offset>( ftell(fh) );
289 vector<MPI_Offset> offset(
cpu.
i().
nCPU());
290 for(
int i=0; i <
cpu.
i().
nCPU(); ++i )
295 MPI_Bcast( &myCopy, 1, MPI_type(myCopy), i, MPI_COMM_WORLD );
306 for(
int j=0; j <
cpu.
i().
nCPU(); ++j )
309 offset[j] = totalSize;
315 MPI_CHAR, MPI_CHAR,
const_cast<char*
>(
"native"),
317 for(
long j=0; j < nfiles; ++j )
323 remove( gridnam.c_str() );
335 int res = statfs( fnam.c_str(), &buf );
339 if( buf.f_type == NFS_SUPER_MAGIC ||
340 buf.f_type == SMB_SUPER_MAGIC ||
341 buf.f_type == AUTOFS_SUPER_MAGIC ||
342 buf.f_type == FUSE_SUPER_MAGIC )
364 bool lgForceNoDelimiter =
false;
369 lgForceNoDelimiter =
true;
371 bool lgAppendDelimiter =
true;
372 bool lgAppendNewline =
false;
378 str.seekg( 0, ios_base::end );
379 if( str.good() && str.tellg() > 0 )
382 str.seekg( -1, ios_base::cur );
385 lgAppendNewline = ( chr !=
'\n' );
388 str.seekg( 0, ios_base::beg );
389 while( getline( str, line ) )
391 if( line.find(
"GRID_DELIMIT" ) != string::npos )
392 lgAppendDelimiter =
false;
397 if( lgForceNoDelimiter )
398 lgAppendDelimiter =
false;
399 if( lgAppendNewline || lgAppendDelimiter )
404 if( lgAppendNewline )
406 if( lgAppendDelimiter )
409 str << setfill(
'0' ) << setw(9) << j << endl;
428 const size_t BUF_SIZE = 4096;
433 size_t nb = fread( buf,
sizeof(
char), BUF_SIZE, src );
434 fwrite( buf,
sizeof(
char), nb, dest );
450 const size_t BUF_SIZE = 32768;
455 size_t nb = fread( buf,
sizeof(
char), BUF_SIZE, src );
realnum punarg[LIMPUN][3]
FILE * open_data(const char *fname, const char *mode, access_scheme scheme)
void finalize(exit_type exit_status)
STATIC void GridGatherOutput(const string &, long, const vector< long > &)
bool lgKeepMainOutputSeparate
bool lgTimeDependentStatic
STATIC void check_grid_file(const string &, int, int)
char chHashString[INPUT_LINE_LENGTH]
#define MPI_File_close(Z)
void init(unsigned int nJobs, unsigned int nCPU)
bool lg_separate_iterations[LIMPUN]
const ios_base::openmode mode_a
const ios_base::openmode mode_r
#define MPI_File_set_view(U, V, W, X, Y, Z)
STATIC void GridGatherOutputParallel(const string &, long, const vector< long > &)
void saveFITSfile(FILE *io, int option, realnum Elo=0.f, realnum Ehi=0.f, realnum Enorm=0.f)
STATIC bool lgIsRemote(const string &)
const int NUM_OUTPUT_TYPES
void rd_block(void *ptr, size_t len, FILE *fdes)
multi_arr< realnum, 3 > Spectra
#define MPI_File_write(V, W, X, Y, Z)
int total_insanity(MPI_File, int, MPI_Status *)
#define MPI_File_get_size(Y, Z)
void append_file(FILE *dest, const char *source)
bool lgHashEndIter[LIMPUN]
#define DEBUG_ENTRY(funcname)
int fprintf(const Output &stream, const char *format,...)
string GridPointPrefix(int n)
bool lgSaveToSeparateFiles[LIMPUN]
STATIC void GridGatherOutputSequential(const string &, long)
#define MPI_Bcast(V, W, X, Y, Z)
vector< string > chFileName