From 5777d480ac68577f78af6a4518717c49489fcb13 Mon Sep 17 00:00:00 2001 From: Thomas Radke Date: Tue, 23 Aug 2005 13:53:00 +0000 Subject: CarpetIOHDF5: bugfix for outputting the same variable into multiple files Before a variable is output it is checked whether it has been output already during the current iteration (eg. due to triggers). This check was only variable-based and therefore caused problems when the same variable was to be output to multiple files (using different alias names). Now the check has been extended to also take the output filenames into account. darcs-hash:20050823135345-776a0-1555987b4aee34bb646e67f491375dbcc44dddad.gz --- Carpet/CarpetIOHDF5/src/CarpetIOHDF5.cc | 120 ++++++++++++++------------------ Carpet/CarpetIOHDF5/src/CarpetIOHDF5.hh | 3 - 2 files changed, 53 insertions(+), 70 deletions(-) (limited to 'Carpet/CarpetIOHDF5') diff --git a/Carpet/CarpetIOHDF5/src/CarpetIOHDF5.cc b/Carpet/CarpetIOHDF5/src/CarpetIOHDF5.cc index 04761116a..4d74275a7 100644 --- a/Carpet/CarpetIOHDF5/src/CarpetIOHDF5.cc +++ b/Carpet/CarpetIOHDF5/src/CarpetIOHDF5.cc @@ -1,8 +1,6 @@ #include -#include -#include -#include +#include #include #include "cctk.h" @@ -24,8 +22,6 @@ using namespace Carpet; // Variable definitions -static vector do_truncate; // [var] -static vector > > last_output; // [ml][rl][var] // when was the last checkpoint written ? static int last_checkpoint_iteration = -1; @@ -272,7 +268,6 @@ static void* SetupGH (tFleshConfig* const fleshconfig, // allocate a new GH extension structure CarpetIOHDF5GH* myGH = new CarpetIOHDF5GH; - myGH->out_last.resize(numvars); myGH->requests.resize(numvars); myGH->cp_filename_index = 0; myGH->checkpoint_keep = abs (checkpoint_keep); @@ -285,10 +280,6 @@ static void* SetupGH (tFleshConfig* const fleshconfig, CheckSteerableParameters (cctkGH, myGH); myGH->stop_on_parse_errors = 0; - for (int i = 0; i < numvars; i++) { - myGH->out_last[i] = -1; - } - // create the output directory (if it doesn't match ".") const char *my_out_dir = *out_dir ? out_dir : io_out_dir; if (strcmp (my_out_dir, ".")) { @@ -365,18 +356,6 @@ static void* SetupGH (tFleshConfig* const fleshconfig, offsetof (CCTK_COMPLEX32, Im), H5T_NATIVE_LDOUBLE)); #endif - // Truncate all files if this is not a restart - do_truncate.resize(numvars, true); - - // No iterations have yet been output - last_output.resize(mglevels); - for (int ml=0; mlcctk_iteration; - return (retval); } @@ -606,7 +564,7 @@ static int OutputVarAs (const cGH* const cctkGH, const char* const fullname, return (0); } - /* get the default I/O request for this variable */ + // get the default I/O request for this variable ioRequest* request = IOUtil_DefaultIORequest (cctkGH, vindex, 1); // Get grid hierarchy extentsion from IOUtil @@ -617,9 +575,9 @@ static int OutputVarAs (const cGH* const cctkGH, const char* const fullname, int ioproc = 0, nioprocs = 1; const CarpetIOHDF5GH *myGH = (CarpetIOHDF5GH *) CCTK_GHExtension (cctkGH, CCTK_THORNSTRING); - string cpp_filename; - cpp_filename.append (myGH->out_dir); - cpp_filename.append (alias); + string filename; + filename.append (myGH->out_dir); + filename.append (alias); if (not (CCTK_EQUALS (out_mode, "onefile") or groupdata.disttype == CCTK_DISTRIB_CONSTANT or dist::size() == 1)) { @@ -627,34 +585,65 @@ static int OutputVarAs (const cGH* const cctkGH, const char* const fullname, ioproc = dist::rank(); nioprocs = dist::size(); snprintf (buffer, sizeof (buffer), ".file_%d", ioproc); - cpp_filename.append (buffer); + filename.append (buffer); + } + filename.append (out_extension); + const char* const c_filename = filename.c_str(); + + // check if the file has been created already + typedef std::map > > > filelist; + static filelist created_files; + filelist::iterator thisfile = created_files.find (filename); + bool is_new_file = thisfile == created_files.end(); + if (is_new_file) { + int const numvars = CCTK_NumVars (); + vector > > last_outputs; // [ml][rl][var] + last_outputs.resize (mglevels); + for (int ml = 0; ml < mglevels; ++ml) { + last_outputs[ml].resize (maxreflevels); + for (int rl = 0; rl < maxreflevels; ++rl) { + last_outputs[ml][rl].resize (numvars, cctk_iteration - 1); + } + } + thisfile = created_files.insert (thisfile, + filelist::value_type (filename, + last_outputs)); + assert (thisfile != created_files.end()); + } + + // check if this variable has been output already during this iteration + int& last_output = thisfile->second.at(mglevel).at(reflevel).at(vindex); + if (last_output == cctk_iteration) { + // Has already been output during this iteration + char* varname = CCTK_FullName(vindex); + CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, + "Skipping output for variable \"%s\", because this variable " + "has already been output during the current iteration -- " + "probably via a trigger during the analysis stage", + varname); + free (varname); + return (0); } - cpp_filename.append (out_extension); - const char* const filename = cpp_filename.c_str(); + assert (last_output < cctk_iteration); + last_output = cctk_iteration; // Open the output file if this is a designated I/O processor hid_t file = -1; if (dist::rank() == ioproc) { - // check if the file should be created anew - static set filename_set; - bool is_new = filename_set.find (cpp_filename) == filename_set.end(); - if (is_new) { - if (not IO_TruncateOutputFiles (cctkGH)) { - H5E_BEGIN_TRY { - is_new = H5Fis_hdf5 (filename) <= 0; - } H5E_END_TRY; - } - filename_set.insert (cpp_filename); + if (is_new_file and not IO_TruncateOutputFiles (cctkGH)) { + H5E_BEGIN_TRY { + is_new_file = H5Fis_hdf5 (c_filename) <= 0; + } H5E_END_TRY; } - if (is_new) { - HDF5_ERROR (file = H5Fcreate (filename, H5F_ACC_TRUNC, H5P_DEFAULT, + if (is_new_file) { + HDF5_ERROR (file = H5Fcreate (c_filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)); // write metadata information WriteMetadata (cctkGH, nioprocs, false, file); } else { - HDF5_ERROR (file = H5Fopen (filename, H5F_ACC_RDWR, H5P_DEFAULT)); + HDF5_ERROR (file = H5Fopen (c_filename, H5F_ACC_RDWR, H5P_DEFAULT)); } } @@ -678,9 +667,6 @@ static int OutputVarAs (const cGH* const cctkGH, const char* const fullname, HDF5_ERROR (H5Fclose (file)); } - // Don't truncate again - do_truncate.at(vindex) = false; - return (0); } diff --git a/Carpet/CarpetIOHDF5/src/CarpetIOHDF5.hh b/Carpet/CarpetIOHDF5/src/CarpetIOHDF5.hh index 3214048ba..b258c8bf5 100644 --- a/Carpet/CarpetIOHDF5/src/CarpetIOHDF5.hh +++ b/Carpet/CarpetIOHDF5/src/CarpetIOHDF5.hh @@ -55,9 +55,6 @@ typedef struct // default number of times to output int out_every_default; - // the last iteration output for each variable - vector out_last; - // list of variables to output char *out_vars; -- cgit v1.2.3