From 00509e12e14450bb26de6fc29b3309a75677891f Mon Sep 17 00:00:00 2001 From: cvs_anon <> Date: Tue, 23 Sep 2003 10:34:00 +0000 Subject: Another (updated) development version. Still not working. darcs-hash:20030923103443-62b91-cd8947bfd13f75214085c9e0d78df729e3f90c72.gz --- .../src/checkpointrestart.cc | 150 ++++++++++------ .../CarpetIOFlexIOCheckpoint/src/ioflexio.cc | 194 +++++++++++++-------- .../CarpetIOFlexIOCheckpoint/src/ioflexio.hh | 15 +- .../CarpetIOFlexIOCheckpoint/src/make.code.defn | 4 +- 4 files changed, 238 insertions(+), 125 deletions(-) (limited to 'CarpetAttic') diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc index a909d7f78..c3c275477 100644 --- a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc +++ b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc @@ -32,9 +32,9 @@ #undef BYTE #undef CHAR -#include "CactusBase/IOUtil/src/ioGH.h" -#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h" -#include "CactusBase/IOUtil/src/ioutil_Utils.h" +//#include "CactusBase/IOUtil/src/ioGH.h" +//#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h" +//#include "CactusBase/IOUtil/src/ioutil_Utils.h" #include "bbox.hh" #include "data.hh" @@ -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.6 2003/09/17 13:47:00 cvs_anon Exp $"; + static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc,v 1.7 2003/09/23 12:34:43 cvs_anon Exp $"; CCTK_FILEVERSION(Carpet_CarpetIOFlexIO_checkpointrestart_cc); } @@ -60,13 +60,18 @@ namespace CarpetCheckpointRestart { using namespace std; using namespace Carpet; using namespace CarpetIOFlexIO; + using namespace CarpetIOFlexIOUtil; static int Checkpoint (const cGH* const cgh, int called_from); + + + void CarpetIOFlexIO_EvolutionCheckpoint( const cGH* const cgh){ DECLARE_CCTK_PARAMETERS + CCTK_VInfo (CCTK_THORNSTRING, "CHECKPOINT? cgh->cctk_iteration %d, cgh->cctk_iteration mod checkpoint_every = %d, checkpoint = %d, checkpoint_next = %d", cgh->cctk_iteration, cgh->cctk_iteration % checkpoint_every,checkpoint,checkpoint_next); if (checkpoint && ((checkpoint_every > 0 && cgh->cctk_iteration % checkpoint_every == 0) || checkpoint_next)) @@ -78,7 +83,7 @@ namespace CarpetCheckpointRestart { "iteration %d", cgh->cctk_iteration); CCTK_INFO ("---------------------------------------------------------"); } -CCTK_VInfo (CCTK_THORNSTRING, "bogusbefore reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); + Checkpoint (cgh, CP_EVOLUTION_DATA); if (checkpoint_next) @@ -164,7 +169,7 @@ CCTK_VInfo (CCTK_THORNSTRING, "bogusbefore reflevel,component,mglevel %d,%d,%d", ioRequest *request; DECLARE_CCTK_PARAMETERS - CCTK_VInfo (CCTK_THORNSTRING, "boguscheck reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); + // CCTK_VInfo (CCTK_THORNSTRING, "boguscheck reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); myproc = CCTK_MyProc (cgh); @@ -210,7 +215,6 @@ CCTK_VInfo (CCTK_THORNSTRING, "bogusbefore reflevel,component,mglevel %d,%d,%d", } amrwriter = new AMRwriter(*writer); - // dump parameters DumpParams (cgh, 1, writer); // dump GH extentions @@ -219,66 +223,106 @@ CCTK_VInfo (CCTK_THORNSTRING, "bogusbefore reflevel,component,mglevel %d,%d,%d", } - // now dump the grid varibles, sorted by groups - - if (CCTK_Equals ("verbose", "full")) - { - CCTK_INFO ("Dumping Grid Variables ..."); - } - for (group = CCTK_NumGroups () - 1; group >= 0; group--) - { - /* only dump groups which have storage assigned */ - if (CCTK_QueryGroupStorageI (cgh, group) <= 0) - { - continue; - } + // now dump the grid varibles for all reflevels and components, sorted by groups + // CCTK_VInfo (CCTK_THORNSTRING, "maxreflevelfact,reflevelfact,it %d,%d,%d",maxreflevelfact,reflevelfact,cgh->cctk_iteration); + BEGIN_REFLEVEL_LOOP(cgh) { - /* dump all timelevels except the oldest (for multi-level groups) */ - CCTK_GroupData (group, &gdata); - if (gdata.numtimelevels > 1) - { - gdata.numtimelevels--; - } + const int do_every = maxreflevelfact/reflevelfact; + if (cgh->cctk_iteration % do_every == 0) { + + BEGIN_MGLEVEL_LOOP(cgh) { + const int do_every = mglevelfact * maxreflevelfact/reflevelfact; + CCTK_VInfo (CCTK_THORNSTRING, "do_every %d",do_every); + + if (cgh->cctk_iteration % do_every == 0) { + + if (CCTK_Equals ("verbose", "full")) + { + CCTK_INFO ("Dumping Grid Variables ..."); + } + for (group = CCTK_NumGroups () - 1; group >= 0; group--) + { + /* only dump groups which have storage assigned */ + if (CCTK_QueryGroupStorageI (cgh, group) <= 0) + { + continue; + } + + /* get the number of allocated timelevels */ + CCTK_GroupData (gindex, &gdata); + gdata.numtimelevels = 0; + gdata.numtimelevels = CCTK_GroupStorageIncrease (cgh, 1, &group, + &gdata.numtimelevels,NULL); + + /* dump all timelevels except the oldest (for multi-level groups) */ + CCTK_GroupData (group, &gdata); + if (gdata.numtimelevels > 1) + { + gdata.numtimelevels--; + } + + int first_vindex = CCTK_FirstVarIndexI (group); - int first_vindex = CCTK_FirstVarIndexI (group); + const int grouptype = CCTK_GroupTypeI(group); - /* get the default I/O request for this group */ - request = IOUtil_DefaultIORequest (cgh, first_vindex, 1); + /* get the default I/O request for this group */ + request = IOUtil_DefaultIORequest (cgh, first_vindex, 1); - /* disable checking for old data objects, disable datatype conversion - and downsampling */ - request->check_exist = 0; - request->hdatatype = gdata.vartype; - for (request->hdim = 0; request->hdim < request->vdim; request->hdim++) - { - request->downsample[request->hdim] = 1; - } + /* disable checking for old data objects, disable datatype conversion + and downsampling */ + request->check_exist = 0; + request->hdatatype = gdata.vartype; + for (request->hdim = 0; request->hdim < request->vdim; request->hdim++) + { + request->downsample[request->hdim] = 1; + } - /* loop over all variables in this group */ - for (request->vindex = first_vindex; - request->vindex < first_vindex + gdata.numvars; - request->vindex++) - { - /* loop over all timelevels of this variable */ - for (request->timelevel = 0; - request->timelevel < gdata.numtimelevels; - request->timelevel++) + /* loop over all variables in this group */ + for (request->vindex = first_vindex; + request->vindex < first_vindex + gdata.numvars; + request->vindex++) { - - if (verbose) + /* loop over all timelevels of this variable */ + for (request->timelevel = 0; + request->timelevel < gdata.numtimelevels; + request->timelevel++) + { + + if (verbose) { fullname = CCTK_FullName (request->vindex); CCTK_VInfo (CCTK_THORNSTRING, " %s (timelevel %d)", fullname, request->timelevel); free (fullname); } - // write the var + // write the var + + if (grouptype == CCTK_SCALAR) + { + retval += WriteGS(cgh,writer,request); + } + // else if (grouptype == CCTK_ARRAY || grouptype == CCTK_GF) + else if (grouptype == CCTK_GF) + { + retval += WriteGF(cgh,writer,amrwriter,request); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid group type %d for variable '%s'", grouptype, fullname); + retval = -1; + } + + } + } /* end of loop over all variables */ + + } /* end of loop over all groups */ + } + } END_MGLEVEL_LOOP; + } + } END_REFLEVEL_LOOP; - retval += WriteVarAs(cgh,writer,amrwriter,request->vindex); - } - } /* end of loop over all variables */ - } /* end of loop over all groups */ // Close the file diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc index 32a147dac..518b75349 100644 --- a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc +++ b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc @@ -44,7 +44,7 @@ #include "ioflexio.hh" extern "C" { - static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc,v 1.5 2003/09/17 13:47:00 cvs_anon Exp $"; + static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.cc,v 1.6 2003/09/23 12:34:43 cvs_anon Exp $"; CCTK_FILEVERSION(Carpet_CarpetIOFlexIO_ioflexio_cc); } @@ -54,7 +54,7 @@ namespace CarpetIOFlexIO { using namespace std; using namespace Carpet; - + using namespace CarpetIOFlexIOUtil; // Variable definitions @@ -92,8 +92,7 @@ namespace CarpetIOFlexIO { - void* SetupGH (tFleshConfig* const fc, - const int convLevel, cGH* const cgh) + void* SetupGH (tFleshConfig* const fc, const int convLevel, cGH* const cgh) { DECLARE_CCTK_PARAMETERS; @@ -124,60 +123,16 @@ namespace CarpetIOFlexIO { } -static IObase::DataType FlexIODataType (int cctk_type){ - //we need this to have the FlexIO data types on hand - //for WriteVarAs - - int retval; - - switch (cctk_type) - { - case CCTK_VARIABLE_CHAR: retval = FLEXIO_CHAR; break; - case CCTK_VARIABLE_INT: retval = FLEXIO_INT; break; - case CCTK_VARIABLE_REAL: retval = FLEXIO_REAL; break; -#ifdef CCTK_INT2 - case CCTK_VARIABLE_INT2: retval = FLEXIO_INT2; break; -#endif -#ifdef CCTK_INT4 - case CCTK_VARIABLE_INT4: retval = FLEXIO_INT4; break; -#endif -#ifdef CCTK_INT8 - case CCTK_VARIABLE_INT8: retval = FLEXIO_INT8; break; -#endif -#ifdef CCTK_REAL4 - case CCTK_VARIABLE_REAL4: retval = FLEXIO_REAL4; break; -#endif -#ifdef CCTK_REAL8 - case CCTK_VARIABLE_REAL8: retval = FLEXIO_REAL8; break; -#endif -#ifdef CCTK_REAL16 - case CCTK_VARIABLE_REAL16: retval = FLEXIO_REAL16; break; -#endif - - default: CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, - "Unsupported CCTK variable datatype %d", cctk_type); - retval = -1; - break; - } - - return (IObase::DataType)retval; - } - - - - - - - - - int WriteVarAs (const cGH* const cgh, IObase* writer, AMRwriter* amrwriter, int varindex) + int WriteGF (const cGH* const cgh, IObase* writer, AMRwriter* amrwriter, ioRequest* request) { DECLARE_CCTK_PARAMETERS; - CCTK_VInfo (CCTK_THORNSTRING, "bogusnew reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); + /* I have got no idea why this stuff below is needed... ask Erik Schnetter */ + + const int varindex = request->vindex; const int group = CCTK_GroupIndexFromVarI (varindex); const int n0 = CCTK_FirstVarIndexI(group); @@ -185,9 +140,9 @@ static IObase::DataType FlexIODataType (int cctk_type){ const int var = varindex - n0; assert (var>=0 && var0)); + + assert (! ( (grouptype != CCTK_GF && grouptype != CCTK_ARRAY) && reflevel>0)); if (CCTK_MyProc(cgh)==0) { @@ -227,7 +182,7 @@ static IObase::DataType FlexIODataType (int cctk_type){ (gpdim, origin, delta, timestep, maxreflevels); // Set refinement information - int interlevel_timerefine1,-1,0ment; + int interlevel_timerefinement; int interlevel_spacerefinement[dim]; int initial_gridplacementrefinement[dim]; interlevel_timerefinement = hh->reffact; @@ -254,13 +209,20 @@ static IObase::DataType FlexIODataType (int cctk_type){ const ggf* ff = 0; + if (grouptype == CCTK_ARRAY) + CCTK_VInfo (CCTK_THORNSTRING, "ARRAY reflevel: %d component: %d grouptype: %d ",reflevel,component,grouptype); + else + CCTK_VInfo (CCTK_THORNSTRING, "GF reflevel: %d component: %d grouptype: %d",reflevel,component,grouptype); + + + + + assert (var < (int)arrdata[group].data.size()); ff = (ggf*)arrdata[group].data[var]; - CCTK_VInfo (CCTK_THORNSTRING, "bogus reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); - const gdata* const data - = (*ff) (tl, reflevel, component, mglevel); - CCTK_VInfo (CCTK_THORNSTRING, "bogus2"); + // CCTK_VInfo (CCTK_THORNSTRING, "bogus reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); + const gdata* const data = (*ff) (tl, reflevel, component, mglevel); // Make temporary copy on processor 0 bbox ext = data->extent(); @@ -268,8 +230,6 @@ static IObase::DataType FlexIODataType (int cctk_type){ vect hi = ext.upper(); vect str = ext.stride(); - - // Ignore ghost zones if desired for (int d=0; dcctk_bbox[2*d ] && !out3D_output_outer_boundary) ? -1 : out3D_max_num_lower_ghosts; @@ -298,9 +258,15 @@ static IObase::DataType FlexIODataType (int cctk_type){ dims[d] = (ext.shape() / ext.stride())[d]; } amrwriter->write (origin, dims, (void*)tmp->storage()); - char *name = CCTK_FullName (varindex); - writer->writeAttribute("name",IObase::Char,strlen(name)+1,name); - free(name); + + + // dump attributes + DumpCommonAttributes(cgh,writer,request); + + + // char *name = CCTK_FullName (varindex); + // writer->writeAttribute("name",IObase::Char,strlen(name)+1,name); + //free(name); } // Delete temporary copy @@ -311,11 +277,99 @@ static IObase::DataType FlexIODataType (int cctk_type){ return 0; } - + int WriteGS (const cGH* const cgh, IObase* writer, ioRequest* request) + { + + // writes out a grid scalar + + DECLARE_CCTK_PARAMETERS; + + const int timelevel = request->timelevel; + const int varindex = request->vindex; + + const int group = CCTK_GroupIndexFromVarI (varindex); + const int n0 = CCTK_FirstVarIndexI(group); + assert (n0>=0 && n0=0 && var0)); + + + int myproc = CCTK_MyProc (cgh); + int nprocs = CCTK_nProcs (cgh); + char* fullname = CCTK_FullName (varindex); + + int datatype = CCTK_VarTypeI(varindex); + int datatypesize = CCTK_VarTypeSize(datatype); + + char* buffer = (char*) calloc (nprocs, datatypesize); + memcpy (buffer + myproc*datatypesize, + CCTK_VarDataPtrI (cgh,timelevel,varindex), + datatypesize); + + if (nprocs > 1) { + int i = CCTK_ReductionHandle ("sum"); + if (i >= 0) + { + i = CCTK_ReduceArray (cgh, -1, i, nprocs, datatype, buffer, 1, 1, datatype, nprocs, buffer); + } + if (i < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "WriteGS: Cannot check whether values on differentprocessors are the same for grid scalar '%s'", fullname); + // copy this processor's value to the start of buffer + memcpy (buffer, buffer + myproc*datatypesize, datatypesize); + } + else + { + int retval = 0; + for (i = 1; i < nprocs; i++) + { + retval |= memcmp (buffer, buffer + i*datatypesize, datatypesize); + } + if (retval) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "WriteGS: value of grid scalar variable '%s' (timelevel %d)" + " differs between processors, only value from processor 0 " + "will be written", fullname, timelevel); + } + } + } + + if (myproc==0) + { + int dim = 1; + + // Traverse all components on this refinement and multigrid level + BEGIN_COMPONENT_LOOP(cgh, grouptype) { + + // actually, looping makes no sense here, since a scalar must be the + // same on all components. in fact, the loop is not being + // executed for scalars; see macro definition. + + + // CCTK_VInfo (CCTK_THORNSTRING, "SCALAR reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); + writer->write(FlexIODataType(CCTK_VarTypeI(varindex)),1,&dim,buffer); + /* scalars have size 0 */ + request->hsize[0] = 0; + DumpCommonAttributes (cgh,writer,request); + + } END_COMPONENT_LOOP; + + } + + return 0; + } + + + int OutputVarAs (const cGH* const cgh, const char* const varname, const char* const alias) { DECLARE_CCTK_PARAMETERS; - CCTK_VInfo (CCTK_THORNSTRING, "bogusnewout reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); + // CCTK_VInfo (CCTK_THORNSTRING, "bogusnewout reflevel,component,mglevel %d,%d,%d",reflevel,component,mglevel); const int n = CCTK_VarIndex(varname); assert (n>=0 && n0) return 0; - + + int first_vindex = CCTK_FirstVarIndexI (group); + /* get the default I/O request for this group */ + ioRequest* request = IOUtil_DefaultIORequest (cgh, first_vindex, 1); + // Get grid hierarchy extentsion from IOUtil const ioGH * const iogh = (const ioGH *)CCTK_GHExtension (cgh, "IO"); assert (iogh); @@ -419,7 +477,7 @@ static IObase::DataType FlexIODataType (int cctk_type){ amrwriter = new AMRwriter(*writer); } - WriteVarAs(cgh,writer,amrwriter,n); + WriteGF(cgh,writer,amrwriter,request); // Close the file if (CCTK_MyProc(cgh)==0) { diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh index 13350bf9f..e92b7653a 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.3 2003/09/17 13:47:00 cvs_anon Exp $ +// $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh,v 1.4 2003/09/23 12:34:43 cvs_anon Exp $ #ifndef CARPETIOFLEXIO_HH #define CARPETIOFLEXIO_HH @@ -8,6 +8,10 @@ #include "cctk.h" #include "cctk_Arguments.h" +#include "CactusBase/IOUtil/src/ioGH.h" +#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h" +#include "CactusBase/IOUtil/src/ioutil_Utils.h" + #include "ioflexio.h" /* define the IOFlexIO datatypes according to CCTK_??? datatypes */ @@ -73,9 +77,16 @@ namespace CarpetIOFlexIO { static const char* GetStringParameter (const char* const parametername, const char* const fallback); - int WriteVarAs (const cGH* const cgh, IObase* writer,AMRwriter* amrwriter, int varindex); + int WriteGF (const cGH* const cgh, IObase* writer,AMRwriter* amrwriter, ioRequest* request); + int WriteGS (const cGH* const cgh, IObase* writer, ioRequest* request); } // namespace CarpetIOFlexIO +namespace CarpetIOFlexIOUtil { + + IObase::DataType FlexIODataType (int cctk_type); + void DumpCommonAttributes (const cGH *cgh, IObase* writer, ioRequest* request); + +} #endif // !defined(CARPETIOFLEXIO_HH) diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/make.code.defn b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/make.code.defn index b15bcae91..0e1021e99 100644 --- a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/make.code.defn +++ b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/make.code.defn @@ -1,8 +1,8 @@ # Main make.code.defn file for thorn CarpetIOFlexIO -# $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/make.code.defn,v 1.1 2003/05/16 14:02:18 hawke Exp $ +# $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/make.code.defn,v 1.2 2003/09/23 12:34:43 cvs_anon Exp $ # Source files in this directory -SRCS = ioflexio.cc checkpointrestart.cc +SRCS = ioflexio.cc checkpointrestart.cc ioflexioUtil.cc # Subdirectories containing source files SUBDIRS = -- cgit v1.2.3