From 8297b39029c9314bc4e4691c9965b318c610fb3c Mon Sep 17 00:00:00 2001 From: tradke Date: Thu, 12 Oct 2000 11:53:20 +0000 Subject: Added checkpoint/recovery functionality. Moved a lot of code into IOHDF5Util and inherit from this thorn. git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOStreamedHDF5/trunk@44 0888f3d4-9f52-45d2-93bc-d00801ff5e46 --- src/Output.c | 250 ++++++++++++++++++++----------------- src/Startup.c | 353 ++++++++++++++++++++++++++++++++--------------------- src/Write.c | 168 ++++++++++++------------- src/make.code.defn | 2 +- 4 files changed, 438 insertions(+), 335 deletions(-) diff --git a/src/Output.c b/src/Output.c index 92766da..0539fdf 100644 --- a/src/Output.c +++ b/src/Output.c @@ -3,61 +3,56 @@ @date Tue Jan 9 1999 @author Gabrielle Allen @desc - Functions to deal with output of variables in HDF5 FiberBundle format + Functions to deal with streaming output of variables + in HDF5 format. @enddesc - @history - @hauthor Thomas Radke @hdate 16 Mar 1999 - @hdesc Converted to Cactus 4.0 - @hendhistory + @version $Id$ @@*/ - -#include #include -#include #include "cctk.h" #include "cctk_Parameters.h" -#include "CactusBase/IOUtil/src/ioGH.h" -#include "StreamedHDF5GH.h" +#include "ioStreamedHDF5GH.h" + +/* the rcs ID and its dummy function to use it */ +static char *rcsid = "$Id$"; +CCTK_FILEVERSION(BetaThorns_IOStreamedHDF5_Output_c) /* function prototypes */ -int StreamedHDF5_TimeFor (cGH *GH, int index); -int StreamedHDF5_OutputVarAs (cGH *GH, const char *var, const char *alias); -static void CheckSteerableParameters (StreamedHDF5GH *myGH); +static void CheckSteerableParameters (ioStreamedHDF5GH *myGH); /*@@ - @routine StreamedHDF5_OutputGH + @routine IOStreamedHDF5_OutputGH @date Sat March 6 1999 @author Gabrielle Allen @desc - Loops over all variables and outputs them if necessary + Loops over all variables and outputs them if necessary @enddesc - @calledby CCTK_OutputGH ("StreamedHDF5") - @history - - @endhistory - @var GH - @vdesc Pointer to CCTK GH - @vtype cGH - @vio in + + @calls IOStreamedHDF5_TimeFor + IOStreamedHDF5_OutputVarAs + + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH * + @vio in @endvar @@*/ - -int StreamedHDF5_OutputGH (cGH *GH) +int IOStreamedHDF5_OutputGH (cGH *GH) { DECLARE_CCTK_PARAMETERS - int i; - StreamedHDF5GH *myGH; + int index; + ioStreamedHDF5GH *myGH; const char *name; char *fullname; - /* Get the GH extension for StreamedHDF5 */ - myGH = (StreamedHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("StreamedHDF5")]; + /* Get the GH extension for IOStreamedHDF5 */ + myGH = (ioStreamedHDF5GH *) CCTK_GHExtension (GH, "IOStreamedHDF5"); CheckSteerableParameters (myGH); @@ -67,27 +62,28 @@ int StreamedHDF5_OutputGH (cGH *GH) } /* Loop over all variables */ - for (i = 0; i < CCTK_NumVars (); i++) + for (index = 0; index < CCTK_NumVars (); index++) { - if (StreamedHDF5_TimeFor (GH, i)) + if (IOStreamedHDF5_TimeFor (GH, index)) { - name = CCTK_VarName (i); - fullname = CCTK_FullName (i); + name = CCTK_VarName (index); + fullname = CCTK_FullName (index); if (verbose) { - CCTK_VInfo (CCTK_THORNSTRING, "StreamedHDF5_OutputGH: fullname / name " - "= %s / %s", fullname, name); + CCTK_VInfo (CCTK_THORNSTRING, "IOStreamedHDF5_OutputGH: " + "output of variable (fullname / name) " + "= ('%s' / '%s')", fullname, name); } - StreamedHDF5_OutputVarAs (GH, fullname, name); + IOStreamedHDF5_OutputVarAs (GH, fullname, name); free (fullname); /* Register variable as having output this iteration */ - myGH->out_last [i] = GH->cctk_iteration; + myGH->out_last[index] = GH->cctk_iteration; } } @@ -96,34 +92,36 @@ int StreamedHDF5_OutputGH (cGH *GH) /*@@ - @routine StreamedHDF5_OutputVarAs + @routine IOStreamedHDF5_OutputVarAs @date Sat March 6 1999 @author Gabrielle Allen @desc - unconditional output of a variable using the StreamedHDF5 output method + Unconditional output of a variable + using the IOStreamedHDF5 output method. @enddesc - @calledby StreamedHDF5_OutputGH, CCTK_OutputVarAsByMethod ("StreamedHDF5") - @var GH - @vdesc Pointer to CCTK GH - @vtype cGH - @vio in - @vcomment + + @calls IOStreamedHDF5_Write + + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH * + @vio in @endvar - @var fullname - @vdesc complete name of variable to output - @vtype const char * - @vio in - @vcomment + @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 - @vcomment + @var alias + @vdesc alias name of variable to output + (used to generate output filename) + @vtype const char * + @vio in @endvar @@*/ - -int StreamedHDF5_OutputVarAs (cGH *GH, const char *fullname, const char *alias) +int IOStreamedHDF5_OutputVarAs (cGH *GH, + const char *fullname, + const char *alias) { DECLARE_CCTK_PARAMETERS int index; @@ -133,50 +131,54 @@ int StreamedHDF5_OutputVarAs (cGH *GH, const char *fullname, const char *alias) if (verbose) { - CCTK_VInfo (CCTK_THORNSTRING, "StreamedHDF5_OutputVarAs: fullname, alias, " - "index = (%s, %s, %d)", fullname, alias, index); + CCTK_VInfo (CCTK_THORNSTRING, "IOStreamedHDF5_OutputVarAs: " + "output of variable (fullname / alias) " + "= ('%s' / '%s')", fullname, alias); } /* Do the output */ - StreamedHDF5_Write (GH, index, alias); + IOStreamedHDF5_Write (GH, index, alias); return (0); } /*@@ - @routine StreamedHDF5_TimeFor + @routine IOStreamedHDF5_TimeFor @date Sat March 6 1999 @author Gabrielle Allen @desc - Decides if it is time to output a variable using the StreamedHDF5 output - method + Decides if it is time to output a variable + using the IOStreamedHDF5 output method. @enddesc - @calledby StreamedHDF5_OutputGH - @history - - @endhistory - @var GH - @vdesc Pointer to CCTK GH - @vtype cGH - @vio in - @vcomment + + @calls CheckSteerableParameters + + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH * + @vio in @endvar - @var index - @vdesc index of variable - @vtype int - @vio in - @vcomment + @var index + @vdesc index of variable + @vtype int + @vio in @endvar -@@*/ -int StreamedHDF5_TimeFor (cGH *GH, int index) + @returntype int + @returndesc + 1 if output should take place + 0 if not + @endreturndesc +@@*/ +int IOStreamedHDF5_TimeFor (cGH *GH, + int index) { - StreamedHDF5GH *myGH; + ioStreamedHDF5GH *myGH; - /* Get the GH extension for StreamedHDF5 */ - myGH = (StreamedHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("StreamedHDF5")]; + /* Get the GH extension for IOStreamedHDF5 */ + myGH = (ioStreamedHDF5GH *) CCTK_GHExtension (GH, "IOStreamedHDF5"); CheckSteerableParameters (myGH); @@ -187,15 +189,15 @@ int StreamedHDF5_TimeFor (cGH *GH, int index) } /* Check this variable should be output */ - if (! (myGH->do_output [index] && GH->cctk_iteration % myGH->out_every == 0)) + if (! (myGH->do_output[index] && GH->cctk_iteration % myGH->out_every == 0)) { return (0); } /* Check variable not already output this iteration */ - if (myGH->out_last [index] == GH->cctk_iteration) + if (myGH->out_last[index] == GH->cctk_iteration) { - CCTK_WARN (2, "Already done output in StreamedHDF5"); + CCTK_WARN (2, "Already done output in IOStreamedHDF5"); return (0); } @@ -204,54 +206,80 @@ int StreamedHDF5_TimeFor (cGH *GH, int index) /*@@ - @routine StreamedHDF5_TriggerOutput + @routine IOStreamedHDF5_TriggerOutput @date Sat March 6 1999 @author Gabrielle Allen @desc - Triggers the output a variable using the StreamedHDF5 output - method + Triggers the output of a variable + using the IOStreamedHDF5 output. @enddesc - @calledby CCTK scheduler - @var GH - @vdesc Pointer to CCTK GH - @vtype cGH - @vio in - @vcomment + + @calls IOStreamedHDF5_Write + + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH * + @vio in @endvar - @var index - @vdesc index of variable to output - @vtype int - @vio in - @vcomment + @var index + @vdesc index of variable + @vtype int + @vio in @endvar @@*/ - -int StreamedHDF5_TriggerOutput (cGH *GH, int index) +int IOStreamedHDF5_TriggerOutput (cGH *GH, + int index) { DECLARE_CCTK_PARAMETERS - StreamedHDF5GH *myGH; + ioStreamedHDF5GH *myGH; + char *fullname; const char *varname; + varname = CCTK_VarName (index); - myGH = (StreamedHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("StreamedHDF5")]; + myGH = (ioStreamedHDF5GH *) CCTK_GHExtension (GH, "IOStreamedHDF5"); if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "StreamedHDF5_TriggerOutput: varname, index " - "= (%s, %d)", varname, index); + { + fullname = CCTK_FullName (index); + CCTK_VInfo (CCTK_THORNSTRING, "IOStreamedHDF5_TriggerOutput: " + "output of (varname, fullname) " + "= ('%s', '%s')", varname, fullname); + free (fullname); + } /* Do the output */ - StreamedHDF5_Write (GH, index, varname); + IOStreamedHDF5_Write (GH, index, varname); /* Register variable as having output this iteration */ - myGH->out_last [index] = GH->cctk_iteration; + myGH->out_last[index] = GH->cctk_iteration; return (0); } -/**************************** local functions ******************************/ -static void CheckSteerableParameters (StreamedHDF5GH *myGH) +/***************************************************************************/ +/* local functions */ +/***************************************************************************/ +/*@@ + @routine CheckSteerableParameters + @date Mon Oct 10 2000 + @author Thomas Radke + @desc + Checks if IOStreamedHDF5 steerable parameters were changed + and does appropriate re-evaluation. + @enddesc + + @calls IOHDF5Util_ParseVarsForOutput + + @var myGH + @vdesc Pointer to IOStreamedHDF5 GH + @vtype ioStreamedHDF5GH * + @vio in + @endvar +@@*/ +static void CheckSteerableParameters (ioStreamedHDF5GH *myGH) { DECLARE_CCTK_PARAMETERS int times_set; @@ -265,11 +293,11 @@ static void CheckSteerableParameters (StreamedHDF5GH *myGH) myGH->out_every = outHDF5_every; } - /* re-parse the 'out_vars' parameter if it was changed */ + /* re-parse the 'IOStreamedHDF5::out_vars' parameter if it was changed */ times_set = CCTK_ParameterQueryTimesSet ("out_vars", CCTK_THORNSTRING); if (times_set != out_vars_lastset) { - ParseVarsForOutputH5stream (myGH, out_vars); + IOHDF5Util_ParseVarsForOutput (out_vars, myGH->do_output, myGH->geo_output); /* Save the last setting of 'out_vars' parameter */ out_vars_lastset = times_set; diff --git a/src/Startup.c b/src/Startup.c index 779a051..7404bda 100644 --- a/src/Startup.c +++ b/src/Startup.c @@ -1,213 +1,286 @@ /*@@ @file Startup.c - @date Fri May 21 1999 + @date Mon Jun 19 2000 @author Thomas Radke @desc - Startup routines for StreamedHDF5. + Startup and termination routines for IOStreamedHDF5. @enddesc - @history - @hauthor Thomas Radke @hdate May 21 1999 - @hdesc Just copied from thorn FlexIO. - @endhistory + @version $Id$ @@*/ -#include #include "cctk.h" #include "cctk_Parameters.h" -#include "CactusBase/IOUtil/src/ioGH.h" #include "BetaThorns/Socket/src/SocketUtils.h" -#include "StreamedHDF5GH.h" +#include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h" +#include "ioStreamedHDF5GH.h" #ifdef HAVE_UNISTD_H #include #endif +/* the rcs ID and its dummy function to use it */ +static char *rcsid = "$Id$"; +CCTK_FILEVERSION(BetaThorns_IOStreamedHDF5_Startup_c) -/* prototypes of functions to be registered */ -int StreamedHDF5_OutputGH(cGH *GH); -int StreamedHDF5_TriggerOutput(cGH *GH, int); -int StreamedHDF5_TimeFor(cGH *GH, int); -int StreamedHDF5_OutputVarAs(cGH *GH, const char *var, const char *alias); /* local function prototypes */ -static void *StreamedHDF5_SetupGH (tFleshConfig *config, - int convergence_level, - cGH *GH); -static int StreamedHDF5_InitGH (cGH *GH); +static void *IOStreamedHDF5_SetupGH (tFleshConfig *config, + int convergence_level, + cGH *GH); /*@@ - @routine StreamedHDF5_Startup - @date Fri May 21 1999 + @routine IOStreamedHDF5_Startup + @date Mon Jun 19 2000 @author Thomas Radke @desc - The startup registration routine for StreamedHDF5. - Registers the GH extensions needed for StreamedHDF5 and - the registerable routines used for each method of StreamedHDF5. - StreamedHDF5 does not overload any functions. + The startup registration routine for IOStreamedHDF5. + Registers the GH extensions needed for IOStreamedHDF5 + along with its setup routine. @enddesc - @calls - @calledby CCTK scheduler at STARTUP - @history - - @endhistory + + @calls CCTK_RegisterGHExtensionSetupGH @@*/ -void StreamedHDF5_Startup (void) +void IOStreamedHDF5_Startup (void) { - int IO_GHExtension; - - - if (CCTK_GHExtensionHandle ("IO") < 0) + /* check that thorn IOHDF5Util was activated */ + if (CCTK_GHExtensionHandle ("IOHDF5Util") < 0) { - CCTK_WARN (1, "Thorn IOUtil was not activated. " - "No StreamedHDF5 IO methods will be enabled."); + CCTK_WARN (1, "Thorn IOHDF5Util was not activated. " + "No IOStreamedHDF5 IO methods will be registered."); return; } - /* this check can go as soon as the Stream VFD - comes with the default HDF5 installation */ -#ifndef H5FDstream_H - CCTK_WARN (1, "The Stream VFD is not included in the configured HDF5 " - "installation. No HDF5 stream output will be available !"); + /* FIXME: this check can go as soon as the Stream VFD + comes with the default HDF5 installation */ +#ifndef H5_HAVE_STREAM + CCTK_WARN (1, "The Stream VFD was not configured in your HDF5 installation. " + "No HDF5 streaming IO will be available !"); #else - IO_GHExtension = CCTK_RegisterGHExtension ("StreamedHDF5"); - CCTK_RegisterGHExtensionSetupGH (IO_GHExtension, StreamedHDF5_SetupGH); - CCTK_RegisterGHExtensionInitGH (IO_GHExtension, StreamedHDF5_InitGH); + CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOStreamedHDF5"), + IOStreamedHDF5_SetupGH); #endif } /*@@ - @routine StreamedHDF5_Terminate + @routine IOStreamedHDF5_Terminate @date Mon Jun 19 2000 @author Thomas Radke @desc - StreamedHDF5's termination routine - Closes the socket if it was opened before. + IOStreamedHDF5's termination routine + Closes all open sockets and destroys the timers. @enddesc - @calls - @calledby CCTK scheduler at TERMINATE - @history - - @endhistory + + @calls CCTK_TimerDestroyI + + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar @@*/ -void StreamedHDF5_Terminate (cGH *GH) +void IOStreamedHDF5_Terminate (cGH *GH) { - int handle; - StreamedHDF5GH *myGH; + int i; + ioStreamedHDF5GH *myGH; - handle = CCTK_GHExtensionHandle ("StreamedHDF5"); - myGH = handle >= 0 ? (StreamedHDF5GH *) GH->extensions [handle] : NULL; + myGH = (ioStreamedHDF5GH *) CCTK_GHExtension (GH, "IOStreamedHDF5"); if (myGH) { - if (myGH->socket >= 0) + /* close the data and checkpoint output sockets */ + if (myGH->data_socket >= 0) { - close (myGH->socket); + close (myGH->data_socket); + } + if (myGH->checkpoint_socket >= 0) + { + close (myGH->checkpoint_socket); + } + + /* release allocated timers */ + if (myGH->print_timing_info) + { + for (i = 0; i < IOHDF5_NUM_TIMERS; i++) + { + CCTK_TimerDestroyI (myGH->timers[i]); + } } } } -/*************************** local routines *********************************/ -static void *StreamedHDF5_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH) +/****************************************************************************/ +/* local routines */ +/****************************************************************************/ + /*@@ + @routine IOStreamedHDF5_SetupGH + @date Mon Jun 19 2000 + @author Thomas Radke + @desc + Allocates and sets up IOStreamedHDF5's GH extension structure + @enddesc + + @calls CCTK_RegisterIOMethod + CCTK_RegisterIOMethodOutputGH + CCTK_RegisterIOMethodOutputVarAs + CCTK_RegisterIOMethodTimeToOutput + CCTK_RegisterIOMethodTriggerOutput + Socket_TCPOpenServerSock + Socket_SetNonBlocking + CCTK_TimerCreateI + CCTK_TimerDestroyI + CCTK_TimerResetI + + @var config + @vdesc the CCTK configuration as provided by the flesh + @vtype tFleshConfig * + @vio unused + @endvar + @var convergence_level + @vdesc the convergence level + @vtype int + @vio unused + @endvar + @var GH + @vdesc Pointer to CCTK grid hierarchy + @vtype cGH * + @vio in + @endvar + + @returntype void * + @returndesc + pointer to the allocated GH extension structure + @endreturndesc +@@*/ +static void *IOStreamedHDF5_SetupGH (tFleshConfig *config, + int convergence_level, + cGH *GH) { DECLARE_CCTK_PARAMETERS - int IOMethod; - int numvars, socket; - StreamedHDF5GH *newGH; + int i; + int myproc; + int numvars; + ioStreamedHDF5GH *myGH; - if (CCTK_MyProc (GH) == 0) - { - socket = Socket_TCPOpenServerSock (port); - if (socket < 0) - { - CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, - "Couldn't open TCP server socket on port %d. No HDF5 stream " - "output available !", port); - return (NULL); - } + myproc = CCTK_MyProc (GH); - if (Socket_SetNonBlocking (socket) < 0) - { - CCTK_WARN (1, "Couldn't set socket into non-blocking mode. No HDF5 " - "stream output available !"); - close (socket); - return (NULL); - } - } - else + /* Register IOStreamedHDF5 routines as output methods */ + i = CCTK_RegisterIOMethod ("IOStreamedHDF5"); + CCTK_RegisterIOMethodOutputGH (i, IOStreamedHDF5_OutputGH); + CCTK_RegisterIOMethodOutputVarAs (i, IOStreamedHDF5_OutputVarAs); + CCTK_RegisterIOMethodTimeToOutput (i, IOStreamedHDF5_TimeFor); + CCTK_RegisterIOMethodTriggerOutput (i, IOStreamedHDF5_TriggerOutput); + + /* Register the IOStreamedHDF5 recovery routine to thorn IOUtil */ + if (IOUtil_RegisterRecover ("IOStreamedHDF5 recovery", + IOStreamedHDF5_Recover) < 0) { - socket = -1; + CCTK_WARN (1, "Failed to register IOStreamedHDF5 recovery routine"); } - /* Register StreamedHDF5 routines as output methods */ - IOMethod = CCTK_RegisterIOMethod ("StreamedHDF5"); - CCTK_RegisterIOMethodOutputGH (IOMethod, StreamedHDF5_OutputGH); - CCTK_RegisterIOMethodOutputVarAs (IOMethod, StreamedHDF5_OutputVarAs); - CCTK_RegisterIOMethodTimeToOutput (IOMethod, StreamedHDF5_TimeFor); - CCTK_RegisterIOMethodTriggerOutput (IOMethod, StreamedHDF5_TriggerOutput); - numvars = CCTK_NumVars (); + myGH = (ioStreamedHDF5GH *) malloc (sizeof (ioStreamedHDF5GH)); + myGH->do_output = (char *) malloc (numvars * sizeof (char)); + myGH->geo_output = (ioHDF5Geo_t*) malloc (numvars * sizeof (ioHDF5Geo_t)); + myGH->out_last = (int *) malloc (numvars * sizeof (int)); - newGH = (StreamedHDF5GH *) malloc (sizeof (StreamedHDF5GH)); - newGH->do_output = (char *) malloc (numvars * sizeof (char)); - newGH->geo_output = (StreamGeo_t*) malloc (numvars * sizeof (StreamGeo_t)); - newGH->out_last = (int *) malloc (numvars * sizeof (int)); - newGH->socket = socket; - - /* save the original error printing routine and its argument */ - CACTUS_IOHDF5_ERROR (H5Eget_auto (&newGH->printErrorFn, - &newGH->printErrorFnArg)); - - /* predefine dataspaces for writing scalar and array attributes */ - /* the dimension of the array dataspace is set when used */ - CACTUS_IOHDF5_ERROR (newGH->scalarDataspace = H5Screate (H5S_SCALAR)); - CACTUS_IOHDF5_ERROR (newGH->arrayDataspace = H5Screate (H5S_SIMPLE)); - - /* predefine a IOHDF5_COMPLEX datatype */ - CACTUS_IOHDF5_ERROR (newGH->IOHDF5_COMPLEX = - H5Tcreate (H5T_COMPOUND, sizeof (CCTK_COMPLEX))); - CACTUS_IOHDF5_ERROR (H5Tinsert (newGH->IOHDF5_COMPLEX, "real", - offsetof (CCTK_COMPLEX, Re), IOHDF5_REAL)); - CACTUS_IOHDF5_ERROR (H5Tinsert (newGH->IOHDF5_COMPLEX, "imag", - offsetof (CCTK_COMPLEX, Im), IOHDF5_REAL)); - - /* predefine a C string datatype */ - CACTUS_IOHDF5_ERROR (newGH->IOHDF5_STRING = H5Tcopy (H5T_C_S1)); - - return (newGH); -} - - -static int StreamedHDF5_InitGH (cGH *GH) -{ - DECLARE_CCTK_PARAMETERS - int i, handle; - StreamedHDF5GH *myGH; - + for (i = 0; i < numvars; i++) + { + myGH->out_last[i] = -1; + } - handle = CCTK_GHExtensionHandle ("StreamedHDF5"); - myGH = handle >= 0 ? (StreamedHDF5GH *) GH->extensions [handle] : NULL; - if (handle < 0 || myGH == NULL) - { - CCTK_WARN (1, "Couldn't access GH extension handle\n"); - return (-1); + /* only processor 0 is doing socket I/O */ + myGH->data_socket = -1; + if (myproc == 0) + { + myGH->data_socket = Socket_TCPOpenServerSock (data_port); + if (myGH->data_socket < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Couldn't open TCP server socket on output port %d. " + "No HDF5 streaming output will be available !", data_port); + } + else if (Socket_SetNonBlocking (myGH->data_socket) < 0) + { + CCTK_WARN (1, "Couldn't set output socket into non-blocking mode. " + "No HDF5 streaming output will be available !"); + close (myGH->data_socket); + myGH->data_socket = -1; + } } - /* How often to output */ - myGH->out_every = out_every > 0 ? out_every : -1; - if (outHDF5_every > 0) + /* create timers if timing info was requested */ + myGH->print_timing_info = print_timing_info; + if (myGH->print_timing_info) { - myGH->out_every = outHDF5_every; + for (i = 0; i < IOHDF5_NUM_TIMERS; i++) + { + if ((myGH->timers[i] = CCTK_TimerCreateI ()) < 0) + { + break; + } + } + if (i != IOHDF5_NUM_TIMERS) + { + 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[CP_TOTAL_TIMER]); + CCTK_TimerResetI (myGH->timers[RECOVERY_TIMER]); + } } - for (i = 0; i < CCTK_NumVars (); i++) + /* FIXME: this check can go as soon as the Stream VFD + comes with the default HDF5 installation */ +#ifdef H5_HAVE_STREAM + /* only processor 0 is doing socket I/O */ + myGH->checkpoint_socket = -1; + myGH->checkpoint_fapl = -1; + if (myproc == 0) { - myGH->out_last [i] = -1; + myGH->checkpoint_socket = Socket_TCPOpenServerSock (checkpoint_port); + if (myGH->checkpoint_socket < 0) + { + CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, + "Couldn't open TCP server socket on checkpoint port %d. " + "No IOStreamedHDF5 checkpointing will be available !", + checkpoint_port); + } + else if (Socket_SetNonBlocking (myGH->checkpoint_socket) < 0) + { + CCTK_WARN (1, "Couldn't set checkpoint socket into non-blocking mode. " + "No IOStreamedHDF5 checkpointing will be available !"); + close (myGH->checkpoint_socket); + myGH->checkpoint_socket = -1; + } + else + { + H5FD_stream_fapl_t fapl; + + + /* setup file access property list and select Stream VFD */ + fapl.increment = 0; + fapl.socket = myGH->checkpoint_socket; + fapl.do_socket_io = 1; + fapl.backlog = 5; + fapl.broadcast_fn = NULL; + fapl.broadcast_arg = NULL; + IOHDF5_ERROR (myGH->checkpoint_fapl = H5Pcreate (H5P_FILE_ACCESS)); + IOHDF5_ERROR (H5Pset_fapl_stream (myGH->checkpoint_fapl, &fapl)); + } } +#endif - return (0); + return (myGH); } diff --git a/src/Write.c b/src/Write.c index 5ea8c65..0ce149a 100644 --- a/src/Write.c +++ b/src/Write.c @@ -1,146 +1,148 @@ /*@@ @file Write.c - @date Fri May 21 1999 + @date Tue Oct 10 2000 @author Thomas Radke @desc - Output and trigger routines for FiberBundle output into HDF5 files + File handling routines for IOStreamedHDF5. @enddesc - @history - @hauthor Thomas Radke @hdate May 21 1999 - @hdesc Just copied from thorn FlexIO. - @hendhistory + @version $Id$ @@*/ -#include #include #include "cctk.h" #include "cctk_Parameters.h" #include "StoreNamedData.h" #include "CactusBase/IOUtil/src/ioGH.h" -#include "StreamedHDF5GH.h" +#include "BetaThorns/IOHDF5Util/src/ioHDF5UtilGH.h" +#include "ioStreamedHDF5GH.h" - -/* local function prototypes */ -void StreamedHDF5i_DumpParameters (cGH *GH, hid_t group); -void StreamedHDF5i_DumpGHExtensions (cGH *GH, hid_t group); +/* the rcs ID and its dummy function to use it */ +static char *rcsid = "$Id$"; +CCTK_FILEVERSION(BetaThorns_IOStreamedHDF5_Write_c) /*@@ - @routine Write - @author Paul Walker - @date Feb 1997 - @calledby StreamedHDF5_OutputVarAs, StreamedHDF5_TriggerOutput - @var GH - @vdesc Pointer to CCTK GH - @vtype cGH - @vio in - @vcomment - @endvar - @var index - @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 + @routine IOStreamedHDF5_Write + @date Tue Oct 10 2000 + @author Thomas Radke + @desc + Opens the HDF5 output file, calls the dump routine, + and closes it again. + @enddesc + + @calls IOHDF5Util_DumpVar + + @var GH + @vdesc Pointer to CCTK GH + @vtype cGH * + @vio in + @endvar + @var index + @vdesc index of variable + @vtype int + @vio in + @endvar + @var alias + @vdesc alias name of variable to output + @vtype const char * + @vio in + @endvar @@*/ -void StreamedHDF5_Write (cGH *GH, int index, const char *alias) +void IOStreamedHDF5_Write (cGH *GH, + int index, + const char *alias) { DECLARE_CCTK_PARAMETERS - int vtype; int timelevel; - StreamedHDF5GH *myGH; - hid_t fid, plist; + int old_ioproc; + int old_nioprocs; + int old_ioproc_every; + char *fullname; + ioGH *ioUtilGH; + ioStreamedHDF5GH *myGH; + hid_t file, plist; H5FD_stream_fapl_t fapl; -#if 0 - hid_t group; -#endif /* first, check if variable has storage assigned */ if (! CCTK_QueryGroupStorageI (GH, CCTK_GroupIndexFromVarI (index))) { - char *fullname = CCTK_FullName (index); + fullname = CCTK_FullName (index); CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "No StreamedHDF5 output for '%s' (no storage)", fullname); + "No IOStreamedHDF5 output for '%s' (no storage)", fullname); free (fullname); return; } - /* check if variable is of type GF or ARRAY */ - vtype = CCTK_GroupTypeFromVarI (index); - if (vtype != CCTK_GF && vtype != CCTK_ARRAY) + /* Get the handles for IO and IOStreamedHDF5 extensions */ + ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); + myGH = (ioStreamedHDF5GH *) CCTK_GHExtension (GH, "IOStreamedHDF5"); + + /* for now we can only have IO mode "oneproc" */ + if (ioUtilGH->nioprocs != 1) { - char *fullname = CCTK_FullName (index); - CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING, - "No StreamedHDF5 output for '%s' (not an array type)", fullname); - free (fullname); - return; + CCTK_WARN (2, "Output into multiple chunked files not yet implemented. " + "Switching to IO mode \"oneproc\"."); } - - /* Get the handles for IO and StreamedHDF5 extensions */ - myGH = (StreamedHDF5GH *) GH->extensions [CCTK_GHExtensionHandle ("StreamedHDF5")]; - - fid = -1; - if (CCTK_MyProc (GH) == 0) + old_ioproc = ioUtilGH->ioproc; + ioUtilGH->ioproc = 0; + old_nioprocs = ioUtilGH->nioprocs; + ioUtilGH->nioprocs = 1; + old_ioproc_every = ioUtilGH->ioproc_every; + ioUtilGH->ioproc_every = CCTK_nProcs (GH); + + file = -1; + if (CCTK_MyProc (GH) == 0 && myGH->data_socket >= 0) { - /* filename is not used if we pass a socket descriptor - but it must not be NULL or an empty string */ - static const char *filename = "bla"; - - if (verbose) - CCTK_VInfo (CCTK_THORNSTRING, "Opening HDF5 output file on port %d", - port); + { + CCTK_VInfo (CCTK_THORNSTRING, "Opening HDF5 output file " + "on data output port %d", data_port); + } /* set file access property list to use the Stream VFD and open the file */ fapl.increment = 0; - fapl.socket = myGH->socket; + fapl.socket = myGH->data_socket; fapl.do_socket_io = 1; fapl.backlog = 5; fapl.broadcast_fn = NULL; fapl.broadcast_arg = NULL; - CACTUS_IOHDF5_ERROR (plist = H5Pcreate (H5P_FILE_ACCESS)); - CACTUS_IOHDF5_ERROR (H5Pset_fapl_stream (plist, &fapl)); - CACTUS_IOHDF5_ERROR (fid = H5Fcreate (filename, H5F_ACC_TRUNC, - H5P_DEFAULT, plist)); - CACTUS_IOHDF5_ERROR (H5Pclose (plist)); - -#if 0 - /* output global attributes */ - if (verbose) - CCTK_INFO ("Dumping GH extensions ..."); - - CACTUS_IOHDF5_ERROR (group = H5Gcreate (fid, GHEXTENSIONS_GROUP, 0)); - StreamedHDF5i_DumpGHExtensions (GH, group); - CACTUS_IOHDF5_ERROR (H5Gclose (group)); -#endif + IOHDF5_ERROR (plist = H5Pcreate (H5P_FILE_ACCESS)); + IOHDF5_ERROR (H5Pset_fapl_stream (plist, &fapl)); + /* filename is not used if we pass a plist + but it must not be NULL or an empty string */ + IOHDF5_ERROR (file = H5Fcreate ("unused", H5F_ACC_TRUNC, H5P_DEFAULT, + plist)); + IOHDF5_ERROR (H5Pclose (plist)); } /* get the current timelevel */ timelevel = CCTK_NumTimeLevelsFromVarI (index) - 1; if (timelevel > 0) + { timelevel--; + } /* output the data */ - StreamedHDF5_DumpVar (GH, index, timelevel, fid); + IOHDF5Util_DumpVar (GH, index, timelevel, &myGH->geo_output[index], file, 0); /* close the file */ - if (fid >= 0) + if (file >= 0) { if (verbose) + { CCTK_INFO ("Closing HDF5 output file from this iteration"); - CACTUS_IOHDF5_ERROR (H5Fclose (fid)); + } + IOHDF5_ERROR (H5Fclose (file)); } + /* restore original IO mode */ + ioUtilGH->ioproc = old_ioproc; + ioUtilGH->nioprocs = old_nioprocs; + ioUtilGH->ioproc_every = old_ioproc_every; } diff --git a/src/make.code.defn b/src/make.code.defn index 2cbdc9c..b7876f9 100644 --- a/src/make.code.defn +++ b/src/make.code.defn @@ -2,4 +2,4 @@ # $Header$ # Source files in this directory -SRCS = Startup.c Output.c Write.c DumpVar.c ParseGeometry.c ParseVars.c +SRCS = Startup.c Output.c Write.c DumpGH.c RecoverGH.c -- cgit v1.2.3