diff options
Diffstat (limited to 'CarpetAttic/CarpetIOFlexIOCheckpoint')
3 files changed, 139 insertions, 188 deletions
diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc index f92cd526e..392c8619d 100644 --- a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc +++ b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc @@ -32,10 +32,6 @@ #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 "bbox.hh" #include "data.hh" #include "gdata.hh" @@ -43,13 +39,12 @@ #include "vect.hh" -//#include "StoreNamedData.h" #include "carpet.hh" #include "ioflexio.hh" extern "C" { - static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc,v 1.21 2004/01/09 15:43:46 cott Exp $"; + static const char* rcsid = "$Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/checkpointrestart.cc,v 1.22 2004/01/12 10:50:31 cott Exp $"; CCTK_FILEVERSION(Carpet_CarpetIOFlexIO_checkpointrestart_cc); } @@ -284,7 +279,7 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) CCTK_INFO ("Recovering GH extensions"); result += RecoverGHextensions (cgh, reader); - cout << refleveltimes[reflevel]<<endl; + // cout << refleveltimes[reflevel]<<endl; tt->set_time(reflevel,mglevel,(CCTK_REAL) cgh->cctk_iteration/maxreflevelfact); cout << "tt " << tt->time(0,reflevel,mglevel) << endl; @@ -459,29 +454,6 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) CCTK_WARN (1, "Unable to restore GH->cctk_time, defaulting to 0.0"); realBuffer = 0.0; } - - /* finally, we need all the times on the individual levels */ - i = reader->readAttributeInfo ("numberoftimes", datatype, dim); - if(i >=0 && datatype == FLEXIO_INT && dim == 1) { - char buffer[100]; - reader->readAttribute (i, &numberoftimes); - assert(numberoftimes==refleveltimes.size()); - for(int lcv=0;lcv<numberoftimes;lcv++) { - sprintf(buffer,"refleveltime%d",lcv); - i = reader->readAttributeInfo (buffer, datatype, dim); - if(i >=0 && datatype == FLEXIO_REAL && dim == 1) { - reader->readAttribute (i, &refleveltimes[lcv]); - } - else { - CCTK_WARN(0,"BAD BAD BAD! Can't read refleveltime!!"); - } - } - } - else - { - CCTK_WARN (0, "Unable to restore reflevel times!"); - } - } #ifdef CCTK_MPI @@ -489,8 +461,7 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) /* NOTE: We have to use MPI_COMM_WORLD here because PUGH_COMM_WORLD is not yet set up at parameter recovery time. We also assume that PUGH_MPI_INT4 is a compile-time defined datatype. */ - CACTUS_MPI_ERROR (MPI_Bcast (&numberoftimes, 1, CARPET_MPI_INT4, 0,MPI_COMM_WORLD)); - CACTUS_MPI_ERROR (MPI_Bcast (&refleveltimes[0], numberoftimes, CARPET_MPI_REAL, 0, MPI_COMM_WORLD)); + CACTUS_MPI_ERROR (MPI_Bcast (int4Buffer, 2, CARPET_MPI_INT4, 0,MPI_COMM_WORLD)); CACTUS_MPI_ERROR (MPI_Bcast (int4Buffer, 2, CARPET_MPI_INT4, 0,MPI_COMM_WORLD)); CACTUS_MPI_ERROR (MPI_Bcast (&realBuffer, 1, CARPET_MPI_REAL,0,MPI_COMM_WORLD)); @@ -498,15 +469,13 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) GH->cctk_time = refleveltimes[reflevel]; - cout << "cctk_time " << realBuffer << endl; GH->cctk_iteration = (int) int4Buffer[0]; CCTK_SetMainLoopIndex ((int) int4Buffer[1]); - cout << "refleveltimes" << refleveltimes[0] << " " << refleveltimes[1] << " " << refleveltimes[2] << endl; return (0); -} + } @@ -519,8 +488,7 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) if(parameters) { - writer->writeAttribute("global_parameters",IObase::Char, - strlen(parameters)+1,parameters); + WriteAttribute(writer,"global_parameters",parameters); free(parameters); } @@ -540,23 +508,22 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) ioUtilGH = (ioGH *) CCTK_GHExtension (cgh, "IO"); itmp = CCTK_MainLoopIndex (); - writer->writeAttribute("main loop index",FLEXIO_INT4,1,&itmp); + WriteAttribute(writer,"main loop index",itmp); itmp = cgh->cctk_iteration; - writer->writeAttribute("GH$iteration",FLEXIO_INT4, 1, &itmp); + WriteAttribute(writer,"GH$iteration",itmp); itmp = ioUtilGH->ioproc_every; - writer->writeAttribute("GH$ioproc_every",FLEXIO_INT4,1,&itmp); + WriteAttribute(writer,"GH$ioproc_every",itmp); itmp = CCTK_nProcs (cgh); - writer->writeAttribute("GH$nprocs",FLEXIO_INT4, 1, &itmp); + WriteAttribute(writer,"GH$nprocs",itmp); dtmp = cgh->cctk_time; - writer->writeAttribute("GH$time", FLEXIO_REAL, 1, &dtmp); + WriteAttribute(writer,"GH$time", dtmp); version = CCTK_FullVersion (); - writer->writeAttribute("Cactus version", FLEXIO_CHAR, - strlen (version) + 1, version); + WriteAttribute(writer,"Cactus version", version); return 0; } @@ -693,7 +660,6 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) } } - // cout << "refleveltimes: " << refleveltimes[0] << "," << refleveltimes[1] << endl; // now dump the grid varibles for all reflevels and components, sorted by groups BEGIN_REFLEVEL_LOOP(cgh) { @@ -746,10 +712,6 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) &gdata.numtimelevels,NULL); - - - - CCTK_GroupData (group, &gdata); /* dump all timelevels except the oldest (for multi-level groups) */ @@ -797,22 +759,14 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) } // write the var - //#if 1 - if (grouptype == CCTK_SCALAR) - { - // retval += WriteGS(cgh,writer,request); - retval += WriteGF(cgh,writer,amrwriter,request); - } - else - //#endif - if (grouptype == CCTK_ARRAY || grouptype == CCTK_GF) - //else if (grouptype == CCTK_GF) + + if (grouptype == CCTK_ARRAY || grouptype == CCTK_GF || grouptype == CCTK_SCALAR) { char* fullname = CCTK_FullName (request->vindex); if (verbose) CCTK_VInfo (CCTK_THORNSTRING,"%s:: reflevel: %d component: %d grouptype: %d ",fullname,reflevel,component,grouptype); free(fullname); - retval += WriteGF(cgh,writer,amrwriter,request); + retval += WriteGF(cgh,writer,amrwriter,request,1); } else { @@ -843,28 +797,28 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) 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) + if (CCTK_MyProc(cgh)==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]) { - remove (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]); } - 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); + 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; } @@ -888,10 +842,8 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) MPI_Bcast (&ndatasets, 1, MPI_INT, 0, dist::comm); assert (ndatasets>=0); - // BEGIN_REFLEVEL_LOOP(cgh) { - // BEGIN_MGLEVEL_LOOP(cgh) { + for (currdataset=1;currdataset < ndatasets;currdataset++) { - //CCTK_VInfo(CCTK_THORNSTRING,"dataset: %d",currdataset); if(myproc==0) { reader->seek(currdataset); } @@ -899,9 +851,6 @@ int CarpetIOFlexIO_Recover (cGH* cgh, const char *basefilename, int called_from) ReadGF(cgh,reader,amrreader,currdataset); } - // } END_MGLEVEL_LOOP; - //} END_REFLEVEL_LOOP; - return retval; } diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh index 124b84297..4f42bdf5b 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.12 2004/01/08 19:43:33 cott Exp $ +// $Header: /home/eschnett/C/carpet/Carpet/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexio.hh,v 1.13 2004/01/12 10:50:31 cott Exp $ #ifndef CARPETIOFLEXIO_HH #define CARPETIOFLEXIO_HH @@ -136,7 +136,7 @@ namespace CarpetIOFlexIO { static const char* GetStringParameter (const char* const parametername, const char* const fallback); - int WriteGF (const cGH* const cgh, IObase* writer, AMRwriter* amrwriter, ioRequest* request); + int WriteGF (const cGH* const cgh, IObase* writer, AMRwriter* amrwriter, ioRequest* request, const int called_from_checkpoint); int ReadGF (const cGH* const cgh, IObase* reader, AmrGridReader* amrreader, int currdataset); } // namespace CarpetIOFlexIO @@ -144,8 +144,19 @@ namespace CarpetIOFlexIO { namespace CarpetIOFlexIOUtil { IObase::DataType FlexIODataType (int cctk_type); - void DumpCommonAttributes (const cGH *cgh, IObase* writer, ioRequest* request); + void WriteAttribute (IObase* writer, const char* name, + int value); + void WriteAttribute (IObase* writer, const char* name, + const int* values, int nvalues); + void WriteAttribute (IObase* writer, const char* name, + CCTK_REAL value); + void WriteAttribute (IObase* writer, const char* name, + const CCTK_REAL* values, int nvalues); + void WriteAttribute (IObase* writer, const char* name, + const char* valuestring); + + void DumpCommonAttributes (const cGH *cgh, IObase* writer, ioRequest* request); } namespace CarpetCheckpointRestart { @@ -157,6 +168,6 @@ namespace CarpetCheckpointRestart { #endif // !defined(CARPETIOFLEXIO_HH) -/* structure holding necessary information about a recovery file */ + diff --git a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc index 17d2c699a..1342cbfa5 100644 --- a/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc +++ b/CarpetAttic/CarpetIOFlexIOCheckpoint/src/ioflexioUtil.cc @@ -30,10 +30,6 @@ #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 "bbox.hh" #include "data.hh" #include "gdata.hh" @@ -50,9 +46,9 @@ namespace CarpetIOFlexIOUtil { using namespace Carpet; using namespace CarpetIOFlexIO; -IObase::DataType FlexIODataType (int cctk_type){ - //we need this to have the FlexIO data types on hand - //for WriteGFAs + IObase::DataType FlexIODataType (int cctk_type){ + //we need this to have the FlexIO data types on hand + //for WriteGFAs int retval; @@ -90,107 +86,102 @@ IObase::DataType FlexIODataType (int cctk_type){ } -void DumpCommonAttributes (const cGH *cgh, IObase* writer, ioRequest* request) -{ - int dim, vdim, tl; - CCTK_INT attr_int,dimscalar; - CCTK_REAL *attr_real; - char coord_system_name[20]; - DECLARE_CCTK_PARAMETERS - - /* attributes describing the variable */ - char* groupname = CCTK_GroupNameFromVarI (request->vindex); - - -// - char *name = CCTK_FullName (request->vindex); - writer->writeAttribute("name",IObase::Char,strlen(name)+1,name); - free(name); + void DumpCommonAttributes (const cGH *cgh, IObase* writer, ioRequest* request) + { + int tl; + CCTK_INT attr_int,dimscalar; + DECLARE_CCTK_PARAMETERS; + + /* attributes describing the variable */ + + char *name = CCTK_FullName (request->vindex); + WriteAttribute(writer,"name",name); + free(name); + + char* groupname = CCTK_GroupNameFromVarI (request->vindex); + WriteAttribute(writer,"groupname",groupname); + free (groupname); - - //fprintf(stderr,"\nattrib %s\n",groupname); - writer->writeAttribute("groupname",IObase::String,strlen(groupname)+1,groupname); - free (groupname); - - CCTK_INT attr_int = CCTK_GroupTypeFromVarI (request->vindex); - writer->writeAttribute("grouptype",FlexIODataType(CCTK_VARIABLE_INT),1,&attr_int); - - writer->writeAttribute("reflevel",FlexIODataType(CCTK_VARIABLE_INT),1,&reflevel); - writer->writeAttribute("component",FlexIODataType(CCTK_VARIABLE_INT),1,&component); - writer->writeAttribute("mglevel",FlexIODataType(CCTK_VARIABLE_INT),1,&mglevel); - - - attr_int = CCTK_MaxTimeLevelsVI (request->vindex); - writer->writeAttribute("ntimelevels",FlexIODataType(CCTK_VARIABLE_INT),1,&attr_int); - - // lets get the correct Carpet time level (which is the (-1) * timelevel): - if (request->timelevel==0) - tl = 0; - else + WriteAttribute(writer,"grouptype",CCTK_GroupTypeFromVarI (request->vindex)); + WriteAttribute(writer,"reflevel",reflevel); + WriteAttribute(writer,"component",component); + WriteAttribute(writer,"mglevel",mglevel); + + + WriteAttribute (writer,"ntimelevels",CCTK_MaxTimeLevelsVI (request->vindex)); + + // lets get the correct Carpet time level (which is the (-1) * timelevel): + if (request->timelevel==0) + tl = 0; + else tl = - request->timelevel; - - writer->writeAttribute("timelevel",FlexIODataType(CCTK_VARIABLE_INT),1,&tl); - - /* we have to do below since cactus believes scalars have dimension 0, but - flexio likes them to be of dimension 1 - */ - - if(CCTK_GroupTypeFromVarI(request->vindex) == CCTK_SCALAR) { - dimscalar=1; - writer->writeAttribute("global_size",FlexIODataType(CCTK_VARIABLE_INT),1,&dimscalar); + WriteAttribute (writer, "timelevel", tl); + + WriteAttribute (writer, "carpet_flexio_version", 1); + WriteAttribute (writer, "cctk_dim", cgh->cctk_dim); + WriteAttribute (writer, "cctk_iteration", cgh->cctk_iteration); + WriteAttribute (writer, "cctk_gsh", cgh->cctk_gsh, dim); + WriteAttribute (writer, "cctk_lsh", cgh->cctk_lsh, dim); + WriteAttribute (writer, "cctk_lbnd", cgh->cctk_lbnd, dim); + WriteAttribute (writer, "cctk_delta_time", cgh->cctk_delta_time); + WriteAttribute (writer, "cctk_delta_space", cgh->cctk_delta_space, dim); + WriteAttribute (writer, "cctk_origin_space", cgh->cctk_origin_space, dim); + WriteAttribute (writer, "cctk_bbox", cgh->cctk_bbox, 2*dim); + WriteAttribute (writer, "cctk_levfac", cgh->cctk_levfac, dim); + WriteAttribute (writer, "cctk_levoff", cgh->cctk_levoff, dim); + WriteAttribute (writer, "cctk_levoffdenom", cgh->cctk_levoffdenom, dim); + WriteAttribute (writer, "cctk_timefac", cgh->cctk_timefac); + WriteAttribute (writer, "cctk_convlevel", cgh->cctk_convlevel); + WriteAttribute (writer, "cctk_nghostzones", cgh->cctk_nghostzones, dim); + WriteAttribute (writer, "cctk_time", cgh->cctk_time); } - else - writer->writeAttribute("global_size",FlexIODataType(CCTK_VARIABLE_INT),request->hdim,request->hsize); - - - - - - // already dumped by amrwriter (obsolete!) - writer->writeAttribute("cctk_time",FlexIODataType(CCTK_VARIABLE_REAL),1,&cgh->cctk_time); - - /* attributes describing the underlying grid - These are only stored for CCTK_GF variables if they are associated - with coordinates. */ - /* FIXME: This is hardcoded for cartesian coordinate systems. - A better solution would be to be able to query the coordinate - system which is associated with the variable. */ - vdim = CCTK_GroupDimFromVarI (request->vindex); - sprintf (coord_system_name, "cart%dd", vdim); - - /* this is already dumped by amrwriter or */ -#if 0 - /* - if (CCTK_GroupTypeFromVarI (request->vindex) == CCTK_GF && - CCTK_CoordSystemHandle (coord_system_name) >= 0) + + void WriteAttribute (IObase* writer, const char* name, int value) + { + WriteAttribute (writer, name, &value, 1); + } + + void WriteAttribute (IObase* writer, const char* name, + const int* values, int nvalues) { - attr_real = (CCTK_REAL*) malloc (3 * vdim * sizeof (CCTK_REAL)); - for (dim = 0; dim < vdim; dim++) - { - CCTK_CoordRange (cgh, &attr_real[dim], &attr_real[dim + vdim], dim + 1, - NULL, coord_system_name); - - attr_real[dim + 0*vdim] += - request->origin[dim] * cgh->cctk_delta_space[dim]; - attr_real[dim + 2*vdim] = - cgh->cctk_delta_space[dim] * request->downsample[dim]; - attr_real[dim + 1*vdim] = attr_real[dim + 0*vdim] + - ((request->extent[dim] + request->downsample[dim]-1) / - request->downsample[dim] - 1) * attr_real[dim + 2*vdim]; + assert (writer); + assert (name); + assert (values); + vector<CCTK_INT4> values1(nvalues); + for (int i=0; i<nvalues; ++i) { + values1[i] = values[i]; } - - writer->writeAttribute ("origin", FlexIODataType(CCTK_VARIABLE_REAL), vdim, attr_real); - writer->writeAttribute ("min_ext", FlexIODataType(CCTK_VARIABLE_REAL), vdim, attr_real); - writer->writeAttribute ("max_ext", FlexIODataType(CCTK_VARIABLE_REAL), vdim, attr_real+vdim); - writer->writeAttribute ("delta", FlexIODataType(CCTK_VARIABLE_REAL), vdim, attr_real+2*vdim); - free (attr_real); - } - */ -#endif - + writer->writeAttribute (name, IObase::Int32, nvalues, &values1[0]); + } + + void WriteAttribute (IObase* writer, const char* name, CCTK_REAL value) + { + WriteAttribute (writer, name, &value, 1); + } + + void WriteAttribute (IObase* writer, const char* name, + const CCTK_REAL* values, int nvalues) + { + assert (writer); + assert (name); + assert (values); + vector<CCTK_REAL8> values1(nvalues); + for (int i=0; i<nvalues; ++i) { + values1[i] = values[i]; + } + writer->writeAttribute (name, IObase::Float64, nvalues, &values1[0]); } + void WriteAttribute (IObase* writer, const char* name, + const char* valuestring) + { + assert (writer); + assert (name); + assert (valuestring); + writer->writeAttribute (name, IObase::String, strlen(valuestring)+1, valuestring); + } + } // namespace CarpetIOFlexIOUtil |