diff options
author | tradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a> | 2002-04-17 18:01:50 +0000 |
---|---|---|
committer | tradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a> | 2002-04-17 18:01:50 +0000 |
commit | e7b5e1e51708eca4912aed95860f06a8b5a522f1 (patch) | |
tree | f6062873e2e0cf56b3e64fe6889fb7c9338b3fad | |
parent | f7f7a801866271138a1888a493ae0c50ca372b52 (diff) |
Tidying up the code to make it consistent with the structure in IOHDF5.
git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOFlexIO/trunk@230 ebee0441-1374-4afa-a3b5-247f3ba15b9a
-rw-r--r-- | schedule.ccl | 15 | ||||
-rw-r--r-- | src/ChooseOutput.c | 194 | ||||
-rw-r--r-- | src/DumpGH.c | 413 | ||||
-rw-r--r-- | src/DumpVar.c | 1067 | ||||
-rw-r--r-- | src/GHExtension.c | 328 | ||||
-rw-r--r-- | src/Output.c | 366 | ||||
-rw-r--r-- | src/Output3D.c | 334 | ||||
-rw-r--r-- | src/RecoverGH.c | 269 | ||||
-rw-r--r-- | src/RestoreFile.c | 28 | ||||
-rw-r--r-- | src/Startup.c | 356 | ||||
-rw-r--r-- | src/Write.c | 350 | ||||
-rw-r--r-- | src/Write2D.c | 20 | ||||
-rw-r--r-- | src/Write3D.c | 410 | ||||
-rw-r--r-- | src/ioFlexGH.h | 98 | ||||
-rw-r--r-- | src/make.code.defn | 8 | ||||
-rw-r--r-- | src/make.configuration.defn | 8 |
16 files changed, 2064 insertions, 2200 deletions
diff --git a/schedule.ccl b/schedule.ccl index 3d432c5..ae3c1e7 100644 --- a/schedule.ccl +++ b/schedule.ccl @@ -1,14 +1,15 @@ # Schedule definitions for thorn IOFlexIO +# $Header$ ######################################################################## -### register IOFlexIO routines +### register IOFlexIO startup/termination routines ######################################################################## schedule IOFlexIO_Startup at STARTUP after ( IOUtil_Startup Driver_Startup ) { LANG:C } "Startup routine" -schedule IOFlexIO_TerminateGH at CCTK_TERMINATE after IOFlexIO_TerminationDumpGH +schedule IOFlexIO_TerminateGH at CCTK_TERMINATE after IOFlexIO_TerminationCheckpoint { LANG:C } "Closing open IEEEIO files" @@ -24,19 +25,19 @@ schedule IOFlexIO_Choose2D at BASEGRID after SpatialCoordinates ######################################################################## -### register checkpointing routines +### register checkpoint/recovery routines ######################################################################## -schedule IOFlexIO_InitialDataDumpGH at CCTK_CPINITIAL +schedule IOFlexIO_InitialDataCheckpoint at CCTK_CPINITIAL { LANG:C } "Initial data checkpoint routine" -schedule IOFlexIO_ConditionallyDumpGH at CCTK_CHECKPOINT +schedule IOFlexIO_EvolutionCheckpoint at CCTK_CHECKPOINT { LANG:C -} "Regular checkpoint routine" +} "Evolution data checkpoint routine" -schedule IOFlexIO_TerminationDumpGH at CCTK_TERMINATE BEFORE Driver_Terminate +schedule IOFlexIO_TerminationCheckpoint at CCTK_TERMINATE BEFORE Driver_Terminate { LANG:C } "Termination checkpoint routine" diff --git a/src/ChooseOutput.c b/src/ChooseOutput.c index 3f9b2fb..896af8c 100644 --- a/src/ChooseOutput.c +++ b/src/ChooseOutput.c @@ -1,149 +1,101 @@ -/*@@ - @file ChooseOutput.c - @author Gabrielle Allen - @date July 6 2000 - @desc - Choose what data to write for different IO methods in IOHDF5 - @enddesc - - @history - @hauthor - @hdesc - @version $Header$ + /*@@ + @file ChooseOutput.c + @author Gabrielle Allen + @date July 6 2000 + @desc + Choose what data to write for different I/O methods in IOFlexIO + @enddesc + @version $Id$ @@*/ #include <stdlib.h> #include "cctk.h" -#include "cctk_Arguments.h" #include "cctk_Parameters.h" #include "CactusBase/IOUtil/src/ioutil_Utils.h" #include "ioFlexGH.h" +/* the rcs ID and its dummy function to use it */ static const char *rcsid = "$Header$"; CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_ChooseOutput_c) -/* prototypes of routines defined in this source file */ -void IOFlexIO_Choose2D(CCTK_ARGUMENTS); - - -/*@@ - @routine IOFlexIO_Choose2D - @author Gabrielle Allen - @date July 6 2000 - @desc - Use parameters to choose the 2D planes through the output data. - @enddesc - - @history - @hauthor - @hdesc - @version $Header$ -@@*/ - -void IOFlexIO_Choose2D(CCTK_ARGUMENTS) -{ - DECLARE_CCTK_PARAMETERS - - int i; - int maxdim; - flexioGH *myGH; /* FlexIO extension handle */ - int *origin_index; /* Specify output planes by indices */ - CCTK_REAL *origin_phys; /* Specify output planes by coordinates */ - - myGH = (flexioGH *) cctkGH->extensions - [CCTK_GHExtensionHandle ("IOFlexIO")]; - - /* Set up lines to be output */ - maxdim = CCTK_MaxDim(); - origin_phys = (CCTK_REAL *)calloc(maxdim,sizeof(CCTK_REAL )); - origin_index = (int *)calloc(maxdim,sizeof(int )); - - /* Set parameters using +/******************************************************************** + ******************** Macro Definitions ************************ + ********************************************************************/ +/* macro to choose origin according actual parameter settings: 1. Indices from IOFlexIO 2. Indices from IOUtil 3. Coords from IOFlexIO 4. Coords from IOUtil - */ - - if (CCTK_ParameterQueryTimesSet("out2D_yzplane_xi","IOFlexIO")>0) - { - origin_index[0] = out2D_yzplane_xi; - } - else if (CCTK_ParameterQueryTimesSet("out_yzplane_xi","IOUtil")>0) - { - origin_index[0] = out_yzplane_xi; - } - else - { - origin_index[0] = -1; - if (CCTK_ParameterQueryTimesSet("out2D_yzplane_x","IOFlexIO")>0) - { - origin_phys[0] = out2D_yzplane_x; - } - else - { - origin_phys[0] = out_yzplane_x; - } - } + */ +#define GET_SLICE(my_param, IOUtil_param, origin_index, origin_phys) \ + { \ + origin_index = -1; \ + if (CCTK_ParameterQueryTimesSet (#my_param "i", "IOFlexIO") > 0) \ + { \ + origin_index = my_param##i; \ + } \ + else if (CCTK_ParameterQueryTimesSet (#IOUtil_param "i", "IOUtil")>0)\ + { \ + origin_index = IOUtil_param##i; \ + } \ + else if (CCTK_ParameterQueryTimesSet (#my_param, "IOFlexIO") > 0) \ + { \ + origin_phys = my_param; \ + } \ + else \ + { \ + origin_phys = IOUtil_param; \ + } \ + } + + +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ +void IOFlexIO_Choose2D (cGH *GH); + + + /*@@ + @routine IOFlexIO_Choose2D + @author Gabrielle Allen + @date July 6 2000 + @desc + Use parameters to choose the 2D planes through the output data. + @enddesc +@@*/ +void IOFlexIO_Choose2D (cGH *GH) +{ + int i; + flexioGH *myGH; + int origin_index[3]; + CCTK_REAL origin_phys[3]; + DECLARE_CCTK_PARAMETERS - if (CCTK_ParameterQueryTimesSet("out2D_xzplane_yi","IOFlexIO")>0) - { - origin_index[1] = out2D_xzplane_yi; - } - else if (CCTK_ParameterQueryTimesSet("out_xzplane_yi","IOUtil")>0) - { - origin_index[1] = out_xzplane_yi; - } - else - { - origin_index[1] = -1; - if (CCTK_ParameterQueryTimesSet("out2D_xzplane_y","IOFlexIO")>0) - { - origin_phys[1] = out2D_xzplane_y; - } - else - { - origin_phys[1] = out_xzplane_y; - } - } - if (CCTK_ParameterQueryTimesSet("out2D_xyplane_zi","IOFlexIO")>0) - { - origin_index[2] = out2D_xyplane_zi; - } - else if (CCTK_ParameterQueryTimesSet("out_xyplane_zi","IOUtil")>0) + /* get the handle for IOFlexIO extensions */ + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); + if (myGH == NULL) { - origin_index[2] = out_xyplane_zi; + CCTK_WARN (1, "IOFlexIO_Choose2D: IOFlexIO GH extension not found"); } else { - origin_index[2] = -1; - if (CCTK_ParameterQueryTimesSet("out2D_xyplane_z","IOFlexIO")>0) - { - origin_phys[2] = out2D_xyplane_z; - } - else - { - origin_phys[2] = out_xyplane_z; - } - } + GET_SLICE (out2D_xyplane_z, out_xyplane_z, origin_index[0], origin_phys[0]); + GET_SLICE (out2D_xzplane_y, out_xzplane_y, origin_index[1], origin_phys[1]); + GET_SLICE (out2D_yzplane_x, out_yzplane_x, origin_index[2], origin_phys[2]); - if (myGH) - { - for (i=1;i<=CCTK_MaxDim();i++) + for (i = 1; i <= CCTK_MaxDim (); i++) { - IOUtil_2DPlanes (cctkGH, i, origin_index, - origin_phys, myGH->sp2xyz[i-1]); + if (i > 1 && i <= 3) + { + IOUtil_2DPlanes (GH, i, origin_index, origin_phys, myGH->sp2xyz[i-1]); + } + else + { + memset (myGH->sp2xyz[i-1], 0, i * sizeof (myGH->sp2xyz[i-1][0])); + } } } - else - { - CCTK_WARN(1,"IOFlexIO_Choose2D: FlexIO GH extension not found"); - } - - return; } - - diff --git a/src/DumpGH.c b/src/DumpGH.c index bfd8b77..e411532 100644 --- a/src/DumpGH.c +++ b/src/DumpGH.c @@ -3,11 +3,12 @@ @date Wed Jun 10 14:13:35 1998 @author Paul Walker @desc - DumpGH dumps an entire grid hierarchy (except for 1D arrays) to a - checkpoint file. This file also contains the different wrappers for - IOFlexIODumpGH: in case of initial data, termination or regular checkpointing + Checkpoint routines scheduled at CCTK_CPINITIAL, CCTK_CHECKPOINT, + and CCTK_TERMINATE. + They check the IO checkpointing parameters and - if it's time + to do so - call the routine which finally creates a checkpoint. @enddesc - @version $Id$ + @version $Id$ @@*/ @@ -30,30 +31,65 @@ static const char *rcsid = "$Id$"; CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_DumpGH_c) -/* prototypes of routines defined in this source file */ -void IOFlexIO_ConditionallyDumpGH (cGH *GH); -void IOFlexIO_TerminationDumpGH (cGH *GH); -void IOFlexIO_InitialDataDumpGH (cGH *GH); -void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile iof); -void IOFlexIOi_DumpGHExtensions (const cGH *GH, IOFile iof); +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ +void IOFlexIO_InitialDataCheckpoint (cGH *GH); +void IOFlexIO_EvolutionCheckpoint (cGH *GH); +void IOFlexIO_TerminationCheckpoint (cGH *GH); +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static int Checkpoint (const cGH *GH, int called_from); /*@@ - @routine IOFlexIO_ConditionallyDumpGH - @date Fri Aug 21 14:38:25 1998 - @author Gabrielle Allen + @routine IOFlexIO_InitialDataCheckpoint + @date Fri Aug 21 14:46:28 1998 + @author Gerd Lanfermann @desc - registered as CCTK_CHECKPOINT, checks if it's time for - checkpointing, sets the checkpoint type and calls DumpGH + This routine is registered at CCTK_CPINITIAL. + It checks if initial data should be checkpointed. @enddesc - @calls IOFlexIO_DumpGH - @history - - @endhistory + @calls Checkpoint + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar @@*/ +void IOFlexIO_InitialDataCheckpoint (cGH *GH) +{ + DECLARE_CCTK_PARAMETERS + -void IOFlexIO_ConditionallyDumpGH (cGH *GH) + if (checkpoint && checkpoint_ID) + { + Checkpoint (GH, CP_INITIAL_DATA); + } +} + + + /*@@ + @routine IOFlexIO_EvolutionCheckpoint + @date Fri Aug 21 14:38:25 1998 + @author Gabrielle Allen + @desc + This routine is registered at CCTK_CHECKPOINT. + It periodically checks if it's time to checkpoint evolution data. + @enddesc + + @calls Checkpoint + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar +@@*/ +void IOFlexIO_EvolutionCheckpoint (cGH *GH) { DECLARE_CCTK_PARAMETERS @@ -68,7 +104,7 @@ void IOFlexIO_ConditionallyDumpGH (cGH *GH) CCTK_VInfo (CCTK_THORNSTRING, "Dumping periodic checkpoint file at " "iteration %d", GH->cctk_iteration); } - IOFlexIO_DumpGH (GH, CP_EVOLUTION_DATA); + Checkpoint (GH, CP_EVOLUTION_DATA); /* reset the 'checkpoint_next' parameter */ if (checkpoint_next) @@ -76,87 +112,34 @@ void IOFlexIO_ConditionallyDumpGH (cGH *GH) CCTK_ParameterSet ("checkpoint_next", CCTK_THORNSTRING, "no"); } } - } /*@@ - @routine IOFlexIO_TerminationDumpGH + @routine IOFlexIO_TerminationCheckpoint @date Fri Aug 21 14:40:21 1998 @author Gabrielle Allen @desc - This routine is registered as CCTK_TERMINATE - and does a checkpoint if the parameter - 'IO::checkpoint_on_terminate' was set. + This routine is registered at CCTK_TERMINATE. + It checks if the last iteration should be checkpointed. @enddesc - @calls IOFlexIO_DumpGH + + @calls Checkpoint + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar @@*/ -void IOFlexIO_TerminationDumpGH (cGH *GH) +void IOFlexIO_TerminationCheckpoint (cGH *GH) { DECLARE_CCTK_PARAMETERS if (checkpoint && checkpoint_on_terminate) { - IOFlexIO_DumpGH (GH, CP_EVOLUTION_DATA); - } -} - - - /*@@ - @routine IOFlexIO_InitialDataDumpGH - @date Fri Aug 21 14:46:28 1998 - @author Gerd Lanfermann - @desc - This routine dumps the initial data of the GHs, registered - as CCTK_CPINITIAL; sets cp_type to CP_INITIAL_DATA and calls - DumpGH; BoxInBox needs special treatment since for now. - @enddesc - @calls IOFlexIO_DumpGH - @history - - @endhistory - -@@*/ - -void IOFlexIO_InitialDataDumpGH (cGH *GH) -{ - DECLARE_CCTK_PARAMETERS - - -/*** FIXME ***/ -#if 0 - cGH *helperGH; - static int maxlev = 0; - int l; - -#ifdef THORN_BOXINBOX - /* This will go once we reorganize the CINitial calling structure! */ - /* or have a function to deregister a rfr routine */ - /* BoxinBox does its own: get maxlevel (once!) and do dumpGH for all GH*/ - /* when this is called by the highest box */ - if (Contains("boxinbox","yes")) { - if (maxlev==0) while (GHbyLevel(0,maxlev+1,0)) maxlev++; - if (maxlev==0) return; - - if (GH->level==maxlev) - for (l=0;l<=maxlev;l++) { - printf("Dumping BoxinBox level %d of %d \n",l,maxlev); - IOFlexIO_DumpGH(GHbyLevel(0,l,0), CP_INITIAL_DATA); - } - return; - } -#endif -#endif - - if (checkpoint && checkpoint_ID) - { - IOFlexIO_DumpGH (GH, CP_INITIAL_DATA); + Checkpoint (GH, CP_EVOLUTION_DATA); } } @@ -166,13 +149,11 @@ void IOFlexIO_InitialDataDumpGH (cGH *GH) @date Thu Jan 20 2000 @author Thomas Radke @desc - Gets the parameters of all active implementations as a single string - and writes it as an attribute into a group of an already opened HDF5 file. + Gets the parameters of all active implementations and writes them + as a single string attribute into a group GLOBAL_PARAMETERS. @enddesc - @calledby IOFlexIO_Write3D, IOFlexIO_DumpGH - @history + @calls IOUtil_GetAllParameters - @endhistory @var GH @vdesc Pointer to CCTK grid hierarchy @vtype const cGH * @@ -184,22 +165,23 @@ void IOFlexIO_InitialDataDumpGH (cGH *GH) @vtype int @vio in @endvar - @var iof + @var file @vdesc the IEEEIO file where to dump the parameters to @vtype IOFile @vio in @endvar @@*/ -void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile iof) +void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile file) { char *parameters; parameters = IOUtil_GetAllParameters (GH, all); - if (parameters) { - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, GLOBAL_PARAMETERS, FLEXIO_CHAR, - strlen (parameters) + 1, parameters)); + if (parameters) + { + FLEXIO_ERROR (IOwriteAttribute (file, GLOBAL_PARAMETERS, FLEXIO_CHAR, + strlen (parameters) + 1, parameters)); free (parameters); } } @@ -210,119 +192,149 @@ void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile iof) @date Thu Jan 20 2000 @author Thomas Radke @desc - Dumps the important variables from the grid hierarchy, PUGH, and IO - into a group of an already opened IEEEIO file. + Dumps the important variables from the grid hierarchy, PUGH, + and IO into a group of an already opened IEEEIO file. @enddesc - @calledby IOFlexIO_Write3D, IOFlexIO_DumpGH - @history - @endhistory @var GH @vdesc Pointer to CCTK grid hierarchy @vtype const cGH * @vio in @endvar - @var iof + @var file @vdesc the IEEEIO file where to dump the GH extensions to @vtype IOFile @vio in @endvar @@*/ -void IOFlexIOi_DumpGHExtensions (const cGH *GH, IOFile iof) +void IOFlexIOi_DumpGHExtensions (const cGH *GH, IOFile file) { - CCTK_INT4 i_temp; - CCTK_REAL d_temp; + CCTK_INT4 itmp; + CCTK_REAL dtmp; const char *version; ioGH *ioUtilGH; - /* Get the handle for IOUtil extensions */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; - i_temp = CCTK_MainLoopIndex (); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "main loop index", FLEXIO_INT4, - 1, &i_temp)); + /* get the handle for IOUtil extensions */ + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); + + itmp = CCTK_MainLoopIndex (); + FLEXIO_ERROR (IOwriteAttribute (file, "main loop index",FLEXIO_INT4,1,&itmp)); - i_temp = GH->cctk_iteration; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "GH$iteration", FLEXIO_INT4, - 1, &i_temp)); + itmp = GH->cctk_iteration; + FLEXIO_ERROR (IOwriteAttribute (file, "GH$iteration", FLEXIO_INT4, 1, &itmp)); - i_temp = ioUtilGH->ioproc_every; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "GH$ioproc_every", FLEXIO_INT4, - 1, &i_temp)); + itmp = ioUtilGH->ioproc_every; + FLEXIO_ERROR (IOwriteAttribute (file, "GH$ioproc_every",FLEXIO_INT4,1,&itmp)); - i_temp = CCTK_nProcs (GH); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "GH$nprocs", FLEXIO_INT4, - 1, &i_temp)); + itmp = CCTK_nProcs (GH); + FLEXIO_ERROR (IOwriteAttribute (file, "GH$nprocs", FLEXIO_INT4, 1, &itmp)); - d_temp = GH->cctk_time; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "GH$time", FLEXIO_REAL, - 1, &d_temp)); + dtmp = GH->cctk_time; + FLEXIO_ERROR (IOwriteAttribute (file, "GH$time", FLEXIO_REAL, 1, &dtmp)); version = CCTK_FullVersion (); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "Cactus version", FLEXIO_CHAR, - strlen (version) + 1, (const void *) version)); + FLEXIO_ERROR (IOwriteAttribute (file, "Cactus version", FLEXIO_CHAR, + strlen (version) + 1, version)); } +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ /*@@ - @routine IOFlexIO_DumpGH + @routine Checkpoint @date Fri Aug 21 15:13:13 1998 @author Paul Walker @desc - The heart of checkpointing. Called by the different wrappers, this - routines get the appropriate filename by IOUtil_PrepareFilename() and - then dumps away using the dump routines from IO ... + The heart of checkpointing. + Called by the different wrappers, this routine creates + a new checkpoint file and then dumps away all grid variables. @enddesc - @calledby IOFlexIO_ConditionallyDumpGH, IOFlexIO_TerminationDumpGH, - IOFlexIO_InitialDataDumpGH + + @calls IOUtil_PrepareFilename + IOUtil_PrintTimings + IOFlexIOi_DumpParameters + IOFlexIOi_DumpGHExtensions + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar + @var called_from + @vdesc flag indicating where this routine was called from + (either CHECKPOINT_ID, CHECKPOINT, or filereader) + @vtype int + @vio in + @endvar + @history - @hdate Oct 4 1998 @hauthor Gabrielle Allen - @hdesc Removed code which checked and reset unchunked, assume that this - is done when the variable is first set. - @hdate Nov 4 1998 @hauthor Gabrielle Allen - @hdesc Do a forced synchronization before checkpointing - @hdate Apr 16 1999 @hauthor Thomas Radke - @hdesc Removed forced sync before checkpointing (just do a normal sync) - Introduced a ring buffer for keeping last <checkpoint_keep> files + @hdate Oct 4 1998 + @hauthor Gabrielle Allen + @hdesc Removed code which checked and reset unchunked, assume that this + is done when the variable is first set. + @hdate Nov 4 1998 + @hauthor Gabrielle Allen + @hdesc Do a forced synchronization before checkpointing + @hdate Apr 16 1999 + @hauthor Thomas Radke + @hdesc Removed forced sync before checkpointing (just do a normal sync) + Introduced a ring buffer for keeping last <checkpoint_keep> files @endhistory + @returntype int + @returndesc + the accumulated return code from @seeroutine IOHDF5Util_DumpVar + (should be 0 for success, or negative if some error occured), or + -1 if checkpoint file could not be created + @endreturndesc @@*/ - -void IOFlexIO_DumpGH (const cGH *GH, int called_from) +static int Checkpoint (const cGH *GH, int called_from) { - DECLARE_CCTK_PARAMETERS - char dumpfname [1024], tmpfname [1024]; - IOFile iof; - int first_vindex, vindex, gindex; + char filename [1024], tmpfilename [1024]; + IOFile file; + int myproc, first_vindex, vindex, gindex, maxdim, retval; int timelevel, last_timelevel; cGroup gdata; int *old_downsample; int old_out_single; ioGH *ioUtilGH; flexioGH *myGH; - static char **dumpfnames = NULL; /* dump filename ring buffer */ - static int findex = 0; /* index into ring buffer */ + static char **cp_filenames = NULL; + static int cp_fileindex = 0; /*** FIXME: can CCTK_SyncGroup() have a 'const cGH *' parameter ?? ***/ union { const cGH *const_ptr; cGH *non_const_ptr; } GH_fake_const; + const char *timer_descriptions [3] = {"Time to dump parameters: ", + "Time to dump datasets: ", + "Total time to checkpoint:"}; + DECLARE_CCTK_PARAMETERS + retval = 0; GH_fake_const.const_ptr = GH; - /* Get the handles for IOUtil and IOFlexIO extensions */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; - myGH = (flexioGH *) GH->extensions [CCTK_GHExtensionHandle ("IOFlexIO")]; + /* get the handles for IOUtil and IOFlexIO extensions */ + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); - /* allocate the ring buffer for filenames */ - if (! dumpfnames) - dumpfnames = (char **) calloc (checkpoint_keep, sizeof (char *)); + myproc = CCTK_MyProc (GH); + maxdim = CCTK_MaxDim (); + + /* allocate the ring buffer for checkpoint filenames */ + if (! cp_filenames) + { + cp_filenames = (char **) calloc (checkpoint_keep, sizeof (char *)); + } /* disable downsampling after saving original downsampling params */ - old_downsample = (int *) malloc (CCTK_MaxDim () * sizeof (int)); - for (vindex = 0; vindex < CCTK_MaxDim (); vindex++) { + old_downsample = (int *) malloc (maxdim * sizeof (int)); + for (vindex = 0; vindex < maxdim; vindex++) + { old_downsample [vindex] = ioUtilGH->downsample [vindex]; ioUtilGH->downsample [vindex] = 1; } @@ -333,38 +345,38 @@ void IOFlexIO_DumpGH (const cGH *GH, int called_from) /* start the total timer */ if (myGH->print_timing_info) + { CCTK_TimerStartI (myGH->timers[2]); - - /* sync all active groups */ - for (vindex = 0; vindex < CCTK_NumGroups (); vindex++) - if (CCTK_IsImplementationActive (CCTK_ImpFromVarI ( - CCTK_FirstVarIndexI (vindex)))) - CCTK_SyncGroupI (GH_fake_const.non_const_ptr, vindex); + } /* get the base filename ... */ - IOUtil_PrepareFilename (GH, NULL, dumpfname, called_from, - CCTK_MyProc (GH) / ioUtilGH->ioproc_every, - ioUtilGH->unchunked); + IOUtil_PrepareFilename (GH, NULL, filename, called_from, + myproc / ioUtilGH->ioproc_every, ioUtilGH->unchunked); /* ... and append the extension */ - sprintf (tmpfname, "%s.tmp.ieee", dumpfname); - sprintf (dumpfname, "%s.ieee", dumpfname); + sprintf (tmpfilename, "%s.tmp.ieee", filename); + sprintf (filename, "%s.ieee", filename); /* Now open the file */ - if (CCTK_MyProc (GH) == ioUtilGH->ioproc) { + if (myproc == ioUtilGH->ioproc) + { if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "Creating file '%s'", tmpfname); - iof = IEEEopen (tmpfname, "w"); - if (! IOisValid (iof)) { + { + CCTK_VInfo (CCTK_THORNSTRING, "Creating file '%s'", tmpfilename); + } + file = IEEEopen (tmpfilename, "w"); + if (! IOisValid (file)) + { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Can't open checkpoint file '%s'. Checkpointing is skipped", - tmpfname); - return; + tmpfilename); + return (-1); } - } else - iof = (IOFile) NULL; - - /* Great; Now start dumping away! */ + } + else + { + file = (IOFile) NULL; + } /* start timer for dumping parameters */ if (myGH->print_timing_info) @@ -373,12 +385,15 @@ void IOFlexIO_DumpGH (const cGH *GH, int called_from) CCTK_TimerStartI (myGH->timers[0]); } - /* first the parameters ... */ - if (iof) { + /* first dump the parameters ... */ + if (file) + { if (verbose) + { CCTK_INFO ("Dumping Params ..."); - IOFlexIOi_DumpParameters (GH, 1, iof); - IOFlexIOi_DumpGHExtensions (GH, iof); + } + IOFlexIOi_DumpParameters (GH, 1, file); + IOFlexIOi_DumpGHExtensions (GH, file); } /* stop parameter timer and start timer for dumping datasets */ @@ -413,64 +428,74 @@ void IOFlexIO_DumpGH (const cGH *GH, int called_from) for (vindex = first_vindex; vindex < first_vindex + gdata.numvars; vindex++) { if (verbose) + { CCTK_VInfo (CCTK_THORNSTRING, " %s", CCTK_VarName (vindex)); + } for (timelevel = 0; timelevel < last_timelevel; timelevel++) { - IOFlexIO_DumpVar (GH, vindex, timelevel, iof); + retval += IOFlexIO_DumpVar (GH, vindex, timelevel, file); } } /* end of loop over all variables */ } /* end of loop over all groups */ /* stop timer for dumping datasets */ if (myGH->print_timing_info) + { CCTK_TimerStopI (myGH->timers[1]); + } - CACTUS_IEEEIO_ERROR (IOclose (iof)); + /* close the temporary checkpoint file */ + FLEXIO_ERROR (IOclose (file)); - if (CCTK_MyProc (GH) == ioUtilGH->ioproc) { + if (myproc == ioUtilGH->ioproc) + { if (verbose) + { CCTK_VInfo (CCTK_THORNSTRING, "Closing and renaming checkpoint file " - "into '%s'", dumpfname); + "into '%s'", filename); + } #ifdef _WIN32 /* Windows' rename(2) routine isn't POSIX compatible in that it would unlink an existing file */ - unlink (dumpfname); + unlink (filename); #endif - if (rename (tmpfname, dumpfname)) + if (rename (tmpfilename, filename)) + { CCTK_VWarn (0, __LINE__, __FILE__, CCTK_THORNSTRING, "Could not rename temporary checkpoint file %s to %s", - tmpfname, dumpfname); + tmpfilename, filename); + } } /* delete the oldest dumpfile if checkpoint_keep_all isn't set and put the new filename into the ring buffer */ - if (dumpfnames [findex]) { + if (cp_filenames [cp_fileindex]) + { if (! checkpoint_keep_all) - remove (dumpfnames [findex]); - free (dumpfnames [findex]); + { + remove (cp_filenames [cp_fileindex]); + } + free (cp_filenames [cp_fileindex]); } - dumpfnames [findex] = strdup (dumpfname); - findex = (findex + 1) % checkpoint_keep; + cp_filenames [cp_fileindex] = strdup (filename); + cp_fileindex = (cp_fileindex + 1) % checkpoint_keep; /* restore output precision flag */ ioUtilGH->out_single = old_out_single; /* restore original downsampling params */ - memcpy (ioUtilGH->downsample, old_downsample, CCTK_MaxDim () * sizeof (int)); + memcpy (ioUtilGH->downsample, old_downsample, maxdim * sizeof (int)); free (old_downsample); /* stop total checkpoint timer and print timing info */ if (myGH->print_timing_info) { - const char *timer_descriptions [3] = {"Time to dump parameters: ", - "Time to dump datasets: ", - "Total time to checkpoint:"}; - - CCTK_TimerStopI (myGH->timers[2]); IOUtil_PrintTimings ("Timing information for checkpointing in IOFlexIO:", 3, myGH->timers, timer_descriptions); } + + return (retval); } diff --git a/src/DumpVar.c b/src/DumpVar.c index 5ca15ca..6932d00 100644 --- a/src/DumpVar.c +++ b/src/DumpVar.c @@ -1,35 +1,16 @@ /*@@ @file DumpVar.c - @desc - Do the actual writing of a 3D grid function, for output or for checkpointing - @enddesc - @history - @hauthor Gabrielle Allen @hdate Oct 17 1998 - @hdesc Split into subroutines and tidied. - @hauthor Gabrielle Allen @hdate 19 Oct 1998 - @hdesc Changed names ready for thorn_IO - @hauthor Thomas Radke @hdate 16 Mar 1999 - @hdesc Converted to Cactus 4.0 - introduced separate downsample values for each dimension - @hauthor Thomas Radke @hdate 17 Mar 1999 - @hdesc Changed naming: IEEEIO -> IOFlexIO - @hauthor Thomas Radke @hdate 17 Mar 1999 - @hdesc fixed errors for MPI - @hauthor Thomas Radke @hdate 12 Apr 1999 - @hdesc Store full variable name in IOFlexIO_AddCommonAttributes() - @hauthor Thomas Radke @hdate 16 Apr 1999 - @hdesc Added groupname, grouptype, ntimelevels, and current timelevel - as common attributes - @hendhistory - @version $Id$ + @author Paul Walker, Gabrielle Allen, Tom Goodale, Thomas Radke + @desc + Routines for writing variables into IOFlexIO data or + checkpoint files. + @enddesc + @version $Id$ @@*/ #include <stdio.h> #include <stdlib.h> -#ifdef SGI -#include <time.h> -#endif #include "cctk.h" #include "cctk_Parameters.h" @@ -38,17 +19,25 @@ #include "ioFlexGH.h" -#define IOTAGBASE 20000 /* This may break on more than 2000 processors */ - -/*#define IOFLEXIO_DEBUG 1 */ - /* the rcs ID and its dummy funtion to use it */ static const char *rcsid = "$Id$"; CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_DumpVar_c) +/******************************************************************** + ******************** Macro Definitions ************************ + ********************************************************************/ +/* #define IOFLEXIO_DEBUG 1 */ + +#define IOTAGBASE 20000 /* This may break on more than 2000 processors */ + + +/******************************************************************** + ******************** Internal Typedefs ************************ + ********************************************************************/ /* info structure describing how to dump a given CCTK variable type */ -typedef struct { +typedef struct +{ int flexio_type; /* the FLEXIO type to use */ int element_size; /* size of a single data element */ #ifdef CCTK_MPI @@ -57,73 +46,78 @@ typedef struct { } dumpInfo_t; -/* local function prototypes */ -static void IOFlexIO_DumpGS (const cGH *GH, int vindex, int timelevel, IOFile iof, - int flexio_type); -static void IOFlexIO_DumpGA (const cGH *GH, int vindex, int timelevel, IOFile iof, - dumpInfo_t *info); -static void IOFlexIO_getDumpData (const cGH *GH, int vindex, int timelevel, - void **outme, int *free_outme, CCTK_INT4 *geom, int element_size); -static void IOFlexIO_eachProcDump (const cGH *GH, int vindex, int timelevel, - void *outme, CCTK_INT4 *geom, IOFile iof, int flexio_type); -static void IOFlexIO_AddChunkAttributes (const cGH *GH, int vindex, CCTK_INT4 *geom, - IOFile iof); -static void IOFlexIO_AddCommonAttributes (const cGH *GH, int vindex, int timelevel, - CCTK_INT4 *gsz, IOFile iof); +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static int DumpGS (const cGH *GH, int vindex, int timelevel, IOFile file, + int flexio_type); +static int DumpGA (const cGH *GH, int vindex, int timelevel, IOFile file, + dumpInfo_t *info); +static int GetDumpData (const cGH *GH, int vindex, int timelevel, void **outme, + int *free_outme, CCTK_INT4 *geom, int element_size); +static void EachProcDump (const cGH *GH, int vindex, int timelevel, void *outme, + CCTK_INT4 *geom, IOFile file, int flexio_type); +static void AddChunkAttributes (const cGH *GH, int vindex, CCTK_INT4 *geom, + IOFile file); +static void AddCommonAttributes (const cGH *GH, int vindex, int timelevel, + CCTK_INT4 *gsz, IOFile file); #ifdef CCTK_MPI -static void IOFlexIO_procDump (IOFile iof, const cGH *GH, int vindex, void *outme, - CCTK_INT4 *geom, int flexio_type); +static void ProcDump (IOFile file, const cGH *GH, int vindex, void *outme, + CCTK_INT4 *geom, int flexio_type); #endif - /*@@ - @routine IOFlexIO_DumpVar - @date 16 Apr 1999 - @author Thomas Radke - @desc - Generic dump routine, just calls the appropriate dump routine - @enddesc - @calls - @calledby IOFlexIO_DumpGH IOFlexIO_Write3D - - @var GH - @vdesc Pointer to CCTK grid hierarchy - @vtype const cGH * - @vio in - @endvar - @var vindex - @vdesc global index of the variable to be dumped - @vtype int - @vio in - @endvar - @var timelevel - @vdesc the timelevel to store - @vtype int - @vio in - @endvar - @var iof - @vdesc the IEEEIO file to dump to - @vtype IOFile - @vio in - @endvar - @history - @endhistory + @routine IOFlexIO_DumpVar + @date 16 Apr 1999 + @author Thomas Radke + @desc + Generic dump routine, just calls the appropriate dump routine + @enddesc + + @calls + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var vindex + @vdesc global index of the variable to be dumped + @vtype int + @vio in + @endvar + @var timelevel + @vdesc the timelevel to store + @vtype int + @vio in + @endvar + @var file + @vdesc the IEEEIO file to dump to + @vtype IOFile + @vio in + @endvar + @returntype int + @returndesc + -1 if variable has unknown type + or return code of either @seeroutine DumpGS or @seeroutine DumpGA + @endreturndesc @@*/ -void IOFlexIO_DumpVar (const cGH *GH, int vindex, int timelevel, IOFile iof) +int IOFlexIO_DumpVar (const cGH *GH, int vindex, int timelevel, IOFile file) { + int vtype, gtype, retval; pGH *pughGH; ioGH *ioUtilGH; - int vtype; dumpInfo_t info; - /* Get the handle for PUGH and IOUtil extensions */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; - pughGH = (pGH *) GH->extensions [CCTK_GHExtensionHandle ("PUGH")]; + /* get the handle for PUGH and IOUtil extensions */ + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); + pughGH = (pGH *) CCTK_GHExtension (GH, "PUGH"); vtype = CCTK_VarTypeI (vindex); + /* downgrade the output precision if requested */ if (ioUtilGH->out_single) { @@ -159,24 +153,27 @@ void IOFlexIO_DumpVar (const cGH *GH, int vindex, int timelevel, IOFile iof) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Unsupported variable type %d", vtype); - return; + return (-1); } - switch (CCTK_GroupTypeFromVarI (vindex)) { - case CCTK_SCALAR: - IOFlexIO_DumpGS (GH, vindex, timelevel, iof, info.flexio_type); - break; - - case CCTK_GF: - case CCTK_ARRAY: - IOFlexIO_DumpGA (GH, vindex, timelevel, iof, &info); - break; - - default: - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Invalid group type %d", CCTK_GroupTypeFromVarI (vindex)); - return; + /* now branch to the appropriate dump routine */ + gtype = CCTK_GroupTypeFromVarI (vindex); + if (gtype == CCTK_SCALAR) + { + retval = DumpGS (GH, vindex, timelevel, file, info.flexio_type); + } + else if (gtype == CCTK_ARRAY || gtype == CCTK_GF) + { + retval = DumpGA (GH, vindex, timelevel, file, &info); + } + else + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid group type %d", gtype); + retval = -1; } + + return (retval); } @@ -206,162 +203,178 @@ int IOFlexIO_DataType (int cctk_type) 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; + 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; + case CCTK_VARIABLE_INT2: retval = FLEXIO_INT2; break; #endif #ifdef CCTK_INT4 - case CCTK_VARIABLE_INT4: retval = FLEXIO_INT4; break; + case CCTK_VARIABLE_INT4: retval = FLEXIO_INT4; break; #endif #ifdef CCTK_INT8 - case CCTK_VARIABLE_INT8: retval = FLEXIO_INT8; break; + case CCTK_VARIABLE_INT8: retval = FLEXIO_INT8; break; #endif #ifdef CCTK_REAL4 - case CCTK_VARIABLE_REAL4: retval = FLEXIO_REAL4; break; + case CCTK_VARIABLE_REAL4: retval = FLEXIO_REAL4; break; #endif #ifdef CCTK_REAL8 - case CCTK_VARIABLE_REAL8: retval = FLEXIO_REAL8; break; + case CCTK_VARIABLE_REAL8: retval = FLEXIO_REAL8; break; #endif #ifdef CCTK_REAL16 - case CCTK_VARIABLE_REAL16: retval = FLEXIO_REAL16; break; + case CCTK_VARIABLE_REAL16: retval = FLEXIO_REAL16; break; #endif default: CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Unsupported CCTK variable datatype %d", cctk_type); retval = -1; + break; } return (retval); } -/************************** local routines ******************************/ +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ /*@@ - @routine IOFlexIO_DumpGS - @date 16 Apr 1999 - @author Thomas Radke - @desc - Dumps a SCALAR type variable into a IEEEIO file - @enddesc - @calls - @calledby IOFlexIO_DumpVar - - @var GH - @vdesc Pointer to CCTK grid hierarchy - @vtype const cGH * - @vio in - @endvar - @var vindex - @vdesc global index of the variable to be dumped - @vtype int - @vio in - @endvar - @var timelevel - @vdesc the timelevel to store - @vtype int - @vio in - @endvar - @var iof - @vdesc the IEEEIO file to dump to - @vtype IOFile - @vio in - @endvar - @var flexio_type - @vdesc the IOFlexIO datatype to store - @vtype int - @vio in - @endvar - @history - @endhistory + @routine DumpGS + @date 16 Apr 1999 + @author Thomas Radke + @desc + Dumps a SCALAR type variable into a IEEEIO file + @enddesc + + @calls AddCommonAttributes + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var vindex + @vdesc global index of the variable to be dumped + @vtype int + @vio in + @endvar + @var timelevel + @vdesc the timelevel to store + @vtype int + @vio in + @endvar + @var file + @vdesc the IEEEIO file to dump to + @vtype IOFile + @vio in + @endvar + @var flexio_type + @vdesc the IOFlexIO datatype to store + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + 0 for success, or -1 if file handle is invalid + @endreturndesc @@*/ -static void IOFlexIO_DumpGS (const cGH *GH, int vindex, int timelevel, IOFile iof, - int flexio_type) +static int DumpGS (const cGH *GH, int vindex, int timelevel, IOFile file, + int flexio_type) { ioGH *ioUtilGH; - CCTK_INT gsz [] = {0, 0, 0}; /* not needed here ? */ - int dim [] = {1}; /* size of scalar */ + CCTK_INT gsz[] = {0, 0, 0}; /* not needed here ? */ + int dim[] = {1}; /* size of scalar */ + + /* immediately return if file handle is invalid */ + if (! IOisValid (file)) + { + return (-1); + } - /* Get the handle for IOUtil extensions */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; + /* get the handle for IOUtil extensions */ + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); if (CCTK_MyProc (GH) != ioUtilGH->ioproc) - return; + { + return (0); + } /* first dump the data then add the attributes */ - CACTUS_IEEEIO_ERROR (IOwrite (iof, flexio_type, 1, dim, - CCTK_VarDataPtrI (GH, timelevel, vindex))); - IOFlexIO_AddCommonAttributes (GH, vindex, timelevel, gsz, iof); + FLEXIO_ERROR (IOwrite (file, flexio_type, 1, dim, + CCTK_VarDataPtrI (GH, timelevel, vindex))); + AddCommonAttributes (GH, vindex, timelevel, gsz, file); + + return (0); } /*@@ - @routine IOFlexIO_DumpGA - @date July 1998 - @author Paul Walker - @desc - - @enddesc - @calls - @calledby IOFlexIO_DumpVar - - @var GH - @vdesc Pointer to CCTK grid hierarchy - @vtype const cGH * - @vio in - @endvar - @var vindex - @vdesc global index of the variable to be dumped - @vtype int - @vio in - @endvar - @var timelevel - @vdesc the timelevel to store - @vtype int - @vio in - @endvar - @var iof - @vdesc the IEEEIO file to dump to - @vtype IOFile - @vio in - @endvar - @var info - @vdesc info structure describing - - the IOFlexIO datatype to store - - the size of an element of variable - - the MPI datatype to communicate - @vtype dumpInfo_t - @vio in - @endvar + @routine DumpGA + @date July 1998 + @author Paul Walker + @desc + Dumps a grid array variable into a IEEEIO file. + @enddesc + + @calls GetDumpData - @history - @endhistory + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype const cGH * + @vio in + @endvar + @var vindex + @vdesc global index of the variable to be dumped + @vtype int + @vio in + @endvar + @var timelevel + @vdesc the timelevel to store + @vtype int + @vio in + @endvar + @var file + @vdesc the IEEEIO file to dump to + @vtype IOFile + @vio in + @endvar + @var info + @vdesc info structure describing + - the IOFlexIO datatype to store + - the size of an element of variable + - the MPI datatype to communicate + @vtype dumpInfo_t + @vio in + @endvar + @returntype int + @returndesc + 0 for success + or returncode of @seeroutine GetDumpData + @endreturndesc @@*/ -static void IOFlexIO_DumpGA (const cGH *GH, int vindex, int timelevel, IOFile iof, - dumpInfo_t *info) +static int DumpGA (const cGH *GH, int vindex, int timelevel, IOFile file, + dumpInfo_t *info) { - DECLARE_CCTK_PARAMETERS - ioGH *ioUtilGH; + int myproc, nprocs, dim, free_outme, retval; pGH *pughGH; - int myproc; - int nprocs; - int dim; - CCTK_INT4 *geom; /* Lower bounds, size and global size of data we send */ - void *outme; /* pointer to the data to be dumped */ - int free_outme; /* indicates whether data buffer needs freeing */ + ioGH *ioUtilGH; + CCTK_INT4 *geom; + void *outme; #ifdef CCTK_MPI - int i, j; + int i, j, incoming, outgoing; + int *local_size; MPI_Status ms; + void *tmpd; #endif + DECLARE_CCTK_PARAMETERS - /* Get the handles for PUGH and IO extensions */ + /* get the handles for PUGH and IO extensions */ pughGH = PUGH_pGH (GH); - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); myproc = CCTK_MyProc (GH); nprocs = CCTK_nProcs (GH); @@ -372,183 +385,198 @@ static void IOFlexIO_DumpGA (const cGH *GH, int vindex, int timelevel, IOFile io /* allocate the geometry buffer */ geom = (CCTK_INT4 *) malloc (3*dim * sizeof (CCTK_INT4)); - /* Get the pointer to the data we want to output (includes downsampling) */ - IOFlexIO_getDumpData (GH, vindex, timelevel, &outme, &free_outme, geom, + /* get the pointer to the data we want to output (includes downsampling) */ + retval = GetDumpData (GH, vindex, timelevel, &outme, &free_outme, geom, info->element_size); - - if (ioUtilGH->ioproc_every == 1) { - - /* - * OUTPUT ON EVERY PROCESSOR - */ - - IOFlexIO_eachProcDump (GH, vindex, timelevel, outme, geom, iof, info->flexio_type); - + if (retval < 0) + { + return (retval); } + if (ioUtilGH->ioproc_every == 1) + { + EachProcDump (GH, vindex, timelevel, outme, geom, file, info->flexio_type); + } #ifdef CCTK_MPI - else if (myproc != ioUtilGH->ioproc) { - - int outgoing = geom [dim]; - - for (i = 1; i < dim; i++) - outgoing *= geom [dim + i]; - - /* - * OUTPUT ON A SUBSET OF PROCESSORS - */ - - /* Send the geometry and data from the processors which aren't - * outputing to the ones that are + else if (myproc != ioUtilGH->ioproc) + { + /* + * Send the geometry and data from non-IO processors to the IO processors */ + outgoing = 1; + for (i = 0; i < dim; i++) + { + outgoing *= geom[dim + i]; + } - /* GEOMETRY SEND */ + /* send geometry */ CACTUS_MPI_ERROR (MPI_Send (geom, 3*dim, PUGH_MPI_INT4, ioUtilGH->ioproc, - 2*myproc+IOTAGBASE+1, pughGH->PUGH_COMM_WORLD)); - /* DATA SEND */ - CACTUS_MPI_ERROR (MPI_Send (outme, outgoing, info->mpi_type, ioUtilGH->ioproc, - 2*myproc+IOTAGBASE, pughGH->PUGH_COMM_WORLD)); - + 2*myproc+IOTAGBASE+1, pughGH->PUGH_COMM_WORLD)); + /* send data */ + if (outgoing > 0) + { + CACTUS_MPI_ERROR (MPI_Send (outme, outgoing, info->mpi_type, + ioUtilGH->ioproc, 2*myproc+IOTAGBASE, + pughGH->PUGH_COMM_WORLD)); #ifdef IOFLEXIO_DEBUG - printf ("Sent %d data points\n", outgoing); - fflush (stdout); + printf ("Processor %d sent %d data points\n", myproc, outgoing); #endif - - } else if (myproc == ioUtilGH->ioproc) { - - int *lsz = (int *) malloc (dim * sizeof (int)); - - /* First calculate the local size and reserve the chunk */ - if (ioUtilGH->ioproc_every >= nprocs) { - - /* One output file ... the local chunk size is the global size */ - for (i = 0; i < dim; i++) - lsz [i] = geom [2*dim + i]; } + } + else if (myproc == ioUtilGH->ioproc) + { + if (ioUtilGH->unchunked) + { + local_size = (int *) malloc (dim * sizeof (int)); - /* Dump data held on output processor */ + /* first calculate the local size and reserve the chunk */ + if (ioUtilGH->ioproc_every >= nprocs) + { + /* one output file ... the local chunk size is the global size */ + for (i = 0; i < dim; i++) + { + local_size[i] = geom[2*dim + i]; + } + } - if (ioUtilGH->unchunked) - IOreserveChunk (iof, info->flexio_type, dim, lsz); + IOreserveChunk (file, info->flexio_type, dim, local_size); - free (lsz); + free (local_size); + } - /* first the data then the attributes */ - IOFlexIO_procDump (iof, GH, vindex, outme, geom, info->flexio_type); + /* write the data first then the attributes */ + ProcDump (file, GH, vindex, outme, geom, info->flexio_type); /* delay adding attributes for unchunked files until all chunks were written (otherwise attributes get lost !) */ if (! ioUtilGH->unchunked) - IOFlexIO_AddCommonAttributes (GH, vindex, timelevel, &geom [2*dim], iof); - - /* Dump data from all other processors */ - - for (i = myproc+1; i < myproc+ioUtilGH->ioproc_every && i < nprocs; i++) { - - /* Allocate temp to the right size (based on GH->ub [i] et..) */ - void *tmpd; - int incoming; + { + AddCommonAttributes (GH, vindex, timelevel, &geom[2*dim], file); + } - /* Receive bounds information */ + /* dump data from all other processors */ + for (i = myproc+1; i < myproc+ioUtilGH->ioproc_every && i < nprocs; i++) + { + /* receive geometry */ CACTUS_MPI_ERROR (MPI_Recv (geom, 3*dim, PUGH_MPI_INT4, i,2*i+IOTAGBASE+1, - pughGH->PUGH_COMM_WORLD, &ms)); + pughGH->PUGH_COMM_WORLD, &ms)); - incoming = geom [dim]; - for (j = 1; j < dim; j++) - incoming *= geom [dim + j]; + incoming = 1; + for (j = 0; j < dim; j++) + { + incoming *= geom[dim + j]; + } - tmpd = malloc (incoming * info->element_size); - CACTUS_MPI_ERROR (MPI_Recv (tmpd, incoming, info->mpi_type, i, - 2*i+IOTAGBASE, pughGH->PUGH_COMM_WORLD, &ms)); + /* receive data */ + if (incoming > 0) + { + tmpd = malloc (incoming * info->element_size); + CACTUS_MPI_ERROR (MPI_Recv (tmpd, incoming, info->mpi_type, i, + 2*i+IOTAGBASE,pughGH->PUGH_COMM_WORLD,&ms)); + } + else + { + tmpd = NULL; + } - IOFlexIO_procDump (iof, GH, vindex, tmpd, geom, info->flexio_type); - free (tmpd); + /* write data */ + ProcDump (file, GH, vindex, tmpd, geom, info->flexio_type); - } /* End loop over processors */ + if (tmpd) + { + free (tmpd); + } + } /* end loop over processors */ /* now add the attributes for unchunked files */ if (ioUtilGH->unchunked) - IOFlexIO_AddCommonAttributes (GH, vindex, timelevel, &geom [2*dim], iof); - - } /* End myproc = 0 */ + { + AddCommonAttributes (GH, vindex, timelevel, &geom[2*dim], file); + } + } + /* wait for every processor to catch up */ CCTK_Barrier (GH); #endif /* MPI */ if (free_outme) + { free (outme); + } free (geom); + + return (retval); } /*@@ - @routine IOFlexIO_AddCommonAttributes + @routine AddCommonAttributes @date July 1998 @author Paul Walker - @desc - Add "Common" attributes, these are the GF name, the current date, - simulation time, origin, bounding box, gridspacings (both downsampled - and evolution), global grid size, number of processors and iteration - number. Note that the datestamp should be turned of if you are byte - comparing two output files. - @enddesc - @calls - @calledby - @history - @hdate Wed Sep 2 10:15:22 1998 @hauthor Tom Goodale - @hdesc Abstracted WRITE_ATTRIBUTE to merge in Szu-Wen's Panda changes. - @hdate Apr 16 1999 @hauthor Thomas Radke - @hdesc Added attributes groupname, grouptype, ntimelevels, - and current timelevel to be stored - @hdate May 02 1999 @hauthor Thomas Radke - @hdesc Made chunked attribute nioprocs common so that it can be found by - the recombiner even for unchunked datasets (eg. SCALARs) - @hdate May 05 1999 @hauthor Thomas Radke - @hdesc Added "unchunked" attribute to distinguish between chunked/unchunked - output files - @endhistory + @desc + Add "Common" attributes, these are the GF name, the current date, + simulation time, origin, bounding box, and gridspacings (both + downsampled and evolution). + @enddesc + + @calls + + @history + @hdate Wed Sep 2 10:15:22 1998 + @hauthor Tom Goodale + @hdesc Abstracted WRITE_ATTRIBUTE to merge in Szu-Wen's Panda changes. + @hdate Apr 16 1999 + @hauthor Thomas Radke + @hdesc Added attributes groupname, grouptype, ntimelevels, + and current timelevel to be stored + @hdate May 02 1999 + @hauthor Thomas Radke + @hdesc Made chunked attribute nioprocs common so that it can be found by + the recombiner even for unchunked datasets (eg. SCALARs) + @hdate May 05 1999 + @hauthor Thomas Radke + @hdesc Added "unchunked" attribute to distinguish between + chunked/unchunked output files + @endhistory @@*/ -static void IOFlexIO_AddCommonAttributes (const cGH *GH, int vindex, int timelevel, - CCTK_INT4 *gsz, IOFile iof) +static void AddCommonAttributes (const cGH *GH, int vindex, int timelevel, + CCTK_INT4 *gsz, IOFile file) { - DECLARE_CCTK_PARAMETERS - int dim, vdim; - CCTK_REAL *attr_real; /* buffer for writing doubles to IEEEIO */ - CCTK_INT4 attr_int4; /* buffer for writing an int to IEEEIO */ - char *name, *gname; + int i, vdim; + CCTK_REAL *dtmp; + CCTK_INT4 itmp; + char *name; ioGH *ioUtilGH; char coord_system_name[20]; + DECLARE_CCTK_PARAMETERS - /* Get the handle for IO extensions */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; + /* get the handle for IO extensions */ + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); /* get the dimension of the variable */ vdim = CCTK_GroupDimFromVarI (vindex); name = CCTK_FullName (vindex); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "name", FLEXIO_CHAR, - strlen (name) + 1, name)); + FLEXIO_ERROR (IOwriteAttribute (file, "name", FLEXIO_CHAR, + strlen (name) + 1, name)); free (name); - gname = CCTK_GroupNameFromVarI (vindex); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "groupname", FLEXIO_CHAR, - strlen (gname) + 1, gname)); - free (gname); + name = CCTK_GroupNameFromVarI (vindex); + FLEXIO_ERROR (IOwriteAttribute (file, "groupname", FLEXIO_CHAR, + strlen (name) + 1, name)); + free (name); - attr_int4 = CCTK_GroupTypeFromVarI (vindex); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "grouptype", FLEXIO_INT4, - 1, &attr_int4)); + itmp = CCTK_GroupTypeFromVarI (vindex); + FLEXIO_ERROR (IOwriteAttribute (file, "grouptype", FLEXIO_INT4, 1, &itmp)); - attr_int4 = CCTK_NumTimeLevelsFromVarI (vindex); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "ntimelevels", FLEXIO_INT4, - 1, &attr_int4)); + itmp = CCTK_NumTimeLevelsFromVarI (vindex); + FLEXIO_ERROR (IOwriteAttribute (file, "ntimelevels", FLEXIO_INT4, 1, &itmp)); - attr_int4 = timelevel; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "timelevel", FLEXIO_INT4, - 1, &attr_int4)); + itmp = timelevel; + FLEXIO_ERROR (IOwriteAttribute (file, "timelevel", FLEXIO_INT4, 1, &itmp)); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "time", FLEXIO_REAL, 1,&GH->cctk_time)); + FLEXIO_ERROR (IOwriteAttribute (file, "time", FLEXIO_REAL, 1,&GH->cctk_time)); /* attributes describing the underlying grid These are only stored for CCTK_GF variables if they are associated @@ -560,164 +588,157 @@ static void IOFlexIO_AddCommonAttributes (const cGH *GH, int vindex, int timelev if (CCTK_GroupTypeFromVarI (vindex) == CCTK_GF && CCTK_CoordSystemHandle (coord_system_name) >= 0) { - attr_real = (CCTK_REAL *) malloc (3 * vdim * sizeof (CCTK_REAL)); - for (dim = 0; dim < vdim; dim++) + dtmp = (CCTK_REAL *) malloc (3 * vdim * sizeof (CCTK_REAL)); + for (i = 0; i < vdim; i++) { - CCTK_CoordRange (GH, &attr_real[dim], &attr_real[dim + vdim], dim + 1, + CCTK_CoordRange (GH, &dtmp[i], &dtmp[i + vdim], i + 1, NULL, coord_system_name); - attr_real [dim + 2*vdim] = GH->cctk_delta_space [dim] * - ioUtilGH->downsample [dim]; + dtmp[i + 2*vdim] = GH->cctk_delta_space[i] * ioUtilGH->downsample[i]; } - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "origin", FLEXIO_REAL, vdim, - attr_real)); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "min_ext", FLEXIO_REAL, vdim, - attr_real)); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "max_ext", FLEXIO_REAL, vdim, - attr_real + vdim)); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "delta", FLEXIO_REAL, vdim, - attr_real + 2*vdim)); - - if (ioUtilGH->downsample [0] > 1 || - ioUtilGH->downsample [1] > 1 || - ioUtilGH->downsample [2] > 1) + FLEXIO_ERROR (IOwriteAttribute (file, "origin", FLEXIO_REAL, vdim, dtmp)); + FLEXIO_ERROR (IOwriteAttribute (file, "min_ext", FLEXIO_REAL, vdim, dtmp)); + FLEXIO_ERROR (IOwriteAttribute (file, "max_ext", FLEXIO_REAL, vdim, + dtmp + vdim)); + FLEXIO_ERROR (IOwriteAttribute (file, "delta", FLEXIO_REAL, vdim, + dtmp + 2*vdim)); + + if (ioUtilGH->downsample[0] > 1 || + ioUtilGH->downsample[1] > 1 || + ioUtilGH->downsample[2] > 1) { - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "evolution_delta", FLEXIO_REAL, - vdim, GH->cctk_delta_space)); + FLEXIO_ERROR (IOwriteAttribute (file, "evolution_delta", FLEXIO_REAL, + vdim, GH->cctk_delta_space)); } - free (attr_real); + free (dtmp); } - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "global_size", FLEXIO_INT4, - vdim, gsz)); + FLEXIO_ERROR (IOwriteAttribute (file, "global_size", FLEXIO_INT4, vdim, gsz)); - attr_int4 = CCTK_nProcs (GH); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "nprocs", FLEXIO_INT4, - 1, &attr_int4)); + itmp = CCTK_nProcs (GH); + FLEXIO_ERROR (IOwriteAttribute (file, "nprocs", FLEXIO_INT4, 1, &itmp)); - attr_int4 = ioUtilGH->ioproc_every; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "ioproc_every", FLEXIO_INT4, - 1, &attr_int4)); + itmp = ioUtilGH->ioproc_every; + FLEXIO_ERROR (IOwriteAttribute (file, "ioproc_every", FLEXIO_INT4, 1, &itmp)); - attr_int4 = ioUtilGH->unchunked; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "unchunked", FLEXIO_INT4, - 1, &attr_int4)); + itmp = ioUtilGH->unchunked; + FLEXIO_ERROR (IOwriteAttribute (file, "unchunked", FLEXIO_INT4, 1, &itmp)); - attr_int4 = GH->cctk_iteration; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "iteration", FLEXIO_INT4, - 1, &attr_int4)); + itmp = GH->cctk_iteration; + FLEXIO_ERROR (IOwriteAttribute (file, "iteration", FLEXIO_INT4, 1, &itmp)); } /*@@ - @routine IOFlexIO_AddChunkAttributes - @author Paul Walker - @date Feb 1997 + @routine AddChunkAttributes + @author Paul Walker + @date Feb 1997 @desc - This routine adds chunk attributes to a data set. That is, - is adds attributes to the chunks of data passed to the - io processors. + This routine adds chunk attributes to a data set. That is, + is adds attributes to the chunks of data passed to the + I/O processors. @enddesc - @history - @hauthor Gabrielle Allen - @hdate Jul 10 1998 - @hdesc Added the name of the grid function - @hdate Wed Sep 2 10:08:31 1998 @hauthor Tom Goodale - @hdesc Abstracted WRITE_ATTRIBUTE to merge in Szu-Wen's Panda calls. - @endhistory + @history + @hauthor Gabrielle Allen + @hdate Jul 10 1998 + @hdesc Added the name of the grid function + @hdate Wed Sep 2 10:08:31 1998 + @hauthor Tom Goodale + @hdesc Abstracted WRITE_ATTRIBUTE to merge in Szu-Wen's Panda calls. + @endhistory @@*/ -static void IOFlexIO_AddChunkAttributes (const cGH *GH, int vindex, CCTK_INT4 *geom, - IOFile iof) +static void AddChunkAttributes (const cGH *GH, int vindex, CCTK_INT4 *geom, + IOFile file) { int vdim; char *name; - CCTK_INT4 attr_int4; + CCTK_INT4 itmp; /* there is nothing to do for a serial run */ if (CCTK_nProcs (GH) == 1) + { return; + } /* get the dimension of the variable */ vdim = CCTK_GroupDimFromVarI (vindex); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "chunk_origin", FLEXIO_INT4, - vdim, &geom [0])); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "subchunk_lb", FLEXIO_INT4, - vdim, &geom [0])); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "global_size", FLEXIO_INT4, - vdim, &geom [2*vdim])); + FLEXIO_ERROR (IOwriteAttribute (file, "chunk_origin", FLEXIO_INT4, vdim, + &geom[0])); + FLEXIO_ERROR (IOwriteAttribute (file, "subchunk_lb", FLEXIO_INT4, vdim, + &geom[0])); + FLEXIO_ERROR (IOwriteAttribute (file, "global_size", FLEXIO_INT4, vdim, + &geom[2*vdim])); - attr_int4 = GH->cctk_iteration; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "chunk_dataset", FLEXIO_INT4, - 1, &attr_int4)); + itmp = GH->cctk_iteration; + FLEXIO_ERROR (IOwriteAttribute (file, "chunk_dataset", FLEXIO_INT4, 1,&itmp)); name = CCTK_FullName (vindex); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "name", FLEXIO_CHAR, - strlen (name)+1, name)); + FLEXIO_ERROR (IOwriteAttribute (file, "name", FLEXIO_CHAR, + strlen (name)+1, name)); free (name); - } /*@@ - @routine IOFlexIO_getDumpData - @author Paul Walker + @routine GetDumpData + @author Paul Walker @date Feb 1997 @desc Bounds and data to be output, takes into account downsampling @enddesc - @history + @history @hauthor Gabrielle Allen @hdate Oct 5 1998 @hdesc Made into subroutine - @endhistory + @endhistory @var GH @vdesc Identifies grid hierachy @vtype const cGH * @vio in - @vcomment - @endvar + @vcomment + @endvar @var vindex @vdesc index of the variable to dump @vtype int @vio in - @vcomment - @endvar + @vcomment + @endvar @var timelevel @vdesc timelevel of the variable to dump @vtype int @vio in - @vcomment - @endvar + @vcomment + @endvar @var outme @vdesc data segment to output @vtype void ** @vio out @vcomment This is just GF->data if there is no downsampling - @endvar + @endvar @var free_outme @vdesc Specifies whether or not to free the storage associated with outme @vtype int * @vio out @vcomment 1: free storage; 0: don't free storage - @endvar + @endvar @var geom @vdesc bounds, local size and global shape of the output - @vtype CCTK_INT4 [3*dim] + @vtype CCTK_INT4[3*dim] @vio out - @vcomment geom [0*dim..1*dim-1] lower bounds and geom[3],geom[4],geom[5] - geom [1*dim..2*dim-1] local size of data to send - geom [2*dim..3*dim-1] global shape - @endvar + @vcomment geom[0*dim..1*dim-1] lower bounds and geom[3],geom[4],geom[5] + geom[1*dim..2*dim-1] local size of data to send + geom[2*dim..3*dim-1] global shape + @endvar @var element_size @vdesc the size of an element of variable @vtype int @vio in @endvar @@*/ -static void IOFlexIO_getDumpData (const cGH *GH, int vindex, int timelevel, - void **outme, int *free_outme, CCTK_INT4 *geom, int element_size) +static int GetDumpData (const cGH *GH, int vindex, int timelevel, void **outme, + int *free_outme, CCTK_INT4 *geom, int element_size) { DECLARE_CCTK_PARAMETERS int i, myproc, do_downsample, dim; @@ -739,7 +760,7 @@ static void IOFlexIO_getDumpData (const cGH *GH, int vindex, int timelevel, myproc = CCTK_MyProc (GH); /* get GH extensions for IO */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; + ioUtilGH = (ioGH *) GH->extensions[CCTK_GHExtensionHandle ("IO")]; /* get the pGExtras pointer as a shortcut */ extras = ((pGA ***)PUGH_pGH (GH)->variables)[vindex][timelevel]->extras; @@ -749,7 +770,7 @@ static void IOFlexIO_getDumpData (const cGH *GH, int vindex, int timelevel, do_downsample = 0; for (i = 0; i < dim; i++) - do_downsample |= ioUtilGH->downsample [i] > 1; + do_downsample |= ioUtilGH->downsample[i] > 1; /* All the downsampling code is hard-coded for 3D data. For other-dimensional variables we print a warning @@ -769,84 +790,84 @@ static void IOFlexIO_getDumpData (const cGH *GH, int vindex, int timelevel, if (! do_downsample) { - if (ioUtilGH->out_single) + if (ioUtilGH->out_single) { single_ptr = (CCTK_REAL4 *) malloc (extras->npoints*sizeof (CCTK_REAL4)); for (i = 0; i < extras->npoints; i++) { - single_ptr [i] = (CCTK_REAL4) ((CCTK_REAL *) data) [i]; + single_ptr[i] = (CCTK_REAL4) ((CCTK_REAL *) data)[i]; } *outme = single_ptr; *free_outme = 1; - } - else + } + else { *outme = data; *free_outme = 0; } - for (i = 0; i < dim; i++) + for (i = 0; i < dim; i++) { - geom [i + 0*dim] = extras->lb [myproc][i];; /* the bounds */ - geom [i + 1*dim] = extras->lnsize [i]; /* the sizes */ - geom [i + 2*dim] = extras->nsize [i]; /* the global space */ + geom[i + 0*dim] = extras->lb[myproc][i];; /* the bounds */ + geom[i + 1*dim] = extras->lnsize[i]; /* the sizes */ + geom[i + 2*dim] = extras->nsize[i]; /* the global space */ } } else { /* NOTE: the following downsampling code is hard-coded for 3D data */ - int start [3], end [3]; + int start[3], end[3]; int j, k, l; /* Downsampling code ... */ for (i = 0; i < 3; i++) { - geom [i + 6] = extras->nsize [i] / ioUtilGH->downsample [i]; - if (extras->nsize [i] % ioUtilGH->downsample [i]) - geom [i + 6]++; + geom[i + 6] = extras->nsize[i] / ioUtilGH->downsample[i]; + if (extras->nsize[i] % ioUtilGH->downsample[i]) + geom[i + 6]++; } - if (verbose) + if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Downsampled sizes (%d, %d, %d) -> " "(%d, %d, %d)", - extras->nsize [0], extras->nsize [1], extras->nsize [2], - (int) geom [6], (int) geom [7], (int) geom [8]); - + extras->nsize[0], extras->nsize[1], extras->nsize[2], + (int) geom[6], (int) geom[7], (int) geom[8]); + /* Now figure out the local downsampling */ /* The local starts are the lb modded into the downsample */ for (i = 0; i < 3; i++) { - geom [i] = extras->lb [myproc][i] / ioUtilGH->downsample [i]; - start [i] = geom [i] * ioUtilGH->downsample [i]; - if (start [i] < - extras->lb [myproc][i] + extras->ownership [PUGH_NO_STAGGER][0][i]) { - start [i] += ioUtilGH->downsample [i]; - geom [i] ++; + geom[i] = extras->lb[myproc][i] / ioUtilGH->downsample[i]; + start[i] = geom[i] * ioUtilGH->downsample[i]; + if (start[i] < + extras->lb[myproc][i] + extras->ownership[PUGH_NO_STAGGER][0][i]) { + start[i] += ioUtilGH->downsample[i]; + geom[i] ++; } - end [i] = ((extras->lb [myproc][i] + - extras->ownership [PUGH_NO_STAGGER][1][i] - 1) / - ioUtilGH->downsample [i]) * ioUtilGH->downsample [i]; - geom [i+3] = (end [i] - start [i]) / ioUtilGH->downsample [i] + 1; + end[i] = ((extras->lb[myproc][i] + + extras->ownership[PUGH_NO_STAGGER][1][i] - 1) / + ioUtilGH->downsample[i]) * ioUtilGH->downsample[i]; + geom[i+3] = (end[i] - start[i]) / ioUtilGH->downsample[i] + 1; } if (verbose) { CCTK_VInfo (CCTK_THORNSTRING, "Downsample ranges (%d, %d, %d) -> " - "(%d, %d, %d)", start [0], start [1], start [2], - end [0], end [1], end [2]); + "(%d, %d, %d)", start[0], start[1], start[2], + end[0], end[1], end[2]); CCTK_VInfo (CCTK_THORNSTRING, "Local size/bound (%d, %d, %d) " "(%d, %d, %d)", - (int) geom [3], (int) geom [4], (int) geom [5], - (int) geom [0], (int) geom [1], (int) geom [2]); + (int) geom[3], (int) geom[4], (int) geom[5], + (int) geom[0], (int) geom[1], (int) geom[2]); } /* compute local ranges */ for (i = 0; i < 3; i++) { - start [i] -= extras->lb [myproc][i]; - end [i] -= extras->lb [myproc][i]; + start[i] -= extras->lb[myproc][i]; + end[i] -= extras->lb[myproc][i]; } - *outme = malloc (geom [3] * geom [4] * geom [5] * element_size); + *outme = malloc (geom[3] * geom[4] * geom[5] * element_size); *free_outme = 1; /* I hate it to repeat the loops for each case label @@ -855,18 +876,18 @@ static void IOFlexIO_getDumpData (const cGH *GH, int vindex, int timelevel, switch (CCTK_VarTypeI (vindex)) { case CCTK_VARIABLE_CHAR: char_ptr = (CCTK_BYTE *) *outme; - for (k = start [2]; k <= end [2]; k += ioUtilGH->downsample [2]) - for (j = start [1]; j <= end [1]; j += ioUtilGH->downsample [1]) - for (i = start [0]; i <= end [0]; i += ioUtilGH->downsample [0]) - char_ptr [l++] = ((CCTK_BYTE *) data) [DATINDEX (extras, i, j, k)]; + for (k = start[2]; k <= end[2]; k += ioUtilGH->downsample[2]) + for (j = start[1]; j <= end[1]; j += ioUtilGH->downsample[1]) + for (i = start[0]; i <= end[0]; i += ioUtilGH->downsample[0]) + char_ptr[l++] = ((CCTK_BYTE *) data)[DATINDEX (extras, i, j, k)]; break; case CCTK_VARIABLE_INT: int_ptr = (CCTK_INT *) *outme; - for (k = start [2]; k <= end [2]; k += ioUtilGH->downsample [2]) - for (j = start [1]; j <= end [1]; j += ioUtilGH->downsample [1]) - for (i = start [0]; i <= end [0]; i += ioUtilGH->downsample [0]) - int_ptr [l++] = ((CCTK_INT *) data) [DATINDEX (extras, i, j, k)]; + for (k = start[2]; k <= end[2]; k += ioUtilGH->downsample[2]) + for (j = start[1]; j <= end[1]; j += ioUtilGH->downsample[1]) + for (i = start[0]; i <= end[0]; i += ioUtilGH->downsample[0]) + int_ptr[l++] = ((CCTK_INT *) data)[DATINDEX (extras, i, j, k)]; break; case CCTK_VARIABLE_REAL: @@ -874,15 +895,15 @@ static void IOFlexIO_getDumpData (const cGH *GH, int vindex, int timelevel, single_ptr = (CCTK_REAL4 *) *outme; else real_ptr = (CCTK_REAL *) *outme; - for (k = start [2]; k <= end [2]; k += ioUtilGH->downsample [2]) - for (j = start [1]; j <= end [1]; j += ioUtilGH->downsample [1]) - for (i = start [0]; i <= end [0]; i += ioUtilGH->downsample [0]) + for (k = start[2]; k <= end[2]; k += ioUtilGH->downsample[2]) + for (j = start[1]; j <= end[1]; j += ioUtilGH->downsample[1]) + for (i = start[0]; i <= end[0]; i += ioUtilGH->downsample[0]) if (ioUtilGH->out_single) - single_ptr [l++] = (CCTK_REAL4) - (((CCTK_REAL *) data) [DATINDEX (extras, i, j, k)]); + single_ptr[l++] = (CCTK_REAL4) + (((CCTK_REAL *) data)[DATINDEX (extras, i, j, k)]); else - real_ptr [l++] = - ((CCTK_REAL *) data) [DATINDEX (extras, i, j, k)]; + real_ptr[l++] = + ((CCTK_REAL *) data)[DATINDEX (extras, i, j, k)]; break; #if 0 @@ -892,57 +913,60 @@ static void IOFlexIO_getDumpData (const cGH *GH, int vindex, int timelevel, single_ptr = (CCTK_REAL4 *) *outme; else cmplx_ptr = (CCTK_COMPLEX *) *outme; - for (k = start [2]; k <= end [2]; k += ioUtilGH->downsample [2]) - for (j = start [1]; j <= end [1]; j += ioUtilGH->downsample [1]) - for (i = start [0]; i <= end [0]; i += ioUtilGH->downsample [0]) + for (k = start[2]; k <= end[2]; k += ioUtilGH->downsample[2]) + for (j = start[1]; j <= end[1]; j += ioUtilGH->downsample[1]) + for (i = start[0]; i <= end[0]; i += ioUtilGH->downsample[0]) if (ioUtilGH->out_single) { - single_ptr [l++] = (CCTK_REAL4) - (((CCTK_REAL *) data) [0 + DATINDEX (extras, i, j, k)]); - single_ptr [l++] = (CCTK_REAL4) - (((CCTK_REAL *) data) [1 + DATINDEX (extras, i, j, k)]); + single_ptr[l++] = (CCTK_REAL4) + (((CCTK_REAL *) data)[0 + DATINDEX (extras, i, j, k)]); + single_ptr[l++] = (CCTK_REAL4) + (((CCTK_REAL *) data)[1 + DATINDEX (extras, i, j, k)]); } else - cmplx_ptr [l++] = - ((CCTK_COMPLEX *) data) [DATINDEX (extras, i, j, k)]; + cmplx_ptr[l++] = + ((CCTK_COMPLEX *) data)[DATINDEX (extras, i, j, k)]; break; #endif default: - CCTK_WARN (1, "Unsupported variable type in IOFlexIO_getDumpData"); - return; + CCTK_WARN (1, "Unsupported variable type in GetDumpData"); + return (-1); } } #ifdef IOFLEXIO_DEBUG - printf ("Lower bound: %d", (int) geom [0]); + printf ("Lower bound: %d", (int) geom[0]); for (i = 1; i < dim; i++) - printf (" %d", (int) geom [i]); + printf (" %d", (int) geom[i]); printf ("\n"); - printf ("Chunk size : %d", (int) geom [1*dim + 0]); + printf ("Chunk size : %d", (int) geom[1*dim + 0]); for (i = 1; i < dim; i++) - printf (" %d", (int) geom [1*dim + i]); + printf (" %d", (int) geom[1*dim + i]); printf ("\n"); - printf ("Global size: %d", (int) geom [2*dim + 0]); + printf ("Global size: %d", (int) geom[2*dim + 0]); for (i = 1; i < dim; i++) - printf (" %d", (int) geom [2*dim + i]); + printf (" %d", (int) geom[2*dim + i]); printf ("\n"); #endif + + return (0); } /*@@ - @routine IOFlexIO_eachProcDump - @author Paul Walker - @date Feb 1997 + @routine EachProcDump + @author Paul Walker + @date Feb 1997 @desc - Dump data from each processor + Dump data from each processor @enddesc - @history - @hauthor Gabrielle Allen @hdate Oct 5 1998 - @hdesc Made into subroutine - @endhistory + @history + @hauthor Gabrielle Allen + @hdate Oct 5 1998 + @hdesc Made into subroutine + @endhistory @@*/ -static void IOFlexIO_eachProcDump (const cGH *GH, int vindex, int timelevel, - void *outme, CCTK_INT4 *geom, IOFile iof, int flexio_type) +static void EachProcDump (const cGH *GH, int vindex, int timelevel, void *outme, + CCTK_INT4 *geom, IOFile file, int flexio_type) { int i, dim, *chunk_dims; @@ -952,68 +976,71 @@ static void IOFlexIO_eachProcDump (const cGH *GH, int vindex, int timelevel, chunk_dims = (int *) malloc (dim * sizeof (int)); - /* So set up the local shape. */ + /* set up the local shape */ for (i = 0; i < dim; i++) - chunk_dims [i] = geom [dim + i]; + { + chunk_dims[i] = geom[dim + i]; + } - /* Dump the data */ - CACTUS_IEEEIO_ERROR (IOwrite (iof, flexio_type, dim, chunk_dims, outme)); - - /* Add attributes for global space */ - IOFlexIO_AddCommonAttributes (GH, vindex, timelevel, &geom [2*dim], iof); - - /* Add chunk attributes */ - IOFlexIO_AddChunkAttributes (GH, vindex, geom, iof); + /* dump the data */ + FLEXIO_ERROR (IOwrite (file, flexio_type, dim, chunk_dims, outme)); + + /* add attributes for global space */ + AddCommonAttributes (GH, vindex, timelevel, &geom[2*dim], file); + + /* add chunk attributes */ + AddChunkAttributes (GH, vindex, geom, file); free (chunk_dims); } /*@@ - @routine IOFlexIO_procDump - @author Paul Walker - @date Feb 1997 + @routine ProcDump + @author Paul Walker + @date Feb 1997 @desc - Dump data + Dump data @enddesc - @history - @hauthor Gabrielle Allen @hdate Oct 5 1998 - @hdesc Made into subroutine - @endhistory + @history + @hauthor Gabrielle Allen + @hdate Oct 5 1998 + @hdesc Made into subroutine + @endhistory @@*/ #ifdef CCTK_MPI -static void IOFlexIO_procDump (IOFile iof, const cGH *GH, int vindex, void *outme, - CCTK_INT4 *geom, int flexio_type) +static void ProcDump (IOFile file, const cGH *GH, int vindex, void *outme, + CCTK_INT4 *geom, int flexio_type) { ioGH *ioUtilGH; - int i, dim, *chunk_dims, *chunk_origin; /* Chunk dim and origin */ + int i, dim, *chunk_dims, *chunk_origin; - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); /* get the dimension of the variable */ dim = CCTK_GroupDimI (CCTK_GroupIndexFromVarI (vindex)); chunk_origin = (int *) malloc (2*dim * sizeof (int)); chunk_dims = chunk_origin + dim; - for (i = 0; i < dim; i++) { - chunk_origin [i] = geom [i]; - chunk_dims [i] = geom [dim + i]; + for (i = 0; i < dim; i++) + { + chunk_origin[i] = geom[i]; + chunk_dims[i] = geom[dim + i]; } - if (ioUtilGH->unchunked) { - - /* Unchunked data */ - CACTUS_IEEEIO_ERROR (IOwriteChunk (iof, chunk_dims, chunk_origin, outme)); - - } else { - - /* Chunked data */ - CACTUS_IEEEIO_ERROR (IOwrite (iof, flexio_type, dim, chunk_dims, outme)); - - /* Write chunk attributes */ - IOFlexIO_AddChunkAttributes (GH, vindex, geom, iof); + if (ioUtilGH->unchunked) + { + /* unchunked data */ + FLEXIO_ERROR (IOwriteChunk (file, chunk_dims, chunk_origin, outme)); + } + else + { + /* uhunked data */ + FLEXIO_ERROR (IOwrite (file, flexio_type, dim, chunk_dims, outme)); + /* write chunk attributes */ + AddChunkAttributes (GH, vindex, geom, file); } free (chunk_origin); diff --git a/src/GHExtension.c b/src/GHExtension.c deleted file mode 100644 index de25a97..0000000 --- a/src/GHExtension.c +++ /dev/null @@ -1,328 +0,0 @@ - /*@@ - @file GHExtension.c - @date Fri May 21 1999 - @author Thomas Radke - @desc - IOFlexIO GH extension stuff. - @enddesc - @history - @hauthor Thomas Radke @hdate May 21 1999 - @hdesc Just copied from thorn IO. - @endhistory - @@*/ - -/*#define DEBUG_IO*/ - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> - -#include "cctk.h" -#include "cctk_Parameters.h" -#include "CactusPUGH/PUGH/src/include/pugh.h" -#include "CactusBase/IOUtil/src/ioGH.h" -#include "CactusBase/IOUtil/src/ioutil_Utils.h" -#include "ioFlexGH.h" - -static const char *rcsid = "$Header$"; - -CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_GHExtension_c) - -/* prototypes of routines defined in this source file */ -void *IOFlexIO_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH); -int IOFlexIO_InitGH (cGH *GH); -int IOFlexIO_TerminateGH (cGH *GH); - - - /*@@ - @routine IOFlexIO_SetupGH - @date Tue May 09 2000 - @author Thomas Radke - @desc - Allocates the IOFlexIO GH extension structure. - @enddesc - @calledby CCTK scheduler at CCTK_INITIALIZE - @var config - @vdesc flesh configuration structure (unused) - @vtype tFleshConfig * - @vio in - @endvar - @var convergence_level - @vdesc convergence level (unused) - @vtype int - @vio in - @endvar - @var GH - @vdesc pointer to grid hierarchy - @vtype cGH * - @vio in - @endvar - @history - - @endhistory -@@*/ -void *IOFlexIO_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH) -{ - DECLARE_CCTK_PARAMETERS - int i; - int maxdim; - int numvars; - flexioGH *newGH; - - - /* prevent compiler warnings about unused parameters */ - config = config; - convergence_level = convergence_level; - GH = GH; - - maxdim = CCTK_MaxDim(); - - numvars = CCTK_NumVars (); - - newGH = (flexioGH *) malloc (sizeof (flexioGH)); - newGH->do_out2D = (char *) malloc (numvars * sizeof (char)); - newGH->do_out3D = (char *) malloc (numvars * sizeof (char)); - newGH->out2D_last = (int *) malloc (numvars * sizeof (int)); - newGH->out3D_last = (int *) malloc (numvars * sizeof (int)); - newGH->sp2xyz = (int **) malloc(maxdim * sizeof (int *)); - for (i=0;i<maxdim;i++) - { - newGH->sp2xyz[i] = (int *) malloc(3 * sizeof (int )); - } - - return (newGH); -} - - - /*@@ - @routine IOFlexIO_InitGH - @date Tue May 09 2000 - @author Thomas Radke - @desc - The GH initialization routine for IOFlexIO. - Necessary output dirs are created. - For 2D output the slice center is set up. - Checkpoint/recovery timers are created if timing information was requested. - @enddesc - @calledby CCTK scheduler at CCTK_INITIALIZE - @var GH - @vdesc pointer to grid hierarchy - @vtype cGH * - @vio in - @endvar - @history - - @endhistory -@@*/ -int IOFlexIO_InitGH (cGH *GH) -{ - DECLARE_CCTK_PARAMETERS - int i; - ioGH *ioUtilGH; - flexioGH *myGH; - const char *timer_names[4] = {"IOFlexIO time to dump parameters", - "IOFlexIO time to dump datasets", - "IOFlexIO total time to checkpoint", - "IOFlexIO time to recover"}; - - - /* get the handles for IOUtil and IOFlexIO extensions */ - ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); - myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); - - /* How often to output */ - myGH->out2D_every = out_every > 0 ? out_every : -1; - myGH->out3D_every = out_every > 0 ? out_every : -1; - if (out2D_every > 0) - { - myGH->out2D_every = out2D_every; - } - if (out3D_every > 0) - { - myGH->out3D_every = out3D_every; - } - - /* Check whether "outdir2D" and/or "outdir3D" was set. - If so take these dirs otherwise default to "IO::outdir" */ - if (CCTK_ParameterQueryTimesSet ("outdir2D", CCTK_THORNSTRING) > 0) - { - myGH->outdir2D = strdup (outdir2D); - } - else - { - myGH->outdir2D = strdup (outdir); - } - - if (CCTK_ParameterQueryTimesSet ("outdir3D", CCTK_THORNSTRING) > 0) - { - myGH->outdir3D = strdup (outdir3D); - } - else - { - myGH->outdir3D = strdup (outdir); - } - - /* Create the output directories */ - i = IOUtil_CreateDirectory (GH, myGH->outdir2D, - ! CCTK_Equals (out3D_mode, "onefile"), - ioUtilGH->ioproc); - if (i < 0) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOFlexIO_InitGH: problem creating IOFlexIO 2D output" - " directory '%s'", myGH->outdir2D); - } - else if (i > 0 && CCTK_Equals (newverbose, "full")) - { - CCTK_VInfo (CCTK_THORNSTRING, - "IOFlexIO_InitGH: 2D IOFlexIO output directory '%s' " - "already exists", myGH->outdir2D); - } - i = IOUtil_CreateDirectory (GH, myGH->outdir3D, - ! CCTK_Equals (out3D_mode, "onefile"), - ioUtilGH->ioproc); - if (i < 0) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOFlexIO_InitGH: Problem creating IOFlexIO 3D output" - " directory '%s'", myGH->outdir3D); - } - else if (i > 0 && CCTK_Equals (newverbose, "full")) - { - CCTK_VInfo (CCTK_THORNSTRING, - "IOFlexIO_InitGH: 3D IOFlexIO output directory '%s' " - "already exists", myGH->outdir3D); - } - - for (i = CCTK_NumVars () - 1; i >= 0; i--) - { - myGH->out2D_last[i] = myGH->out3D_last[i] = -1; - } - - myGH->fileList_2D = myGH->fileList_3D = NULL; - - /* create timers if timing info was requested */ - myGH->print_timing_info = print_timing_info; - if (myGH->print_timing_info) - { - for (i = 0; i < 4; i++) - { - if ((myGH->timers[i] = CCTK_TimerCreate (timer_names[i])) < 0) - break; - } - if (i != 4) - { - CCTK_WARN (1, "Could not create timers for checkpoint/recovery ! " - "No timer information will be available."); - while (--i >= 0) - { - CCTK_TimerDestroyI (myGH->timers[i]); - } - myGH->print_timing_info = 0; - } - else - { - CCTK_TimerResetI (myGH->timers[2]); - CCTK_TimerResetI (myGH->timers[3]); - } - } - - return (0); -} - - - /*@@ - @routine IOFlexIO_TerminateGH - @date Tue May 09 2000 - @author Thomas Radke - @desc - The termination routine for IOFlexIO. - All open files (stored in the file lists) are closed, - and the file lists are freed. - Also any created timers are destroyed. - @enddesc - @calledby CCTK scheduler at TERMINATE - @var GH - @vdesc pointer to grid hierarchy - @vtype cGH * - @vio in - @endvar - @history - - @endhistory -@@*/ -int IOFlexIO_TerminateGH (cGH *GH) -{ - DECLARE_CCTK_PARAMETERS - flexioGH *myGH; - int i, handle; - pNamedData *current; - IOFile *IEEEfiles_2D; - IEEEfile_3D_t *IEEEfile_3D; - - - /* Get the handle for IOFlexIO extensions */ - handle = CCTK_GHExtensionHandle ("IOFlexIO"); - myGH = handle >= 0 ? (flexioGH *) GH->extensions [handle] : NULL; - - /* immediately return if IOFlexIO wasn't active */ - if (! myGH) - { - return (0); - } - - /* close any open files by walking through the file lists */ - current = myGH->fileList_2D; - while (current) - { - IEEEfiles_2D = (IOFile *) current->data; - if (verbose) - { - CCTK_VInfo (CCTK_THORNSTRING, "Closing 2D IEEEIO output files " - "for variable alias '%s'", current->name); - } - CACTUS_IEEEIO_ERROR (IOclose (IEEEfiles_2D [0])); - CACTUS_IEEEIO_ERROR (IOclose (IEEEfiles_2D [1])); - CACTUS_IEEEIO_ERROR (IOclose (IEEEfiles_2D [2])); - free (IEEEfiles_2D); - - current = current->next; - } - - current = myGH->fileList_3D; - while (current) - { - IEEEfile_3D = (IEEEfile_3D_t *) current->data; - if (IEEEfile_3D->iofile) - { - if (verbose) - { - CCTK_VInfo (CCTK_THORNSTRING, "Closing IEEEIO output file '%s'", - IEEEfile_3D->filename); - } - IOclose (IEEEfile_3D->iofile); - } - free (IEEEfile_3D->filename); - free (IEEEfile_3D); - - current = current->next; - } - - /* free the file lists */ - DestroyNamedDataList (myGH->fileList_2D); - DestroyNamedDataList (myGH->fileList_3D); - - if (myGH->print_timing_info) - { - for (i = 0; i < 4; i++) - { - CCTK_TimerDestroyI (myGH->timers[i]); - } - } - - /* finally unregister and free my GH extension structure */ - CCTK_UnregisterGHExtension ("IOFlexIO"); - free (myGH); - - return (0); -} diff --git a/src/Output.c b/src/Output.c new file mode 100644 index 0000000..dbc3fa8 --- /dev/null +++ b/src/Output.c @@ -0,0 +1,366 @@ + /*@@ + @file Output.c + @date Tue Jan 9 1999 + @author Gabrielle Allen + @desc + Functions to deal with IOFlexIO output of grid variables + @enddesc + @version $Id$ + @@*/ + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include "cctk.h" +#include "cctk_Parameters.h" +#include "ioFlexGH.h" + +/* the rcs ID and its dummy function to use it */ +static const char *rcsid = "$Header$"; +CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_Output_c) + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static int CheckOutputVar (int vindex); +static void CheckSteerableParameters (flexioGH *myGH); +static void SetOutputFlag (int vindex, const char *optstring, void *arg); + + +/*@@ + @routine IOFlexIO_OutputGH + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Loops over all variables and outputs them if necessary + @enddesc + + @calls IOFlexIO_TimeFor + IOFlexIO_OutputVarAs + + @var GH + @vdesc Pointer to CCTK GH + @vtype const cGH * + @vio in + @endvar + + @returntype int + @returndesc + the number of variables which were output at this iteration + (or 0 if it wasn't time to output yet) + @endreturndesc +@@*/ +int IOFlexIO_OutputGH (const cGH *GH) +{ + int vindex, retval; + flexioGH *myGH; + char *fullname; + const char *name; + DECLARE_CCTK_PARAMETERS + + + /* get the GH extension for IOFlexIO */ + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); + + CheckSteerableParameters (myGH); + + if (myGH->out_every <= 0) + { + return (0); + } + + /* loop over all variables */ + for (vindex = retval = 0; vindex < CCTK_NumVars (); vindex++) + { + if (IOFlexIO_TimeFor (GH, vindex)) + { + name = CCTK_VarName (vindex); + fullname = CCTK_FullName (vindex); + + if (verbose) + { + CCTK_VInfo (CCTK_THORNSTRING, "IOFlexIO_OutputGH: " + "(fullname, name) = (%s, %s)", fullname, name); + } + + if (IOFlexIO_OutputVarAs (GH, fullname, name) == 0) + { + /* Register variables as having output this iteration */ + myGH->out_last[vindex] = GH->cctk_iteration; + retval++; + } + + free (fullname); + } + } + + return (retval); +} + + +/*@@ + @routine IOFlexIO_OutputVarAs + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Unconditional output of a variable using the IOFlexIO I/O method. + @enddesc + + @calls IOFlexIO_Write + + @var GH + @vdesc Pointer to CCTK GH + @vtype const cGH * + @vio in + @endvar + @var fullname + @vdesc complete name of variable to output + @vtype const char * + @vio in + @endvar + @var alias + @vdesc alias name of variable to output + (used to generate output filename) + @vtype const char * + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine IOFlexIO_Write + @endreturndesc +@@*/ +int IOFlexIO_OutputVarAs (const cGH *GH, const char *fullname, const char*alias) +{ + int vindex, retval; + DECLARE_CCTK_PARAMETERS + + + vindex = CCTK_VarIndex (fullname); + + if (verbose) + { + CCTK_VInfo (CCTK_THORNSTRING, "IOFlexIO_OutputVarAs: (fullname, alias, " + "index) = (%s, %s, %d)", fullname, alias, vindex); + } + + /* do the output */ + retval = IOFlexIO_Write (GH, vindex, alias); + + return (retval); +} + + +/*@@ + @routine IOFlexIO_TimeFor + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Decides if it is time to output a variable + using the IOFlexIO I/O method. + @enddesc + + @calls CheckSteerableParameters + + @var GH + @vdesc Pointer to CCTK GH + @vtype const cGH * + @vio in + @endvar + @var vindex + @vdesc index of variable + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + 1 if output should take place at this iteration, or<BR> + 0 if not + @endreturndesc +@@*/ +int IOFlexIO_TimeFor (const cGH *GH, int vindex) +{ + int retval; + flexioGH *myGH; + char *fullname; + + + /* get the GH extension for IOFlexIO */ + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); + + CheckSteerableParameters (myGH); + + /* check if this variable should be output */ + retval = myGH->out_every > 0 && myGH->do_out[vindex] && + GH->cctk_iteration % myGH->out_every == 0; + if (retval) + { + /* check if variable was not already output this iteration */ + if (myGH->out_last[vindex] == GH->cctk_iteration) + { + fullname = CCTK_FullName (vindex); + CCTK_VWarn (6, __LINE__, __FILE__, CCTK_THORNSTRING, + "Already done IOFlexIO output for variable '%s' in current " + "iteration (probably via triggers)", fullname); + free (fullname); + retval = 0; + } + } + + return (retval); +} + + +/*@@ + @routine IOFlexIO_TriggerOutput + @date Sat March 6 1999 + @author Gabrielle Allen + @desc + Triggers the output a variable using the IOFlexIO I/O method. + method + + @calls IOFlexIO_Write + + @var GH + @vdesc Pointer to CCTK GH + @vtype const cGH * + @vio in + @endvar + @var vindex + @vdesc index of variable + @vtype int + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine IOFlexIO_Write + @endreturndesc +@@*/ +int IOFlexIO_TriggerOutput (const cGH *GH, int vindex) +{ + int retval; + flexioGH *myGH; + const char *varname; + DECLARE_CCTK_PARAMETERS + + + varname = CCTK_VarName (vindex); + + /* get the GH extension for IOFlexIO */ + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); + + if (verbose) + CCTK_VInfo (CCTK_THORNSTRING, "IOFlexIO_TriggerOutput: " + "name, index = %s, %d", varname, vindex); + + /* do the output */ + retval = IOFlexIO_Write (GH, vindex, varname); + + if (retval == 0) + { + /* register variable as having output this iteration */ + myGH->out_last[vindex] = GH->cctk_iteration; + } + + return (retval); +} + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +/*@@ + @routine CheckSteerableParameters + @date Mon Oct 10 2000 + @author Thomas Radke + @desc + Checks if IOFlexIO steerable parameters were changed + and does appropriate re-evaluation. + @enddesc + + @calls CCTK_TraverseString + + @var myGH + @vdesc Pointer to IOFlexIO GH + @vtype flexioGH * + @vio in + @endvar +@@*/ +static void CheckSteerableParameters (flexioGH *myGH) +{ + int times_set; + static int out_vars_lastset = -1; + DECLARE_CCTK_PARAMETERS + + + /* How often to output */ + myGH->out_every = out_every > 0 ? out_every : -1; + if (out3D_every > 0) + { + myGH->out_every = out3D_every; + } + + /* re-parse the 'out3D_vars' parameter if it was changed */ + times_set = CCTK_ParameterQueryTimesSet ("out3D_vars", CCTK_THORNSTRING); + if (times_set != out_vars_lastset) + { + memset (myGH->do_out, 0, CCTK_NumVars ()); + CCTK_TraverseString (out3D_vars, SetOutputFlag, myGH->do_out, + CCTK_GROUP_OR_VAR); + + /* Save the last setting of 'out3D_vars' parameter */ + out_vars_lastset = times_set; + } +} + + +/* check if this variable can be output (static conditions) */ +static int CheckOutputVar (int vindex) +{ + int retval; + char *fullname; + + +/*** FIXME: IEEEIO doesn't provide a COMPLEX datatype + so we should map CCTK_COMPLEX to two REALs here. + We have to check for this already here because if an IEEEIO file + is created and nothing is written to it, it will crash + at re-opening. ***/ + retval = strncmp (CCTK_VarTypeName (CCTK_VarTypeI (vindex)), + "CCTK_VARIABLE_COMPLEX", 21); + if (! retval) + { + fullname = CCTK_FullName (vindex); + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOFlexIO output for complex variable '%s' not yet " + "supported", fullname); + free (fullname); + } + + return (! retval); +} + + +/* callback for CCTK_TraverseString() to set the output flag + for the given variable */ +static void SetOutputFlag (int vindex, const char *optstring, void *arg) +{ + char *flags = (char *) arg; + + + /* Check the variable type */ + if (CheckOutputVar (vindex) == 0) + { + flags[vindex] = 1; + } + + if (optstring) + { + CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, + "Optional string '%s' in variable name ignored", optstring); + } +} diff --git a/src/Output3D.c b/src/Output3D.c deleted file mode 100644 index f3b6431..0000000 --- a/src/Output3D.c +++ /dev/null @@ -1,334 +0,0 @@ - /*@@ - @file Output3D.c - @date Tue Jan 9 1999 - @author Gabrielle Allen - @desc - Functions to deal 3D output of variables - @enddesc - @history - @hauthor Thomas Radke @hdate 16 Mar 1999 - @hdesc Converted to Cactus 4.0 - @hendhistory - @@*/ - -#include <stdio.h> -#include <assert.h> -#include <stdlib.h> -#include <string.h> - -#include "cctk.h" -#include "cctk_Parameters.h" -#include "ioFlexGH.h" - -static const char *rcsid = "$Header$"; - -CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_Output3D_c) - -/* function prototypes */ -int IOFlexIO_Output3DVarAs (const cGH *GH, const char *var, const char *alias); -int IOFlexIO_TimeFor3D (const cGH *GH, int vindex); -static int CheckOutputVar (int vindex); -static void CheckSteerableParameters (flexioGH *myGH); -static void SetOutputFlag (int vindex, const char *optstring, void *arg); - - -/*@@ - @routine IOFlexIO_Output3DGH - @date Sat March 6 1999 - @author Gabrielle Allen - @desc - Loops over all variables and outputs them if necessary - @enddesc - @calledby CCTK_OutputGH ("IOFlexIO_3D") - @history - - @endhistory - @var GH - @vdesc Pointer to CCTK GH - @vtype const cGH * - @vio in - @vcomment - @endvar -@@*/ - -int IOFlexIO_Output3DGH (const cGH *GH) -{ - DECLARE_CCTK_PARAMETERS - int i, retval; - flexioGH *myGH; - const char *name; - char *fullname; - - - /* Get the GH extension for IOFlexIO */ - myGH = (flexioGH *) GH->extensions [CCTK_GHExtensionHandle ("IOFlexIO")]; - - CheckSteerableParameters (myGH); - - if (myGH->out3D_every <= 0) - return (0); - - /* Loop over all variables */ - for (i = retval = 0; i < CCTK_NumVars (); i++) { - if (IOFlexIO_TimeFor3D (GH, i)) { - name = CCTK_VarName (i); - fullname = CCTK_FullName (i); - - if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "IOFlexIO_Output3DGH: " - "(fullname, name) = (%s, %s)", fullname, name); - - if (IOFlexIO_Output3DVarAs (GH, fullname, name) == 0) - { - /* Register variables as having 3D output this iteration */ - myGH->out3D_last [i] = GH->cctk_iteration; - retval++; - } - - free (fullname); - } - } - - return (retval); -} - - -/*@@ - @routine IOFlexIO_Output3DVarAs - @date Sat March 6 1999 - @author Gabrielle Allen - @desc - unconditional output of a variable using the IOFlexIO 3D output method - @enddesc - @calledby IOFlexIO_Output3DGH, CCTK_OutputVarAsByMethod ("IOFlexIO_3D") - @history - - @endhistory - @var GH - @vdesc Pointer to CCTK GH - @vtype const cGH * - @vio in - @vcomment - @endvar - @var fullname - @vdesc complete name of variable to output - @vtype const char * - @vio in - @vcomment - @endvar - @var alias - @vdesc alias name of variable to output (used to generate output filename) - @vtype const char * - @vio in - @vcomment - @endvar -@@*/ -int IOFlexIO_Output3DVarAs (const cGH *GH, const char *fullname, const char *alias) -{ - int vindex, retval; - DECLARE_CCTK_PARAMETERS - - - vindex = CCTK_VarIndex (fullname); - - if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "IOFlexIO_Output3DVarAs: " - "(fullname, alias, index) = (%s, %s, %d)", fullname, alias,vindex); - - /* Do the 3D output */ - retval = IOFlexIO_Write3D (GH, vindex, alias); - - return (retval); -} - - -/*@@ - @routine IOFlexIO_TimeFor3D - @date Sat March 6 1999 - @author Gabrielle Allen - @desc - Decides if it is time to output a variable using the IOFlexIO 3D output - method - @enddesc - @calledby IOFlexIO_Output3DGH - @history - - @endhistory - @var GH - @vdesc Pointer to CCTK GH - @vtype const cGH * - @vio in - @vcomment - @endvar - @var vindex - @vdesc index of variable - @vtype int - @vio in - @vcomment - @endvar -@@*/ -int IOFlexIO_TimeFor3D (const cGH *GH, int vindex) -{ - flexioGH *myGH; - - - /* Get the GH extension for IOFlexIO */ - myGH = (flexioGH *) GH->extensions [CCTK_GHExtensionHandle ("IOFlexIO")]; - - CheckSteerableParameters (myGH); - - /* Check if any output was requested */ - if (myGH->out3D_every <= 0) - return (0); - - /* Check this var should be output */ - if (! (myGH->do_out3D [vindex] && GH->cctk_iteration % myGH->out3D_every == 0)) - return (0); - - /* Check var not already output this iteration */ - if (myGH->out3D_last [vindex] == GH->cctk_iteration) - { - char *fullname = CCTK_FullName (vindex); - - - CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, - "Already done FlexIO output for variable '%s' in current " - "iteration (probably via triggers)", fullname); - free (fullname); - return (0); - } - - return (1); -} - - -/*@@ - @routine IOFlexIO_TriggerOutput3D - @date Sat March 6 1999 - @author Gabrielle Allen - @desc - Triggers the output a variable using the IOFlexIO 3D output - method - @enddesc - @calledby CCTK scheduler - @history - - @endhistory - @var GH - @vdesc Pointer to CCTK GH - @vtype const cGH * - @vio in - @vcomment - @endvar - @var vindex - @vdesc index of variable to output - @vtype int - @vio in - @vcomment - @endvar -@@*/ -int IOFlexIO_TriggerOutput3D (const cGH *GH, int vindex) -{ - int retval; - flexioGH *myGH; - const char *varname; - DECLARE_CCTK_PARAMETERS - - - varname = CCTK_VarName (vindex); - - /* Get the GH extension for IOFlexIO */ - myGH = (flexioGH *) GH->extensions [CCTK_GHExtensionHandle ("IOFlexIO")]; - - if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "IOFlexIO_TriggerOutput3D: " - "name, index = %s, %d", varname, vindex); - - /* Do the 3D output */ - retval = IOFlexIO_Write3D (GH, vindex, varname); - - if (retval == 0) - { - /* Register var as having 3D output this iteration */ - myGH->out3D_last [vindex] = GH->cctk_iteration; - } - - return (retval); -} - - -/**************************** local functions ******************************/ -/* check if steerable parameters have changed */ -static void CheckSteerableParameters (flexioGH *myGH) -{ - int times_set; - static int out3D_vars_lastset = -1; - DECLARE_CCTK_PARAMETERS - - - /* How often to output */ - myGH->out3D_every = out_every > 0 ? out_every : -1; - if (out3D_every > 0) - myGH->out3D_every = out3D_every; - - /* re-parse the 'out3D_vars' parameter if it was changed */ - times_set = CCTK_ParameterQueryTimesSet ("out3D_vars", CCTK_THORNSTRING); - if (times_set != out3D_vars_lastset) - { - memset (myGH->do_out3D, 0, CCTK_NumVars ()); - CCTK_TraverseString (out3D_vars, SetOutputFlag, myGH->do_out3D, - CCTK_GROUP_OR_VAR); - - /* Save the last setting of 'out3D_vars' parameter */ - out3D_vars_lastset = times_set; - } - -} - - -/* check if this variable can be output (static conditions) */ -static int CheckOutputVar (int vindex) -{ - int retval; - char *fullname; - - -/*** FIXME: IEEEIO doesn't provide a COMPLEX datatype - so we should map CCTK_COMPLEX to two REALs here. - We have to check for this already here because if an IEEEIO file - is created and nothing is written to it, it will crash - at re-opening. ***/ - retval = strncmp (CCTK_VarTypeName (CCTK_VarTypeI (vindex)), - "CCTK_VARIABLE_COMPLEX", 21); - if (! retval) - { - fullname = CCTK_FullName (vindex); - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "IOFlexIO output for complex variable '%s' not yet " - "supported", fullname); - free (fullname); - } - - return (! retval); -} - - -/* callback for CCTK_TraverseString() to set the output flag - for the given variable */ -static void SetOutputFlag (int vindex, const char *optstring, void *arg) -{ - char *flags = (char *) arg; - - - /* Check the variable type */ - if (CheckOutputVar (vindex) == 0) - { - flags[vindex] = 1; - } - - if (optstring) - { - CCTK_VWarn (5, __LINE__, __FILE__, CCTK_THORNSTRING, - "Optional string '%s' in variable name ignored", optstring); - } -} diff --git a/src/RecoverGH.c b/src/RecoverGH.c index 5a1932e..53befd0 100644 --- a/src/RecoverGH.c +++ b/src/RecoverGH.c @@ -3,24 +3,15 @@ @date Fri Jun 19 09:14:22 1998 @author Tom Goodale @desc - Contains the routines to do the internal checkpoint recovery. - - Currently can recover from: - (1) One file containing recombined data - (2) Multiple unrecombined files, where the current - number of processors and outputing processors - match those used to write the data. + Routines to recover variables from a given IEEEIO data or + checkpoint file. @enddesc - @history - @hauthor Gabrielle Allen @hdate 19 Oct 1998 - @hdesc Changed names ready for thorn_IO - @endhistory - @version $Id$ + @version $Id$ @@*/ -#include <ctype.h> #include <stdio.h> +#include <string.h> #include <stdlib.h> #include "cctk.h" @@ -30,29 +21,30 @@ #include "ioFlexGH.h" /* the rcs ID and its dummy function to use it */ - static const char *rcsid = "$Id$"; CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_RecoverGH_c) - +/******************************************************************** + ******************** Macro Definitions ************************ + ********************************************************************/ /* maximum length of an attribute name */ #define MAX_ATTRNAME_LEN 256 -/* prototypes of routines defined in this source file */ -int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from); +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ int IOFlexIO_RecoverParameters (void); -static int IOFlexIOi_RecoverParameters (fileinfo_t *file); -static int IOFlexIOi_RecoverGHextensions (cGH *GH, - fileinfo_t *file); -static int IOFlexIOi_OpenFile (cGH *GH, - const char *basefilename, - int called_from, - fileinfo_t *file); -/* this one comes from RestoreFile.c */ -int IOFlexIOi_RecoverVariables (cGH *GH, - fileinfo_t *file); + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static int RecoverParameters (fileinfo_t *file); +static int RecoverGHextensions (cGH *GH, fileinfo_t *file); +static int OpenFile (cGH *GH, const char *basefilename, int called_from, + fileinfo_t *file); /*@@ @@ -61,15 +53,19 @@ int IOFlexIOi_RecoverVariables (cGH *GH, @author Tom Goodale @desc Recovers a GH from an IEEEIO file. - This routine is registered with IOUtil - as IOFlexIO's recovery routine. + This routine is registered with IOUtil as IOFlexIO's recovery + routine. @enddesc - @calledby IOUtil_RecoverFromFile - @history - @endhistory + + @calls OpenFile + RecoverParameters + RecoverGHextensions + IOFlexIOi_RecoverVariables + IOUtil_PrintTimings + @var GH @vdesc Pointer to CCTK grid hierarchy - @vtype cGH + @vtype cGH * @vio in @endvar @var basefilename @@ -84,31 +80,22 @@ int IOFlexIOi_RecoverVariables (cGH *GH, @vtype int @vio in @endvar + @returntype int @returndesc >0 = success -1 = recovery failed @endreturndesc - - @history - @hauthor Gabrielle Allen - @hdate Thu Jul 2 18:17:59 1998 - @hdesc Restore the physical time and iteration count, pass myproc to - IEEEIOparamRestore - Derives the filename from IOUtil_PrepareFilename (in thorn IOUtil) - @hauthor Gabrielle Allen @hdate Oct 17 1998 - @hdesc Added input of (some) GH structure variables - @endhistory - @@*/ - int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) { - DECLARE_CCTK_PARAMETERS int result; flexioGH *myGH; static fileinfo_t file; /* this is static because info is passed from CP_RECOVERY_PARAMETERS to CP_RECOVERY_DATA */ + const char *timer_description = "Time to recover:"; + DECLARE_CCTK_PARAMETERS + /* to make the compiler happy */ myGH = NULL; @@ -117,7 +104,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) /* start the total timer */ if (GH) { - myGH = (flexioGH *) GH->extensions[CCTK_GHExtensionHandle ("IOFlexIO")]; + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); if (myGH->print_timing_info) { CCTK_TimerStartI (myGH->timers[3]); @@ -130,7 +117,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) called_from == FILEREADER_DATA || (GH && (GH->cctk_levfac[0] > 1 || GH->cctk_convlevel > 0))) { - if (IOFlexIOi_OpenFile (GH, basefilename, called_from, &file) < 0) + if (OpenFile (GH, basefilename, called_from, &file) < 0) { return (-1); } @@ -149,7 +136,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) /* Recover parameters (and return) */ if (called_from == CP_RECOVER_PARAMETERS) { - return (IOFlexIOi_RecoverParameters (&file)); + return (RecoverParameters (&file)); } /* Recover GH extensions */ @@ -159,7 +146,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) { CCTK_INFO ("Recovering GH extensions"); } - result = IOFlexIOi_RecoverGHextensions (GH, &file); + result = RecoverGHextensions (GH, &file); } if (! result) @@ -189,7 +176,7 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) CCTK_VInfo (CCTK_THORNSTRING, "Closing data file '%s'", file.filename); } } - CACTUS_IEEEIO_ERROR (IOclose (file.fid)); + FLEXIO_ERROR (IOclose (file.fid)); if (called_from == CP_RECOVER_DATA && recover_and_remove) { @@ -209,9 +196,6 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) /* stop total recovery timer and print timing info */ if (called_from == CP_RECOVER_DATA && myGH->print_timing_info) { - const char *timer_description = "Time to recover:"; - - CCTK_TimerStopI (myGH->timers[3]); IOUtil_PrintTimings ("Timing information for recovery in IOFlexIO:", 1, &myGH->timers[3], &timer_description); @@ -250,10 +234,16 @@ int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from) not even a GH, because this doesn't exist yet at the time it is being called. @enddesc - @calledby flesh's scheduler - @history - @endhistory + @calls IOUtil_RecoverParameters + + @returntype int + @returndesc + return code of @seeroutine IOUtil_RecoverParameters, ie. + positive for successful parameter recovery, or<BR> + 0 if recovery wasn't requested, or<BR> + negative if parameter recovery failed + @endreturndesc @@*/ int IOFlexIO_RecoverParameters (void) { @@ -261,34 +251,21 @@ int IOFlexIO_RecoverParameters (void) } -/**************************** local routines ******************************/ - -static int IOFlexIOi_OpenFile (cGH *GH, - const char *basefilename, - int called_from, - fileinfo_t *file) +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static int OpenFile (cGH *GH, const char *basefilename, int called_from, + fileinfo_t *file) { - DECLARE_CCTK_PARAMETERS - int retval; - int vindex; - int nprocs, myproc; - Long nels_stored; - int nt_stored; - CCTK_INT4 tmpInt; + int i, myproc, nprocs, type, retval; + Long dim; #ifdef CCTK_MPI MPI_Comm comm; CCTK_INT4 info[4]; #endif + DECLARE_CCTK_PARAMETERS -#ifdef CCTK_MPI - /* Get the communicator for broadcasting the info structure */ - /* NOTE: When recovering parameters thorn PUGH is not yet initialized - so that we have to use MPI_COMM_WORLD in this case */ - comm = CCTK_GHExtensionHandle ("PUGH") < 0 ? - MPI_COMM_WORLD : PUGH_pGH (GH)->PUGH_COMM_WORLD; -#endif - /* identify myself */ nprocs = CCTK_nProcs (GH); myproc = CCTK_MyProc (GH); @@ -311,7 +288,6 @@ static int IOFlexIOi_OpenFile (cGH *GH, if (myproc == 0) { - if (verbose) { CCTK_VInfo (CCTK_THORNSTRING, "Opening file '%s'", file->filename); @@ -319,11 +295,8 @@ static int IOFlexIOi_OpenFile (cGH *GH, /* Open file, make sure the file is valid */ file->fid = IEEEopen (file->filename, "r"); - if (IOisValid (file->fid)) - { - file->is_IEEEIO_file = 1; - } - else + file->is_IEEEIO_file = IOisValid (file->fid); + if (! file->is_IEEEIO_file) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, "No valid IEEEIO file '%s' found", file->filename); @@ -345,19 +318,16 @@ static int IOFlexIOi_OpenFile (cGH *GH, } } - /* Okay, we have the complete filename. Let's read the file now. */ + /* okay, we have the complete filename. Let's read the file now. */ if (myproc == 0 && file->is_IEEEIO_file) { - file->is_IEEEIO_file = 0; - /* Determine how the data was written by reading the GH extensions */ - vindex = IOreadAttributeInfo (file->fid, "GH$ioproc_every", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + /* determine how the data was written by reading the GH extensions */ + i = IOreadAttributeInfo (file->fid, "GH$ioproc_every", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &tmpInt); - file->ioproc_every = tmpInt; + IOreadAttribute (file->fid, i, &file->ioproc_every); } else { @@ -366,13 +336,11 @@ static int IOFlexIOi_OpenFile (cGH *GH, file->ioproc_every = nprocs; } - /* Read nprocs used to write data */ - vindex = IOreadAttributeInfo (file->fid, "GH$nprocs", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + /* read nprocs used to write data */ + i = IOreadAttributeInfo (file->fid, "GH$nprocs", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &tmpInt); - file->nprocs = tmpInt; + IOreadAttribute (file->fid, i, &file->nprocs); } else { @@ -381,14 +349,12 @@ static int IOFlexIOi_OpenFile (cGH *GH, file->nprocs = 1; } - /* Determine whether data is chunked or unchunked + /* determine whether data is chunked or unchunked We could derive this from the filename itself but just to be sure ... */ - vindex = IOreadAttributeInfo (file->fid, "unchunked", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + i = IOreadAttributeInfo (file->fid, "unchunked", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &tmpInt); - file->unchunked = tmpInt; + IOreadAttribute (file->fid, i, &file->unchunked); } else { @@ -397,28 +363,21 @@ static int IOFlexIOi_OpenFile (cGH *GH, "and continuing", file->unchunked ? "true" : "false"); } - /* Determine whether data was written using the old timelevel naming + /* determine whether data was written using the old timelevel naming scheme. New files contain a Cactus version string attribute... */ - vindex = IOreadAttributeInfo (file->fid, "Cactus version", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_CHAR) - { - /* for now we don't actually need the Cactus version info */ - file->has_version = 1; - } - else + i = IOreadAttributeInfo (file->fid, "Cactus version", &type, &dim); + file->has_version = i >= 0 && type == FLEXIO_CHAR; + if (! file->has_version) { CCTK_WARN (4, "Unable to restore 'Cactus version' attribute. " "Assuming data was written using the the old timelevel " "naming scheme and continuing"); - file->has_version = 0; } /* If we recover from multiple files the number of * writing processors must match the number of reading * processors, and the total number of processors must match. */ - if ((file->ioproc_every == nprocs && nprocs > 1) || file->unchunked) { if (verbose) @@ -457,6 +416,12 @@ static int IOFlexIOi_OpenFile (cGH *GH, } #ifdef CCTK_MPI + /* Get the communicator for broadcasting the info structure */ + /* NOTE: When recovering parameters thorn PUGH is not yet initialized + so that we have to use MPI_COMM_WORLD in this case */ + comm = CCTK_GHExtensionHandle ("PUGH") < 0 ? + MPI_COMM_WORLD : PUGH_pGH (GH)->PUGH_COMM_WORLD; + /* Broadcast the file information to all processors */ info[0] = file->is_IEEEIO_file; info[1] = file->unchunked; @@ -471,7 +436,6 @@ static int IOFlexIOi_OpenFile (cGH *GH, if (file->is_IEEEIO_file) { - /* Determine the IO processors for each node and the corresponding checkpoint file */ file->ioproc = myproc - (myproc % file->ioproc_every); @@ -482,7 +446,6 @@ static int IOFlexIOi_OpenFile (cGH *GH, /* Open chunked files on other IO processors */ if (myproc == file->ioproc && myproc != 0) { - if (verbose) { CCTK_VInfo (CCTK_THORNSTRING, "Opening chunked file '%s' on " @@ -498,17 +461,19 @@ static int IOFlexIOi_OpenFile (cGH *GH, file->is_IEEEIO_file = 0; } } + #ifdef CCTK_MPI /* Finally check whether all files have valid recovery files */ info[0] = file->is_IEEEIO_file; - CACTUS_MPI_ERROR (MPI_Allreduce (&info[0], &info[1], 1, - PUGH_MPI_INT4, MPI_LAND, comm)); + CACTUS_MPI_ERROR (MPI_Allreduce (&info[0], &info[1], 1, PUGH_MPI_INT4, + MPI_LAND, comm)); file->is_IEEEIO_file = info[1]; #endif } /* Return 0 for success otherwise negative */ retval = (file->is_IEEEIO_file ? 0 : -1); + return (retval); } @@ -518,25 +483,24 @@ static int IOFlexIOi_OpenFile (cGH *GH, Broadcasting the GH extensions is found faster than sending it in a loop from each IO processor to all the non IOs (don't have subcommunicators yet) */ -static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) +static int RecoverGHextensions (cGH *GH, fileinfo_t *file) { - Long nels_stored; - int vindex, nt_stored; + Long dim; + int i, type; CCTK_REAL realBuffer; CCTK_INT4 int4Buffer[2]; + if (CCTK_MyProc (GH) == 0) { - /* rewind to the first dataset where the GH extensions are attached to */ - CACTUS_IEEEIO_ERROR (IOseek (file->fid, 0)); + FLEXIO_ERROR (IOseek (file->fid, 0)); - /* Get the iteration number. */ - vindex = IOreadAttributeInfo (file->fid, "GH$iteration", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + /* get the iteration number */ + i = IOreadAttributeInfo (file->fid, "GH$iteration", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &int4Buffer[0]); + IOreadAttribute (file->fid, i, &int4Buffer[0]); } else { @@ -544,12 +508,11 @@ static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) int4Buffer[0] = 0; } - /* Get the main loop index. */ - vindex = IOreadAttributeInfo (file->fid, "main loop index", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_INT4 && nels_stored == 1) + /* get the main loop index */ + i = IOreadAttributeInfo (file->fid, "main loop index", &type, &dim); + if (i >= 0 && type == FLEXIO_INT4 && dim == 1) { - IOreadAttribute (file->fid, vindex, &int4Buffer[1]); + IOreadAttribute (file->fid, i, &int4Buffer[1]); } else { @@ -557,12 +520,11 @@ static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) int4Buffer[1] = 0; } - /* Get cctk_time. */ - vindex = IOreadAttributeInfo (file->fid, "GH$time", - &nt_stored, &nels_stored); - if (vindex >= 0 && nt_stored == FLEXIO_REAL && nels_stored == 1) + /* get cctk_time */ + i = IOreadAttributeInfo (file->fid, "GH$time", &type, &dim); + if (i >= 0 && type == FLEXIO_REAL && dim == 1) { - IOreadAttribute (file->fid, vindex, &realBuffer); + IOreadAttribute (file->fid, i, &realBuffer); } else { @@ -577,8 +539,7 @@ static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) 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 (int4Buffer, 2, PUGH_MPI_INT4, 0,MPI_COMM_WORLD)); - CACTUS_MPI_ERROR (MPI_Bcast (&realBuffer, 1, PUGH_MPI_REAL, 0, - MPI_COMM_WORLD)); + CACTUS_MPI_ERROR (MPI_Bcast (&realBuffer, 1, PUGH_MPI_REAL,0,MPI_COMM_WORLD)); #endif GH->cctk_time = realBuffer; @@ -594,22 +555,21 @@ static int IOFlexIOi_RecoverGHextensions (cGH *GH, fileinfo_t *file) Broadcasting the complete parameter string is found faster than sending it in a loop from each IO processor to all the non IOs (don't have subcommunicators yet) */ -static int IOFlexIOi_RecoverParameters (fileinfo_t *file) +static int RecoverParameters (fileinfo_t *file) { - DECLARE_CCTK_PARAMETERS - int retval; - int vindex, atype; + int i, myproc, atype, retval; Long asize; char *parameters; CCTK_INT4 parameterSize; - cGH *GH = NULL; /* There's no cGH set up yet so we pass - a NULL pointer to CCTK_MyProc() */ + DECLARE_CCTK_PARAMETERS + /* To make the compiler happy */ parameterSize = -1; parameters = NULL; - if (CCTK_MyProc (GH) == 0) + myproc = CCTK_MyProc (NULL); + if (myproc == 0) { if (verbose) { @@ -618,12 +578,12 @@ static int IOFlexIOi_RecoverParameters (fileinfo_t *file) } /* Get the parameters attribute. */ - vindex = IOreadAttributeInfo (file->fid, GLOBAL_PARAMETERS, &atype, &asize); - if (vindex >= 0 && atype == FLEXIO_CHAR && asize > 0) + i = IOreadAttributeInfo (file->fid, GLOBAL_PARAMETERS, &atype, &asize); + if (i >= 0 && atype == FLEXIO_CHAR && asize > 0) { parameterSize = (CCTK_INT4) asize; parameters = (char *) malloc (parameterSize); - IOreadAttribute (file->fid, vindex, parameters); + IOreadAttribute (file->fid, i, parameters); } else { @@ -644,7 +604,7 @@ static int IOFlexIOi_RecoverParameters (fileinfo_t *file) if (parameterSize > 0) { #ifdef CCTK_MPI - if (CCTK_MyProc (GH) != 0) + if (myproc) { parameters = (char *) malloc (parameterSize + 1); } @@ -658,7 +618,8 @@ static int IOFlexIOi_RecoverParameters (fileinfo_t *file) free (parameters); } - /* Return positive value for success otherwise negative */ + /* return positive value for success otherwise negative */ retval = (parameterSize > 0 ? 1 : -1); - return retval; + + return (retval); } diff --git a/src/RestoreFile.c b/src/RestoreFile.c index f85ce1e..995e0a8 100644 --- a/src/RestoreFile.c +++ b/src/RestoreFile.c @@ -136,7 +136,7 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) /* Seek here once to the beginning of the file, the file pointer is advanced then implicitely by subsequent calls to IOreadInfo() */ - CACTUS_IEEEIO_ERROR (IOseek (file->fid, 0)); + FLEXIO_ERROR (IOseek (file->fid, 0)); /* Each IO processor loops over all available datasets, checks their consistency and broadcasts them to the non-IO processors. */ @@ -173,7 +173,7 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) } if (file->ioproc_every == 1) - CACTUS_IEEEIO_ERROR ( + FLEXIO_ERROR ( IOread (file->fid, CCTK_VarDataPtrI (GH, timelevel, vindex))); #ifdef CCTK_MPI else { @@ -208,7 +208,7 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) /* read my own data directly into data, read others data into buffer and communicate it */ if (! file->unchunked || gtype == CCTK_SCALAR) - CACTUS_IEEEIO_ERROR (IOread (file->fid, + FLEXIO_ERROR (IOread (file->fid, CCTK_VarDataPtrI (GH, timelevel, vindex))); else { for (i = 0; i < dim; i++) { @@ -216,7 +216,7 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) chunkorigin [i] = extras->lb [file->ioproc][i]; } - CACTUS_IEEEIO_ERROR (IOreadChunk (file->fid, chunkdims, chunkorigin, + FLEXIO_ERROR (IOreadChunk (file->fid, chunkdims, chunkorigin, CCTK_VarDataPtrI (GH, timelevel, vindex))); } @@ -249,14 +249,14 @@ int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file) continue; } - CACTUS_IEEEIO_ERROR (IOread (file->fid, buffer)); + FLEXIO_ERROR (IOread (file->fid, buffer)); } else { for (i = 0; i < dim; i++) { chunkdims [i] = extras->rnsize [proc][i]; chunkorigin [i] = extras->lb [proc][i]; } - CACTUS_IEEEIO_ERROR (IOreadChunk (file->fid, chunkdims, + FLEXIO_ERROR (IOreadChunk (file->fid, chunkdims, chunkorigin, buffer)); } @@ -378,7 +378,7 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, /* read the next dataset's info from the file */ result = IOreadInfo (fid, &vartype_stored, &rank_stored, dims_stored, MAXDIM); - CACTUS_IEEEIO_ERROR (result); + FLEXIO_ERROR (result); if (result == 0) { CCTK_WARN (1, "Can't read dataset info"); return (-1); @@ -391,7 +391,7 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, CCTK_WARN (2, "Can't read name attribute"); return (-1); } - CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, fullname)); + FLEXIO_ERROR (IOreadAttribute (fid, i, fullname)); /* check if there is a matching variable */ *vindex = CCTK_VarIndex (fullname); @@ -409,7 +409,7 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, "Can't read groupname attribute of '%s'", fullname); return (-1); } - CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, groupname_stored)); + FLEXIO_ERROR (IOreadAttribute (fid, i, groupname_stored)); groupname = CCTK_GroupNameFromVarI (*vindex); if (! CCTK_Equals (groupname_stored, groupname)) { CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, @@ -425,7 +425,7 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, "Can't read grouptype attribute for '%s'", fullname); return (-1); } - CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, &grouptype_stored)); + FLEXIO_ERROR (IOreadAttribute (fid, i, &grouptype_stored)); /* read the number of timelevels */ i = IOreadAttributeInfo (fid, "ntimelevels", &atype, &asize); @@ -434,7 +434,7 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, "Can't read ntimelevels attribute for '%s'", fullname); return (-1); } - CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, &numtimelevels_stored)); + FLEXIO_ERROR (IOreadAttribute (fid, i, &numtimelevels_stored)); /* read the timelevel to restore */ i = IOreadAttributeInfo (fid, "timelevel", &atype, &asize); @@ -443,7 +443,7 @@ static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *vindex, "Can't read timelevel attribute for '%s'", fullname); return (-1); } - CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, &timelevel_stored)); + FLEXIO_ERROR (IOreadAttribute (fid, i, &timelevel_stored)); *timelevel = (int) timelevel_stored; /* verify group type, variable type, dims, sizes and ntimelevels */ @@ -543,7 +543,7 @@ static int GetChunkAttributes (IOFile fid, int vindex) /* read the next dataset's info from the file */ result = IOreadInfo (fid, &vtype_stored, &rank_stored, dims_stored, MAXDIM); - CACTUS_IEEEIO_ERROR (result); + FLEXIO_ERROR (result); if (result == 0) { CCTK_WARN (1, "Can't read dataset info"); return (-1); @@ -556,7 +556,7 @@ static int GetChunkAttributes (IOFile fid, int vindex) CCTK_WARN (2, "Can't read name attribute"); return (-1); } - CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, fullname)); + FLEXIO_ERROR (IOreadAttribute (fid, i, fullname)); /* check if there is a matching variable */ if (vindex != CCTK_VarIndex (fullname)) { diff --git a/src/Startup.c b/src/Startup.c index 0df6beb..29b27e6 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -2,91 +2,349 @@ @file Startup.c @date Fri May 21 1999 @author Thomas Radke - @desc - Startup routines for IOFlexIO. - @enddesc - @history - @hauthor Thomas Radke @hdate May 21 1999 - @hdesc Just copied from thorn IOFlexIO. - @endhistory + @desc + Startup routines for IOFlexIO. + @enddesc + @version $Id$ @@*/ #include <stdio.h> #include <string.h> +#include <stdlib.h> #include "cctk.h" #include "cctk_Parameters.h" +#include "CactusPUGH/PUGH/src/include/pugh.h" +#include "CactusBase/IOUtil/src/ioGH.h" +#include "CactusBase/IOUtil/src/ioutil_Utils.h" #include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h" #include "ioFlexGH.h" +/* the rcs ID and its dummy function to use it */ static const char *rcsid = "$Header$"; - CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_Startup_c) -/* prototypes of routines defined in this source file */ +/******************************************************************** + ******************** External Routines ************************ + ********************************************************************/ void IOFlexIO_Startup (void); -void *IOFlexIO_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH); -int IOFlexIO_InitGH (cGH *GH); -int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from); +int IOFlexIO_TerminateGH (cGH *GH); + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static void *SetupGH (tFleshConfig *config, int convergence_level, cGH *GH); /*@@ @routine IOFlexIO_Startup @date Fri May 21 1999 @author Thomas Radke - @desc - The startup registration routine for IOFlexIO. - Registers the GH extensions needed for IOFlexIO and - the registerable routines used for each method of IOFlexIO. - IOFlexIO does not overload any functions. - @enddesc - @calledby CCTK scheduler at STARTUP - @history - - @endhistory - + @desc + The startup registration routine for IOFlexIO. + Registers the GH extensions needed for IOFlexIO + along with its setup routine. + @enddesc + @calls CCTK_RegisterGHExtension + CCTK_RegisterGHExtensionSetupGH @@*/ void IOFlexIO_Startup (void) { + /* check that PUGH was activated */ + if (CCTK_GHExtensionHandle ("PUGH") >= 0) + { + CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOFlexIO"), + SetupGH); + + } + else + { CCTK_WARN (1, "Thorn PUGH was not activated. " + "No IOFlexIO IO methods will be enabled."); + } +} + + + /*@@ + @routine IOFlexIO_TerminateGH + @date Tue May 09 2000 + @author Thomas Radke + @desc + The termination routine for IOFlexIO. + All open files (stored in the file lists) are closed, and the + file lists are freed. Also any created timers are destroyed. + @enddesc + + @calls CCTK_UnregisterGHExtension + + @var GH + @vdesc pointer to grid hierarchy + @vtype cGH * + @vio in + @endvar + + @returntype int + @returndesc + 0 for success + @endreturndesc +@@*/ +int IOFlexIO_TerminateGH (cGH *GH) +{ + int i; + flexioGH *myGH; + pNamedData *current; + IOFile *IEEEfiles_2D; + IEEEfile_t *IEEEfile; DECLARE_CCTK_PARAMETERS - int IO_GHExtension; - int IOMethod; - if (CCTK_GHExtensionHandle ("IO") < 0) + /* get the handle for IOFlexIO extensions */ + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); + + /* immediately return if IOFlexIO wasn't active */ + if (! myGH) { - CCTK_WARN (1, "Thorn IOUtil was not activated. " - "No IOFlexIO IO methods will be enabled."); - return; + return (0); } - if (CCTK_GHExtensionHandle ("PUGH") < 0) + + /* close any open files by walking through the file lists */ + current = myGH->fileList_2D; + while (current) { - CCTK_WARN (1, "Thorn PUGH was not activated. " - "No IOFlexIO IO methods will be enabled."); - return; + IEEEfiles_2D = (IOFile *) current->data; + if (verbose) + { + CCTK_VInfo (CCTK_THORNSTRING, "Closing 2D IEEEIO output files " + "for variable alias '%s'", current->name); + } + FLEXIO_ERROR (IOclose (IEEEfiles_2D [0])); + FLEXIO_ERROR (IOclose (IEEEfiles_2D [1])); + FLEXIO_ERROR (IOclose (IEEEfiles_2D [2])); + free (IEEEfiles_2D); + + current = current->next; + } + + current = myGH->fileList; + while (current) + { + IEEEfile = (IEEEfile_t *) current->data; + if (IEEEfile->iofile) + { + if (verbose) + { + CCTK_VInfo (CCTK_THORNSTRING, "Closing IEEEIO output file '%s'", + IEEEfile->filename); + } + IOclose (IEEEfile->iofile); + } + free (IEEEfile->filename); + free (IEEEfile); + + current = current->next; } - IO_GHExtension = CCTK_RegisterGHExtension ("IOFlexIO"); - CCTK_RegisterGHExtensionSetupGH (IO_GHExtension, IOFlexIO_SetupGH); - CCTK_RegisterGHExtensionInitGH (IO_GHExtension, IOFlexIO_InitGH); + /* free the file lists */ + DestroyNamedDataList (myGH->fileList_2D); + DestroyNamedDataList (myGH->fileList); + + if (myGH->print_timing_info) + { + for (i = 0; i < 4; i++) + { + CCTK_TimerDestroyI (myGH->timers[i]); + } + } + + /* finally unregister and free IOFlexIO's GH extension structure */ + CCTK_UnregisterGHExtension ("IOFlexIO"); + free (myGH); + + return (0); +} + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ + /*@@ + @routine SetupGH + @date Tue May 09 2000 + @author Thomas Radke + @desc + Allocates and sets up the IOFlexIO GH extension structure. + @enddesc + + @calls CCTK_RegisterIOMethod + CCTK_RegisterIOMethodOutputGH + CCTK_RegisterIOMethodOutputVarAs + CCTK_RegisterIOMethodTimeToOutput + CCTK_RegisterIOMethodTriggerOutput + IOUtil_CreateDirectory + + @var config + @vdesc flesh configuration structure (unused) + @vtype tFleshConfig * + @vio in + @endvar + @var convergence_level + @vdesc convergence level (unused) + @vtype int + @vio in + @endvar + @var GH + @vdesc pointer to grid hierarchy + @vtype cGH * + @vio in + @endvar + + @returntype void * + @returndesc + pointer to the allocated GH extension structure + @endreturndesc +@@*/ +static void *SetupGH (tFleshConfig *config, int convergence_level, cGH *GH) +{ + int i, numvars, maxdim; + flexioGH *myGH; + const ioGH *ioUtilGH; + const char *timer_names[4] = {"IOFlexIO time to dump parameters", + "IOFlexIO time to dump datasets", + "IOFlexIO total time to checkpoint", + "IOFlexIO time to recover"}; + DECLARE_CCTK_PARAMETERS + + + /* suppress compiler warnings about unused parameters */ + (void) (config + 0); + (void) (convergence_level + 0); - /* Register the 2D and 3D IOFlexIO routines as output methods */ - IOMethod = CCTK_RegisterIOMethod ("IOFlexIO_2D"); - CCTK_RegisterIOMethodOutputGH (IOMethod, IOFlexIO_Output2DGH); - CCTK_RegisterIOMethodOutputVarAs (IOMethod, IOFlexIO_Output2DVarAs); - CCTK_RegisterIOMethodTimeToOutput (IOMethod, IOFlexIO_TimeFor2D); - CCTK_RegisterIOMethodTriggerOutput (IOMethod, IOFlexIO_TriggerOutput2D); + /* register the IOFlexIO routines as I/O methods */ + i = CCTK_RegisterIOMethod ("IOFlexIO_2D"); + CCTK_RegisterIOMethodOutputGH (i, IOFlexIO_Output2DGH); + CCTK_RegisterIOMethodOutputVarAs (i, IOFlexIO_Output2DVarAs); + CCTK_RegisterIOMethodTimeToOutput (i, IOFlexIO_TimeFor2D); + CCTK_RegisterIOMethodTriggerOutput (i, IOFlexIO_TriggerOutput2D); - IOMethod = CCTK_RegisterIOMethod ("IOFlexIO_3D"); - CCTK_RegisterIOMethodOutputGH (IOMethod, IOFlexIO_Output3DGH); - CCTK_RegisterIOMethodOutputVarAs (IOMethod, IOFlexIO_Output3DVarAs); - CCTK_RegisterIOMethodTimeToOutput (IOMethod, IOFlexIO_TimeFor3D); - CCTK_RegisterIOMethodTriggerOutput (IOMethod, IOFlexIO_TriggerOutput3D); + i = CCTK_RegisterIOMethod ("IOFlexIO"); + CCTK_RegisterIOMethodOutputGH (i, IOFlexIO_OutputGH); + CCTK_RegisterIOMethodOutputVarAs (i, IOFlexIO_OutputVarAs); + CCTK_RegisterIOMethodTimeToOutput (i, IOFlexIO_TimeFor); + CCTK_RegisterIOMethodTriggerOutput (i, IOFlexIO_TriggerOutput); - /* Register the IOFlexIO recovery routine to thorn IOUtil */ + /* register the IOFlexIO recovery routine to thorn IOUtil */ if (IOUtil_RegisterRecover ("IOFlexIO recovery", IOFlexIO_Recover) < 0) + { CCTK_WARN (1, "Failed to register IOFlexIO recovery routine"); + } + + /* allocate a new GH extension structure */ + numvars = CCTK_NumVars (); + myGH = (flexioGH *) malloc (sizeof (flexioGH)); + myGH->do_out = (char *) malloc (numvars * sizeof (char)); + myGH->do_out2D = (char *) malloc (numvars * sizeof (char)); + myGH->out_last = (int *) malloc (numvars * sizeof (int)); + myGH->out2D_last = (int *) malloc (numvars * sizeof (int)); + + maxdim = CCTK_MaxDim(); + myGH->sp2xyz = (int **) malloc(maxdim * sizeof (int *)); + for (i = 0; i < maxdim; i++) + { + myGH->sp2xyz[i] = (int *) malloc (3 * sizeof (int )); + } + + /* get the handle for IOUtil extensions */ + ioUtilGH = (const ioGH *) CCTK_GHExtension (GH, "IO"); + + /* check whether "outdir2D" and/or "outdir3D" were set. + If so take these dirs otherwise default to "IO::outdir" */ + if (CCTK_ParameterQueryTimesSet ("outdir2D", CCTK_THORNSTRING) > 0) + { + myGH->outdir2D = strdup (outdir2D); + } + else + { + myGH->outdir2D = CCTK_ParameterValString ("outdir", + CCTK_ImplementationThorn ("IO")); + } + + if (CCTK_ParameterQueryTimesSet ("outdir3D", CCTK_THORNSTRING) > 0) + { + myGH->outdir = strdup (outdir3D); + } + else + { + myGH->outdir = CCTK_ParameterValString ("outdir", + CCTK_ImplementationThorn ("IO")); + } + + /* create the output directories */ + i = IOUtil_CreateDirectory (GH, myGH->outdir2D, + ! CCTK_Equals (out3D_mode, "onefile"), + ioUtilGH->ioproc); + if (i < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOFlexIO_InitGH: problem creating IOFlexIO 2D output" + " directory '%s'", myGH->outdir2D); + } + else if (i > 0 && CCTK_Equals (newverbose, "full")) + { + CCTK_VInfo (CCTK_THORNSTRING, + "IOFlexIO_InitGH: 2D IOFlexIO output directory '%s' " + "already exists", myGH->outdir2D); + } + i = IOUtil_CreateDirectory (GH, myGH->outdir, + ! CCTK_Equals (out3D_mode, "onefile"), + ioUtilGH->ioproc); + if (i < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "IOFlexIO_InitGH: Problem creating IOFlexIO output" + " directory '%s'", myGH->outdir); + } + else if (i > 0 && CCTK_Equals (newverbose, "full")) + { + CCTK_VInfo (CCTK_THORNSTRING, + "IOFlexIO_InitGH: IOFlexIO output directory '%s' " + "already exists", myGH->outdir); + } + + for (i = 0; i < numvars; i++) + { + myGH->out2D_last[i] = myGH->out_last[i] = -1; + } + + myGH->fileList_2D = myGH->fileList = NULL; + + /* create timers if timing info was requested */ + myGH->print_timing_info = print_timing_info; + if (myGH->print_timing_info) + { + for (i = 0; i < 4; i++) + { + myGH->timers[i] = CCTK_TimerCreate (timer_names[i]); + if (myGH->timers[i] < 0) + { + break; + } + } + if (i != 4) + { + CCTK_WARN (1, "Could not create timers for checkpoint/recovery ! " + "No timer information will be available."); + while (--i >= 0) + { + CCTK_TimerDestroyI (myGH->timers[i]); + } + myGH->print_timing_info = 0; + } + else + { + CCTK_TimerResetI (myGH->timers[2]); + CCTK_TimerResetI (myGH->timers[3]); + } + } - + return (myGH); } diff --git a/src/Write.c b/src/Write.c new file mode 100644 index 0000000..97213b6 --- /dev/null +++ b/src/Write.c @@ -0,0 +1,350 @@ +/*@@ + @file Write.c + @date Fri Feb 21 15:27:03 1997 + @author John Shalf, Gabrielle Allen, Tom Goodale, Thomas Radke + @desc + File handling routines for IOFlexIO. + @enddesc + @version $Id$ + @@*/ + + +#include <stdio.h> +#include <stdlib.h> + +#include "cctk.h" +#include "cctk_Parameters.h" +#include "CactusPUGH/PUGH/src/include/pugh.h" +#include "CactusBase/IOUtil/src/ioGH.h" +#include "CactusBase/IOUtil/src/ioutil_Utils.h" +#include "ioFlexGH.h" + +/* the rcs ID and its dummy funtion to use it */ +static const char *rcsid = "$Header$"; +CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_Write_c) + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +static IEEEfile_t *OpenFile (const cGH *GH, const char *alias, int *is_new_file); + + +/*@@ + @routine IOFlexIO_Write + @author Paul Walker + @date Feb 1997 + @desc + Opens the IOFlexIO output file, calls the dump routine, + and closes it again. + @enddesc + + @calls OpenFile + IOFlexIO_DumpVar + + @var GH + @vdesc Pointer to CCTK GH + @vtype const cGH * + @vio in + @endvar + @var vindex + @vdesc index of variable + @vtype int + @vio in + @endvar + @var alias + @vdesc alias name of variable to output + @vtype const char * + @vio in + @endvar + + @returntype int + @returndesc + return code of @seeroutine IOFlexIO_DumpVar, or<BR> + -1 if no storage was assigned to variable<BR> + -2 if file couldn't be opened + @endreturndesc +@@*/ +int IOFlexIO_Write (const cGH *GH, int vindex, const char *alias) +{ + ioGH *ioUtilGH; + int len, is_new_file, retval; + char buffer[128]; + char *fullname; + IEEEfile_t *file; + DECLARE_CCTK_PARAMETERS + + + /* check if variable has storage assigned */ + if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex))) + { + fullname = CCTK_FullName (vindex); + CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, + "No IOFlexIO output for '%s' (no storage)", fullname); + free (fullname); + return (-1); + } + + /* get the handle for IOUtil and IOFlexIO extensions */ + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); + + if (verbose) + { + CCTK_VInfo (CCTK_THORNSTRING, "IOFlexIO output of variable '%s', " + "alias '%s'", CCTK_VarName (vindex), alias); + } + + /* get the filename and descriptor for output */ + file = OpenFile (GH, alias, &is_new_file); + + /* nothing to do for an already opened file which is kept open all the time */ + if (CCTK_MyProc (GH) == ioUtilGH->ioproc) + { + if (is_new_file || reuse_filehandles) + { + if (verbose) + { + CCTK_VInfo (CCTK_THORNSTRING, "%s IEEEIO output file '%s'", + is_new_file ? "Opening" : "Resuming", file->filename); + } + + /* first time through or one file per slice: open anew */ + if (is_new_file) + { + file->iofile = IEEEopen (file->filename, "w"); + if (! IOisValid (file->iofile)) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Couldn't " + "create IEEEIO output file '%s'", file->filename); + } + + /* add the parameter filename and the creation date + as file identification attributes */ + if (CCTK_Equals (out_fileinfo, "parameter filename") || + CCTK_Equals (out_fileinfo, "all")) + { + buffer[0] = 0; + CCTK_ParameterFilename (sizeof (buffer), buffer); + FLEXIO_ERROR (IOwriteAttribute (file->iofile, "parameter file", + FLEXIO_CHAR, + strlen (buffer) + 1, buffer)); + } + if (CCTK_Equals (out_fileinfo, "creation date") || + CCTK_Equals (out_fileinfo, "all")) + { + buffer[0] = 0; + Util_CurrentDate (sizeof (buffer), buffer); + len = strlen (buffer) + 1; + buffer[len-1] = ' '; + Util_CurrentTime (sizeof (buffer) - len, buffer + len); + FLEXIO_ERROR (IOwriteAttribute (file->iofile, "creation date", + FLEXIO_CHAR, + strlen (buffer) + 1, buffer)); + } + } + else + { + /* resume the file (reopen descriptor) + This allows descriptor reuse without requiring expensive destruction + and reallocation of the associated datastructures */ + FLEXIO_ERROR (IOresume (file->iofile)); + } + + /* Turn on buffer cache (with default size chosen by IEEEIO lib) */ + if (file->iofile) + { + IEEEbufferOn (file->iofile, 0); + } + } + if (! file->iofile) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Invalid file descriptor for IEEEIO ouput file '%s'", + file->filename); + return (-2); + } + } + else + { + file->iofile = (IOFile) 0; + } + + /* output the data */ + retval = IOFlexIO_DumpVar (GH, vindex, 0, file->iofile); + + /* output the GH extensions and parameters */ + if (file->iofile) + { + /* output parameters necessary for filereader datafiles */ + if (is_new_file) + { + IOFlexIOi_DumpGHExtensions (GH, file->iofile); + if (strcmp (out3D_parameters, "no")) + { + IOFlexIOi_DumpParameters (GH, strcmp (out3D_parameters, "all") == 0, + file->iofile); + } + } + + /* close the file */ + if (out3D_septimefiles || reuse_filehandles) + { + if (verbose) + { + CCTK_VInfo (CCTK_THORNSTRING, "%s IEEEIO output file '%s'", + out3D_septimefiles ? "Closing" : "Pausing", + file->filename); + } + + IEEEbufferOff (file->iofile); + if (out3D_septimefiles) + { + FLEXIO_ERROR (IOclose (file->iofile)); + } + else + { + FLEXIO_ERROR (IOpause (file->iofile)); + } + } + } + if (out3D_septimefiles) + { + free (file->filename); + free (file); + } + + return (retval); +} + + +/******************************************************************** + ******************** Internal Routines ************************ + ********************************************************************/ +/* generate the filename for the given alias and creates/opens the file */ +static IEEEfile_t *OpenFile (const cGH *GH, const char *alias, int *is_new_file) +{ + ioGH *ioUtilGH; + pGH *pughGH; + flexioGH *myGH; + int myproc, nprocs, result; + char extra[256], extradir[256]; + char *outputdir, *tmp; + IEEEfile_t *file; + DECLARE_CCTK_PARAMETERS + + + /* get the GH extensions for PUGH, IOUtil, and IOFlexIO */ + pughGH = PUGH_pGH (GH); + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); + myGH = (flexioGH *) CCTK_GHExtension (GH, "IOFlexIO"); + + file = (IEEEfile_t *) GetNamedData (myGH->fileList, alias); + if (file != NULL) + { + /* set flag to indicate that file should be opened in append mode */ + *is_new_file = 0; + return (file); + } + + extra[0] = '\0'; + extradir[0] = '\0'; + + nprocs = CCTK_nProcs (GH); + myproc = CCTK_MyProc (GH); + + if (out3D_septimefiles) + { + tmp = extra; + sprintf (extra, "%s.time_%7.3f", extra, GH->cctk_time); + + /* be sure to replace any spaces in the filename with an _ */ + do + { + if (*tmp == ' ') + { + *tmp = '_'; + } + } while (*++tmp); + } + + /* OUTPUT ONE FILE FOR EACH N PROCESSORS + * ------------------------------------- + * + * If only one output file, the single file for each GF is written + * in the normal output dir (that is extradir = ""). Otherwise + * a directory is created for each output GF to hold the multiple + * file + */ + + if (ioUtilGH->ioproc_every < nprocs) + { + /* add the output processor number to the extra string */ + sprintf (extra, "%s.file_%d", extra, myproc / ioUtilGH->ioproc_every); + + /* if necessary create the output directory */ + outputdir = (char *) malloc (strlen (myGH->outdir) + strlen (alias) + 5); + sprintf (outputdir, "%s/%s_3d", myGH->outdir, alias); + + result = IOUtil_CreateDirectory (GH, outputdir, + ! CCTK_Equals (out3D_mode, "onefile"), + ioUtilGH->ioproc); + if (result < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Problem creating IOFlexIO output directory '%s'", outputdir); + } + else if (result > 0 && CCTK_Equals (newverbose, "full")) + { + CCTK_VInfo (CCTK_THORNSTRING, + "IOFlexIO output directory '%s' already exists", outputdir); + } + + free (outputdir); + +#ifdef CCTK_MPI + /* wait for all processors to catch up */ + CCTK_Barrier (GH); +#endif + + /* extradir is the relative output directory */ + sprintf (extradir, "%s_3d/", alias); + } + + /* CREATE THE COMPLETE OUTPUT FILENAME + ----------------------------------- */ + + file = (IEEEfile_t *) malloc (sizeof (IEEEfile_t)); + + file->filename = (char *) malloc (strlen (myGH->outdir) + strlen (extradir) + + strlen (alias) + strlen (extra) + + (pughGH->identity_string ? + strlen (pughGH->identity_string) : 0) + + 10); + sprintf (file->filename, "%s/%s%s_3d%s%s.ieee", myGH->outdir, + extradir, alias, extra, (pughGH->identity_string ? + pughGH->identity_string : "")); + + /* no need to store file info if used only once */ + if (! out3D_septimefiles) + { + if (myproc == ioUtilGH->ioproc) + { + if (ioUtilGH->recovered) + { + file->iofile = IEEEopen (file->filename, "a"); + *is_new_file = ! IOisValid (file->iofile); + } + else + { + *is_new_file = 1; + } + } + StoreNamedData (&myGH->fileList, alias, file); + } + else + { + *is_new_file = 1; + } + + return (file); +} diff --git a/src/Write2D.c b/src/Write2D.c index c623c1a..0427ab5 100644 --- a/src/Write2D.c +++ b/src/Write2D.c @@ -190,7 +190,7 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias) { buffer[0] = 0; CCTK_ParameterFilename (sizeof (buffer), buffer); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], + FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "parameter file", FLEXIO_CHAR, strlen (buffer) + 1, buffer)); } @@ -202,7 +202,7 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias) len = strlen (buffer) + 1; buffer[len-1] = ' '; Util_CurrentTime (sizeof (buffer) - len, buffer + len); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], + FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "creation date", FLEXIO_CHAR, strlen (buffer) + 1, buffer)); } @@ -227,7 +227,7 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias) for (dir = 0; dir < 3; dir++) { - CACTUS_IEEEIO_ERROR (IOresume (IEEEfile_2D[dir])); + FLEXIO_ERROR (IOresume (IEEEfile_2D[dir])); } } } @@ -287,7 +287,7 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias) if (myproc == 0) { /* the data itself */ - CACTUS_IEEEIO_ERROR (IOwrite (IEEEfile_2D[dir], + FLEXIO_ERROR (IOwrite (IEEEfile_2D[dir], ioflex_type, 2, data_hsizes, data)); free (data); @@ -298,15 +298,15 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias) max_ext_attr[1] = max_ext[dir_j]; delta_attr[0] = GH->cctk_delta_space[dir_i]; delta_attr[1] = GH->cctk_delta_space[dir_j]; - CACTUS_IEEEIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "time", + FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "time", FLEXIO_REAL, 1, &GH->cctk_time)); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "origin", + FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "origin", FLEXIO_REAL, 2, min_ext_attr)); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "min_ext", + FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "min_ext", FLEXIO_REAL, 2, min_ext_attr)); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "max_ext", + FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "max_ext", FLEXIO_REAL, 2, max_ext_attr)); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "delta", + FLEXIO_ERROR (IOwriteAttribute (IEEEfile_2D[dir], "delta", FLEXIO_REAL, 2, delta_attr)); } @@ -323,7 +323,7 @@ int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias) for (dir = 0; dir < 3; dir++) { - CACTUS_IEEEIO_ERROR (IOpause (IEEEfile_2D[dir])); + FLEXIO_ERROR (IOpause (IEEEfile_2D[dir])); } } diff --git a/src/Write3D.c b/src/Write3D.c deleted file mode 100644 index 9850d05..0000000 --- a/src/Write3D.c +++ /dev/null @@ -1,410 +0,0 @@ -/*@@ - @file Write3D.c - @date Fri Feb 21 15:27:03 1997 - @author - @desc - A horrible blocking write and not-quite-so-horrible - slicer for xgraph output. Basically MPI based IO - bites the big one, and this is MPI based IO written - quickly and in the obvious inefficient fashion. - <p> - Oh, not it also contains zero-d I/O and a closer also. - <p> - This routine can write DFSD style HDF (not the default) - or Johns IEEEIO 3D files (the default). For 0 and 1D - I/O it writes xgraph files. - @enddesc - @history - @hauthor Gabrielle Allen @hdate 26 Sep 1998 - @hdesc Changed routine name (WriteGF->Write3D), Lots of tidying up and - renaming of parameters - @hauthor Gabrielle Allen @hdate 17 Oct 1998 - @hdesc Implemented new parameters IO_verbose,IO_parameter,IO_structures,IO_scalars - @hauthor Gabrielle Allen @hdate 19 Oct 1998 - @hdesc Changed names ready for thorn_IO - @hauthor Thomas Radke @hdate 16 Mar 1999 - @hdesc Converted to Cactus 4.0 - @hauthor Thomas Radke @hdate 17 Mar 1999 - @hdesc Changed naming: IEEEIO -> IOFlexIO - @hendhistory - @version $Id$ - @@*/ - - -#include <stdio.h> -#include <stdlib.h> - -#include "cctk.h" -#include "cctk_Parameters.h" -#include "CactusPUGH/PUGH/src/include/pugh.h" -#include "CactusBase/IOUtil/src/ioGH.h" -#include "CactusBase/IOUtil/src/ioutil_Utils.h" -#include "ioFlexGH.h" - -/* the rcs ID and its dummy funtion to use it */ -static const char *rcsid = "$Header$"; -CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_Write3D_c) - - -/* Function prototypes from other files in this thorn */ -void IOFlexIOi_DumpGHExtensions (const cGH *GH, IOFile iof); -void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile iof); - - - -/* local function prototypes */ -static IEEEfile_3D_t *IOFlexIO_Get3Dfile (const cGH *GH, const char *alias, - int *isNewFile); - -/*@@ - @routine IOFlexIO_Write3D - @author Paul Walker - @date Feb 1997 - @desc - This routine does 3D IO for a grid function which has been - distributed with MPI. - <p> - 3D MPI IO! Wow, you may say, that sounds pretty clever. Well it isn't - because <b><i>The method I use sucks rocks</i></b>. That is. - I spam the data from all processors onto processor 0. Luckily - it doesn't just put it all in one memory chunk, but recieves it - bit by bit and writes it out chunkwise, using IEEEIO. Alas, - while this happens the other processors <i>sit in a barrier - with their metaphoric thumbs up their asses</i>. - <p> - <b>Even Worse</b> it is a blocking send which must come in order - from the other processors. - <p> - This is inefficient to say the least. I/O costs can go up to 70-80% - using this technique on the T3E. So there are also a couple of ways to - get around it. - <p> - The easiest option is one-file-per-processor which is - good on some machines, (eg T3E) and bad on others (eg O2K, I think). - So you can activate this mode (or de-activate it on the T3E) - by setting the parameter onefileperproc to "yes" or "no". - This will create a bunch of files in their own subdirectory, - and they can be smooshed together using cactus/lib/etc/Recombiner.C - <p> - Also, you can downsample output. You can also output one file per - slice. Various combinations of these work or don't, depending. - <p> - Finally notice that @seeroutine main guarantees that this is never - called on a 1- or 2-D grid. - @enddesc - @calledby IOFlexIO_Output3DVarAs, IOFlexIO_TriggerOutput3D - @history - @hdate Wed Sep 2 10:11:41 1998 @hauthor Tom Goodale - @hdesc Merged in Szu-Wen's Panda calls. - @hdate Sep 25 1998 1998 @hauthor Gabrielle Allen - @hdesc Split into subroutines - @endhistory - @var GH - @vdesc Pointer to CCTK GH - @vtype const cGH * - @vio in - @vcomment - @endvar - @var vindex - @vdesc index of variable to output - @vtype int - @vio in - @vcomment - @endvar - @var alias - @vdesc alias name of variable to output - @vtype const char * - @vio in - @vcomment - @endvar - @@*/ -int IOFlexIO_Write3D (const cGH *GH, int vindex, const char *alias) -{ - ioGH *ioUtilGH; - int len, isNewFile; - char buffer[128]; - IEEEfile_3D_t *IEEEfile_3D; - DECLARE_CCTK_PARAMETERS - - - /* first, check if variable has storage assigned */ - if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (vindex))) - { - char *fullname = CCTK_FullName (vindex); - - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "No IOFlexIO output for '%s' (no storage)", fullname); - free (fullname); - return (-1); - } - - /* Get the handle for IOUtil and IOFlexIO extensions */ - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; - - if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "IOFlexIO output of variable '%s', " - "alias '%s'", CCTK_VarName (vindex), alias); - - /* Get the filename and descriptor for output */ - IEEEfile_3D = IOFlexIO_Get3Dfile (GH, alias, &isNewFile); - - /* nothing to do for an already opened file - which is kept open all the time */ - if (CCTK_MyProc (GH) == ioUtilGH->ioproc) - { - if (isNewFile || reuse_filehandles) - { - - if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "%s IEEEIO output file '%s'", - isNewFile ? "Opening" : "Resuming", IEEEfile_3D->filename); - - /* First time through or one file per slice; open anew */ - if (isNewFile) - { - IEEEfile_3D->iofile = IEEEopen (IEEEfile_3D->filename, "w"); - if (! IOisValid (IEEEfile_3D->iofile)) - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Couldn't " - "create IEEEIO output file '%s'", IEEEfile_3D->filename); - - /* add the parameter filename and the creation date - as file identification attributes */ - if (CCTK_Equals (out_fileinfo, "parameter filename") || - CCTK_Equals (out_fileinfo, "all")) - { - buffer[0] = 0; - CCTK_ParameterFilename (sizeof (buffer), buffer); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (IEEEfile_3D->iofile, - "parameter file", FLEXIO_CHAR, - strlen (buffer) + 1, buffer)); - } - if (CCTK_Equals (out_fileinfo, "creation date") || - CCTK_Equals (out_fileinfo, "all")) - { - buffer[0] = 0; - Util_CurrentDate (sizeof (buffer), buffer); - len = strlen (buffer) + 1; - buffer[len-1] = ' '; - Util_CurrentTime (sizeof (buffer) - len, buffer + len); - CACTUS_IEEEIO_ERROR (IOwriteAttribute (IEEEfile_3D->iofile, - "creation date", FLEXIO_CHAR, - strlen (buffer) + 1, buffer)); - } - } - else - { - /* resume the file (reopen descriptor) - This allows descriptor reuse without requiring expensive destruction - and reallocation of the associated datastructures */ - CACTUS_IEEEIO_ERROR (IOresume (IEEEfile_3D->iofile)); - } - - /* Turn on buffer cache (with default size chosen by IEEEIO lib) */ - if (IEEEfile_3D->iofile) - IEEEbufferOn (IEEEfile_3D->iofile, 0); - } - if (! IEEEfile_3D->iofile) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Invalid file descriptor for IEEEIO ouput file '%s'", - IEEEfile_3D->filename); - return (-2); - } - } - else - { - IEEEfile_3D->iofile = (IOFile) 0; - } - - /* output the data */ - IOFlexIO_DumpVar (GH, vindex, 0, IEEEfile_3D->iofile); - - /* output the GH extensions and parameters */ - /* Don't do this if the output is being byte compared, as the - * thorn lists might be different. - */ - if (IEEEfile_3D->iofile) - { - /* output parameters necessary for filereader datafiles */ - if (isNewFile) - { - IOFlexIOi_DumpGHExtensions (GH, IEEEfile_3D->iofile); - if (strcmp (out3D_parameters, "no")) - IOFlexIOi_DumpParameters (GH, strcmp (out3D_parameters, "all") == 0, - IEEEfile_3D->iofile); - } - - /* close the file */ - if (out3D_septimefiles || reuse_filehandles) - { - if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "%s IEEEIO output file '%s'", - out3D_septimefiles ? "Closing" : "Pausing", - IEEEfile_3D->filename); - - IEEEbufferOff (IEEEfile_3D->iofile); - if (out3D_septimefiles) - CACTUS_IEEEIO_ERROR (IOclose (IEEEfile_3D->iofile)); - else - CACTUS_IEEEIO_ERROR (IOpause (IEEEfile_3D->iofile)); - } - } - if (out3D_septimefiles) - { - free (IEEEfile_3D->filename); - free (IEEEfile_3D); - } - - return (0); -} - - -/**************************** local routines ****************************/ - - -/*@@ - @routine IOFlexIO_Get3Dfile - @author Paul Walker - @date Feb 1997 - @desc - Generates the filename for output - @enddesc - @history - @hauthor Gabrielle Allen - @hdate Sep 1998 - @hdesc Split into subroutine - @endhistory - @@*/ - -static IEEEfile_3D_t *IOFlexIO_Get3Dfile (const cGH *GH, const char *alias, - int *isNewFile) -{ - DECLARE_CCTK_PARAMETERS - ioGH *ioUtilGH; /* handle for IOUtil extensions */ - pGH *pughGH; /* handle for PUGH extensions */ - flexioGH *myGH; /* handle for IOFlexIO extensions */ - int nprocs; - int myproc, result; - char extra [256]; /* Extra stuff in fname based on mode */ - char extradir [256]; /* Extra stuff for an output dir */ - char *outputdir; /* the output directory to be created */ - IEEEfile_3D_t *IEEEfile_3D; - - - /* get the GH extensions for PUGH, IOUtil, and IOFlexIO */ - pughGH = PUGH_pGH (GH); - ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; - myGH = (flexioGH *) GH->extensions [CCTK_GHExtensionHandle ("IOFlexIO")]; - - IEEEfile_3D = (IEEEfile_3D_t *) GetNamedData (myGH->fileList_3D, alias); - if (IEEEfile_3D != NULL) - { - /* set flag to indicate that file should be opened in append mode */ - *isNewFile = 0; - return (IEEEfile_3D); - } - - extra [0] = '\0'; - extradir [0] = '\0'; - - nprocs = CCTK_nProcs (GH); - myproc = CCTK_MyProc (GH); - - if (out3D_septimefiles) - { - char *tmp = extra; - - sprintf (extra, "%s.time_%7.3f", extra, GH->cctk_time); - - /* And be sure to replace any spaces in the filename with an _ */ - do - if (*tmp == ' ') - *tmp = '_'; - while (*++tmp); - } - - /* OUTPUT ONE FILE FOR EACH N PROCESSORS - * ------------------------------------- - * - * If only one output file, the single file for each GF is written - * in the normal output dir (that is extradir = ""). Otherwise - * a directory is created for each output GF to hold the multiple - * file - */ - - if (ioUtilGH->ioproc_every < nprocs) - { - - /* Add the output processor number to the extra string */ - sprintf (extra, "%s.file_%d", extra, myproc / ioUtilGH->ioproc_every); - - /* If necessary create the output directory */ - outputdir = (char *) malloc (strlen (myGH->outdir3D) + - strlen (alias) + 5); - sprintf (outputdir, "%s/%s_3d", myGH->outdir3D, alias); - - result = IOUtil_CreateDirectory (GH, outputdir, - ! CCTK_Equals (out3D_mode, "onefile"), - ioUtilGH->ioproc); - if (result < 0) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Problem creating 3D output directory '%s'", outputdir); - } - else if (result > 0 && CCTK_Equals (newverbose, "full")) - { - CCTK_VInfo (CCTK_THORNSTRING, - "3D output directory '%s' already exists", outputdir); - } - - free (outputdir); - -#ifdef CCTK_MPI - /* Wait for all processors to catch up */ - CCTK_Barrier (GH); -#endif - - /* extradir is the relative output directory */ - sprintf (extradir, "%s_3d/", alias); - - } - - - /* CREATE THE COMPLETE OUTPUT FILENAME - ----------------------------------- */ - - IEEEfile_3D = (IEEEfile_3D_t *) malloc (sizeof (IEEEfile_3D_t)); - - IEEEfile_3D->filename = (char *) malloc (strlen (myGH->outdir3D) + - strlen (extradir) + - strlen (alias) + - strlen (extra) + - (pughGH->identity_string ? strlen (pughGH->identity_string) : 0) + - 10); - sprintf (IEEEfile_3D->filename, "%s/%s%s_3d%s%s.ieee", myGH->outdir3D, - extradir, alias, extra, (pughGH->identity_string ? pughGH->identity_string : "")); - - /* no need to store file info if used only once */ - if (! out3D_septimefiles) - { - if (myproc == ioUtilGH->ioproc) - { - if (ioUtilGH->recovered) - { - IEEEfile_3D->iofile = IEEEopen (IEEEfile_3D->filename, "a"); - *isNewFile = ! IOisValid (IEEEfile_3D->iofile); - } - else - { - *isNewFile = 1; - } - } - StoreNamedData (&myGH->fileList_3D, alias, IEEEfile_3D); - } - else - { - *isNewFile = 1; - } - - return (IEEEfile_3D); -} diff --git a/src/ioFlexGH.h b/src/ioFlexGH.h index 7cffc34..6691a6c 100644 --- a/src/ioFlexGH.h +++ b/src/ioFlexGH.h @@ -3,19 +3,13 @@ @date Tue 9th Jan 1999 @author Gabrielle Allen @desc - The extensions to the GH structure from IO. - @history - @hauthor Thomas Radke @hdate 16 Mar 1999 - @hdesc Added parameters for 2D and 3D output - @hauthor Thomas Radke @hdate 17 Mar 1999 - @hdesc Changed naming: IEEEIO -> IOFlexIO - @hauthor Thomas Radke @hdate 30 Mar 1999 - @hdesc Undefined DI macro - @endhistory - @version $Header$ + The extensions to the GH structure from IOFlexIO. + @enddesc + @version $Header$ @@*/ -#include <string.h> +#ifndef _IOFLEXIO_IOFLEXGH_H_ +#define _IOFLEXIO_IOFLEXGH_H_ 1 #include "StoreNamedData.h" @@ -26,23 +20,23 @@ /* define the IOFlexIO datatypes according to CCTK_??? datatypes */ #define FLEXIO_CHAR CHAR -#ifdef CCTK_INT2 +#ifdef CCTK_INT2 #define FLEXIO_INT2 INT16 #endif -#ifdef CCTK_INT4 +#ifdef CCTK_INT4 #define FLEXIO_INT4 INT32 #endif -#ifdef CCTK_INT8 +#ifdef CCTK_INT8 #define FLEXIO_INT8 INT64 #endif -#ifdef CCTK_REAL4 +#ifdef CCTK_REAL4 #define FLEXIO_REAL4 FLOAT32 #endif -#ifdef CCTK_REAL8 +#ifdef CCTK_REAL8 #define FLEXIO_REAL8 FLOAT64 #endif -#ifdef CCTK_REAL16 +#ifdef CCTK_REAL16 #define FLEXIO_REAL16 -1 #endif @@ -70,25 +64,27 @@ #define GLOBAL_PARAMETERS "global_parameters" /* Check error flags from IOFlexIO */ -#define CACTUS_IEEEIO_ERROR(fn_call) \ - do { \ +#define FLEXIO_ERROR(fn_call) \ + do \ + { \ + int error_code = fn_call; \ \ - int error_code = fn_call; \ - \ - if (error_code < 0) \ - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, \ - "IEEEIO call '%s' returned error code %d\n", \ - #fn_call, error_code); \ - } while (0) + if (error_code < 0) \ + { \ + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, \ + "IEEEIO call '%s' returned error code %d\n", \ + #fn_call, error_code); \ + } \ + } while (0) -/* info structure describing 3D IEEEIO output files +/* info structure describing IEEEIO output files For each open file there is one entry in the file database. */ typedef struct { IOFile iofile; char *filename; -} IEEEfile_3D_t; +} IEEEfile_t; /* structure holding necessary information about a recovery file */ @@ -96,11 +92,11 @@ typedef struct { int is_IEEEIO_file; /* flag indicating valid file info */ IOFile fid; /* IEEEIO file handle */ - char filename [1024]; /* complete file name for recovery */ - int nprocs; /* number of total processors */ - int ioproc; /* the associated IO processor */ - int ioproc_every; /* how many IO processors there are */ - int unchunked; /* whether data was written chunked or unchunked */ + char filename[1024]; /* complete file name for recovery */ + CCTK_INT nprocs; /* number of total processors */ + CCTK_INT ioproc; /* the associated IO processor */ + CCTK_INT ioproc_every; /* how many IO processors there are */ + CCTK_INT unchunked; /* whether data was written chunked or unchunked */ int has_version; /* whether whether file contains a Cactus version ID (this is used to distinguish checkpoint files with old/new timelevel naming scheme) */ @@ -111,24 +107,19 @@ typedef struct typedef struct IOFlexIOGH { /* flags indicating output for var [i] */ - char *do_out2D; - char *do_out3D; + char *do_out2D, *do_out; /* how often to output */ - int out2D_every; - int out3D_every; + int out2D_every, out_every; /* directory in which to output */ - char *outdir2D; - char *outdir3D; + char *outdir2D, *outdir; /* the last iteration output */ - int *out2D_last; - int *out3D_last; + int *out2D_last, *out_last; /* filename database for opened files */ - pNamedData *fileList_2D; - pNamedData *fileList_3D; + pNamedData *fileList_2D, *fileList; /* timer array for checkpointing/recovery */ int timers[4]; @@ -147,15 +138,20 @@ int IOFlexIO_Output2DGH (const cGH *GH); int IOFlexIO_TriggerOutput2D (const cGH *GH, int); int IOFlexIO_TimeFor2D (const cGH *GH, int); int IOFlexIO_Output2DVarAs (const cGH *GH, const char *var, const char *alias); -int IOFlexIO_Output3DGH (const cGH *GH); -int IOFlexIO_TriggerOutput3D (const cGH *GH, int); -int IOFlexIO_TimeFor3D (const cGH *GH, int); -int IOFlexIO_Output3DVarAs (const cGH *GH, const char *var, const char *alias); +int IOFlexIO_OutputGH (const cGH *GH); +int IOFlexIO_TriggerOutput (const cGH *GH, int); +int IOFlexIO_TimeFor (const cGH *GH, int); +int IOFlexIO_OutputVarAs (const cGH *GH, const char *var, const char *alias); /* other function prototypes */ +int IOFlexIO_DataType (int cctk_type); int IOFlexIO_Write2D (const cGH *GH, int vindex, const char *alias); -int IOFlexIO_Write3D (const cGH *GH, int vindex, const char *alias); -void IOFlexIO_DumpVar (const cGH *GH, int vindex, int timelevel, IOFile iof); -void IOFlexIO_IEEEIOStructDump (const cGH *GH, IOFile iof); +int IOFlexIO_Write (const cGH *GH, int vindex, const char *alias); void IOFlexIO_DumpGH (const cGH *GH, int called_from); -int IOFlexIO_DataType (int cctk_type); +int IOFlexIO_DumpVar (const cGH *GH, int vindex, int timelevel, IOFile iof); +void IOFlexIOi_DumpParameters (const cGH *GH, int all, IOFile file); +void IOFlexIOi_DumpGHExtensions (const cGH *GH, IOFile file); +int IOFlexIO_Recover (cGH *GH, const char *basefilename, int called_from); +int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file); + +#endif /* _IOFLEXIO_IOFLEXGH_H_ */ diff --git a/src/make.code.defn b/src/make.code.defn index 5f804c9..9376fc6 100644 --- a/src/make.code.defn +++ b/src/make.code.defn @@ -1,4 +1,8 @@ -SRCS = Startup.c GHExtension.c Output2D.c Write2D.c Output3D.c Write3D.c DumpVar.c DumpGH.c RecoverGH.c RestoreFile.c ChooseOutput.c +# Main make.code.defn file for thorn IOFlexIO +# $Header$ -# all compilers should understand ANSI C +SRCS = Startup.c Output2D.c Write2D.c Output.c Write.c DumpVar.c DumpGH.c \ + RecoverGH.c RestoreFile.c ChooseOutput.c + +# This avoids warnings when including the FlexIO headers CFLAGS += -DANSI diff --git a/src/make.configuration.defn b/src/make.configuration.defn index d287aa7..93b56b9 100644 --- a/src/make.configuration.defn +++ b/src/make.configuration.defn @@ -1,13 +1,9 @@ # make.configuration.defn for IOFlexIO +# $Header$ # make sure that IOFlexIO was configured with PUGH - ifeq ($(findstring CactusPUGH/PUGH,$(THORNS)),) -.pseudo: MissingPUGHinIOFlexIO -MissingPUGHinIOFlexIO: - @echo "IOFlexIO: requires PUGH" - @echo "IOFlexIO: Please add CactusPUGH/PUGH or remove IOFlexIO from Thornlist !" - exit 2 + $(error "IOFlexIO requires PUGH. Please add CactusPUGH/PUGH or remove IOFlexIO from Thornlist !" endif |