From 8853f70930b2bcee06762746f781e19c423d584a Mon Sep 17 00:00:00 2001 From: cvs_anon <> Date: Thu, 25 Sep 2003 06:38:00 +0000 Subject: Writing checkpoint files with refinement turned on works now. HDF5 problem. IEEE fine. darcs-hash:20030925063804-62b91-2be238f72d1e5321a7d4c1c2e9a10dac619305a4.gz --- .../src/checkpointrestart.cc | 62 ++++++++++++++++++--- .../CarpetIOFlexIOCheckpoint/src/ioflexio.cc | 64 ++++++++++++++++------ .../CarpetIOFlexIOCheckpoint/src/ioflexio.hh | 3 +- 3 files changed, 104 insertions(+), 25 deletions(-) (limited to 'CarpetAttic') diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc index 69d332648..192167b9f 100644 --- a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc +++ b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc @@ -48,7 +48,7 @@ #include "ioflexio.hh" extern "C" { - static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc,v 1.8 2003/09/24 08:35:30 cvs_anon Exp $"; + static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc,v 1.9 2003/09/25 08:38:04 cvs_anon Exp $"; CCTK_FILEVERSION(Carpet_CarpetIOFlexIO_checkpointrestart_cc); } @@ -158,6 +158,7 @@ namespace CarpetCheckpointRestart { "Time to dump datasets: ", "Total time to checkpoint:"}; const ioGH *ioUtilGH; + // const int varindex = CCTK_VarIndex("ADMBASE:gxx"); int varindex = 0; @@ -171,6 +172,17 @@ namespace CarpetCheckpointRestart { DECLARE_CCTK_PARAMETERS // CCTK_VInfo (CCTK_THORNSTRING, "boguscheck reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); + CarpetIOFlexIOGH *myGH; + myGH = (CarpetIOFlexIOGH *) CCTK_GHExtension (cgh, "CarpetIOFlexIO"); + + /* check if CarpetIOFlexIO was registered as I/O method */ + if (myGH == NULL) + { + CCTK_WARN (-1, "No CarpetIOFlexIO I/O methods registered"); + return (-1); + } + + myproc = CCTK_MyProc (cgh); ioUtilGH = (const ioGH *) CCTK_GHExtension (cgh, "IO"); @@ -193,8 +205,8 @@ namespace CarpetCheckpointRestart { assert (0); } - sprintf(cp_tempname,"%s.tmp.%s",cp_filename,extension); - sprintf(cp_filename,"%s.%s",cp_filename,extension); + sprintf(cp_tempname,"%s.tmp%s",cp_filename,extension); + sprintf(cp_filename,"%s%s",cp_filename,extension); if (CCTK_MyProc(cgh)==0) @@ -206,6 +218,20 @@ namespace CarpetCheckpointRestart { writer = new IEEEIO(cp_tempname, IObase::Create); + if (CCTK_Equals(out3D_format, "IEEE")) { + writer = new IEEEIO(cp_tempname, IObase::Create); +#ifdef HDF4 + } else if (CCTK_Equals(out3D_format, "HDF4")) { + writer = new HDFIO(cp_tempname, IObase::Create); +#endif +#ifdef HDF5 + } else if (CCTK_Equals(out3D_format, "HDF5")) { + writer = new H5IO(cp_tempname, IObase::Create); +#endif + } else { + assert (0); + } + if (! (writer->isValid()) ) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, @@ -318,9 +344,7 @@ namespace CarpetCheckpointRestart { } END_REFLEVEL_LOOP; - - - // Close the file + // Close the temporary file if (CCTK_MyProc(cgh)==0) { delete amrwriter; amrwriter = 0; @@ -328,9 +352,33 @@ namespace CarpetCheckpointRestart { writer = 0; } + if (retval == 0) + { + if (rename (cp_tempname, cp_filename)) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Could not rename temporary checkpoint file '%s' to '%s'", + cp_tempname, cp_filename); + retval = -1; + } + else + { + if (myGH->cp_filename_list[myGH->cp_filename_index]) + { + if (checkpoint_keep > 0) + { + remove (myGH->cp_filename_list[myGH->cp_filename_index]); + } + free (myGH->cp_filename_list[myGH->cp_filename_index]); + } + myGH->cp_filename_list[myGH->cp_filename_index] = strdup (cp_filename); + myGH->cp_filename_index = (myGH->cp_filename_index+1) % abs (checkpoint_keep); + } + } + return 0; - } + } } // namespace CarpetCheckpointRestart diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc index ea9a63960..5380a5fc3 100644 --- a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc +++ b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc @@ -43,8 +43,9 @@ #include "ioflexio.hh" + extern "C" { - static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc,v 1.7 2003/09/24 08:35:30 cvs_anon Exp $"; + static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc,v 1.8 2003/09/25 08:38:04 cvs_anon Exp $"; CCTK_FILEVERSION(Carpet_CarpetIOFlexIO_ioflexio_cc); } @@ -58,7 +59,7 @@ namespace CarpetIOFlexIO { // Variable definitions - int GHExtension; + // int GHExtension; int IOMethod; vector do_truncate; vector > last_output; @@ -78,10 +79,10 @@ namespace CarpetIOFlexIO { { CCTK_RegisterBanner ("AMR 3D FlexIO I/O provided by CarpetIOFlexIO"); - GHExtension = CCTK_RegisterGHExtension("CarpetIOFlexIO"); - CCTK_RegisterGHExtensionSetupGH (GHExtension, SetupGH); + // GHExtension = CCTK_RegisterGHExtension("CarpetIOFlexIO"); + CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension("CarpetIOFlexIO"),SetupGH); - IOMethod = CCTK_RegisterIOMethod ("IOFlexIO"); + IOMethod = CCTK_RegisterIOMethod ("CarpetIOFlexIO"); CCTK_RegisterIOMethodOutputGH (IOMethod, OutputGH); CCTK_RegisterIOMethodOutputVarAs (IOMethod, OutputVarAs); CCTK_RegisterIOMethodTimeToOutput (IOMethod, TimeToOutput); @@ -95,7 +96,9 @@ namespace CarpetIOFlexIO { void* SetupGH (tFleshConfig* const fc, const int convLevel, cGH* const cgh) { DECLARE_CCTK_PARAMETERS; - + CarpetIOFlexIOGH* myGH; + CCTK_INT i; + // Truncate all files if this is not a restart do_truncate.resize(CCTK_NumVars(), true); @@ -108,11 +111,33 @@ namespace CarpetIOFlexIO { // We register only once, ergo we get only one handle. We store // that statically, so there is no need to pass anything to // Cactus. + + /* allocate a new GH extension structure */ + + + CCTK_INT numvars = CCTK_NumVars (); + myGH = (CarpetIOFlexIOGH*) malloc (sizeof (CarpetIOFlexIOGH)); + myGH->out_last = (int *) malloc (numvars * sizeof (int)); + myGH->requests = (ioRequest **) calloc (numvars, sizeof (ioRequest *)); + myGH->cp_filename_list = (char **) calloc (abs (checkpoint_keep), sizeof (char *)); + myGH->cp_filename_index = 0; + myGH->out_vars = strdup (""); + myGH->out_every_default = out_every - 1; + + for (i = 0; i < numvars; i++) + { + myGH->out_last [i] = -1; + } + + myGH->open_output_files = NULL; + + + return (myGH); + return 0; } - int OutputGH (const cGH* const cgh) { for (int vindex=0; vindex* const data = (*ff) (tl, reflevel, component, mglevel); + // get some more group information + cGroupDynamicData gdyndata; + int ierr = CCTK_GroupDynamicData(cgh,group,&gdyndata); + assert(ierr==0); + // Make temporary copy on processor 0 bbox ext = data->extent(); vect lo = ext.lower(); @@ -237,14 +267,14 @@ namespace CarpetIOFlexIO { // Ignore ghost zones if desired for (int d=0; dcctk_bbox[2*d ] && !out3D_output_outer_boundary) ? -1 : out3D_max_num_lower_ghosts; - const int max_upper_ghosts = (cgh->cctk_bbox[2*d+1] && !out3D_output_outer_boundary) ? -1 : out3D_max_num_upper_ghosts; + const int max_lower_ghosts = (gdyndata.bbox[2*d ] && !out3D_output_outer_boundary) ? -1 : out3D_max_num_lower_ghosts; + const int max_upper_ghosts = (gdyndata.bbox[2*d+1] && !out3D_output_outer_boundary) ? -1 : out3D_max_num_upper_ghosts; - const int num_lower_ghosts = max_lower_ghosts == -1 ? cgh->cctk_nghostzones[d] : min(out3D_max_num_lower_ghosts, cgh->cctk_nghostzones[d]); - const int num_upper_ghosts = max_upper_ghosts == -1 ? cgh->cctk_nghostzones[d] : min(out3D_max_num_upper_ghosts, cgh->cctk_nghostzones[d]); + const int num_lower_ghosts = max_lower_ghosts == -1 ? gdyndata.nghostzones[d] : min(out3D_max_num_lower_ghosts, gdyndata.nghostzones[d]); + const int num_upper_ghosts = max_upper_ghosts == -1 ? gdyndata.nghostzones[d] : min(out3D_max_num_upper_ghosts, gdyndata.nghostzones[d]); - lo[d] += (cgh->cctk_nghostzones[d] - num_lower_ghosts) * str[d]; - hi[d] -= (cgh->cctk_nghostzones[d] - num_upper_ghosts) * str[d]; + lo[d] += (gdyndata.nghostzones[d] - num_lower_ghosts) * str[d]; + hi[d] -= (gdyndata.nghostzones[d] - num_upper_ghosts) * str[d]; } ext = bbox(lo,hi,str); @@ -364,7 +394,7 @@ namespace CarpetIOFlexIO { } END_COMPONENT_LOOP; - } + } return 0; } @@ -854,6 +884,6 @@ namespace CarpetIOFlexIO { flags[index] = true; } - + } // namespace CarpetIOFlexIO diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh index e92b7653a..5719ef0f6 100644 --- a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh +++ b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh @@ -1,4 +1,4 @@ -// $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh,v 1.4 2003/09/23 12:34:43 cvs_anon Exp $ +// $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh,v 1.5 2003/09/25 08:38:04 cvs_anon Exp $ #ifndef CARPETIOFLEXIO_HH #define CARPETIOFLEXIO_HH @@ -13,6 +13,7 @@ #include "CactusBase/IOUtil/src/ioutil_Utils.h" #include "ioflexio.h" +#include "ioflexioGH.h" /* define the IOFlexIO datatypes according to CCTK_??? datatypes */ #define FLEXIO_CHAR IObase::Char -- cgit v1.2.3