/*@@ @file Startup.c @date Fri May 21 1999 @author Thomas Radke @desc Startup and termination routines for IOHDF5. @enddesc @version $Id$ @@*/ #include #include #include "cctk.h" #include "cctk_Parameters.h" #include "CactusBase/IOUtil/src/ioGH.h" #include "CactusBase/IOUtil/src/ioutil_Utils.h" #include "CactusBase/IOUtil/src/ioutil_CheckpointRecovery.h" #include "ioHDF5GH.h" /* the rcs ID and its dummy function to use it */ static const char *rcsid = "$Id$"; CCTK_FILEVERSION(AlphaThorns_IOHDF5_Startup_c) /* local function prototypes */ void IOHDF5_Startup (void); static void *IOHDF5_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH); /*@@ @routine IOHDF5_Startup @date Fri May 21 1999 @author Thomas Radke @desc The startup registration routine for IOHDF5. Registers the GH extensions needed for IOHDF5 along with its setup routine. @enddesc @calls CCTK_RegisterGHExtensionSetupGH @@*/ void IOHDF5_Startup (void) { /* check that thorn IOHDF5Util was activated */ if (CCTK_GHExtensionHandle ("IOHDF5Util") < 0) { CCTK_WARN (1, "Thorn IOHDF5Util was not activated. " "No IOHDF5 IO methods will be registered."); return; } CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IOHDF5"), IOHDF5_SetupGH); } /****************************************************************************/ /* local routines */ /****************************************************************************/ /*@@ @routine IOHDF5_SetupGH @date Mon Jun 19 2000 @author Thomas Radke @desc Allocates and sets up IOHDF5's GH extension structure. @enddesc @calls CCTK_RegisterIOMethod CCTK_RegisterIOMethodOutputGH CCTK_RegisterIOMethodOutputVarAs CCTK_RegisterIOMethodTimeToOutput CCTK_RegisterIOMethodTriggerOutput CCTK_TimerCreate CCTK_TimerDestroyI CCTK_TimerResetI IOUtil_CreateDirectory @var config @vdesc the CCTK configuration as provided by the flesh @vtype tFleshConfig * @vio usused @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 *IOHDF5_SetupGH (tFleshConfig *config, int convergence_level, cGH *GH) { DECLARE_CCTK_PARAMETERS int i; int numvars; ioGH *ioUtilGH; ioHDF5GH *myGH; const char *timer_names[4] = {"IOHDF5 time to dump parameters", "IOHDF5 time to dump variables", "IOHDF5 total time to checkpoint", "IOHDF5 time to recover"}; /* suppress compiler warnings about unused variables */ config = config; convergence_level = convergence_level; /* Register the IOHDF5 routines as a new IO method */ i = CCTK_RegisterIOMethod ("IOHDF5"); CCTK_RegisterIOMethodOutputGH (i, IOHDF5_OutputGH); CCTK_RegisterIOMethodOutputVarAs (i, IOHDF5_OutputVarAs); CCTK_RegisterIOMethodTimeToOutput (i, IOHDF5_TimeFor); CCTK_RegisterIOMethodTriggerOutput (i, IOHDF5_TriggerOutput); /* Register the IOHDF5 recovery routine to thorn IOUtil */ if (IOUtil_RegisterRecover ("IOHDF5 recovery", IOHDF5_Recover) < 0) { CCTK_WARN (1, "Failed to register IOHDF5 recovery routine"); } numvars = CCTK_NumVars (); myGH = (ioHDF5GH *) malloc (sizeof (ioHDF5GH)); myGH->out_last = (int *) malloc (numvars * sizeof (int)); myGH->out_geo = (ioHDF5Geo_t **) calloc (numvars, sizeof (ioHDF5Geo_t *)); myGH->check_exisiting_objects = (char *) calloc (numvars, 1); myGH->cp_filename_list = (char **) calloc (checkpoint_keep, sizeof (char *)); myGH->cp_filename_index = 0; /* Check whether "IOHDF5::outdir_HDF5" was set. If so take this directory otherwise default to "IO::outdir" */ if (CCTK_ParameterQueryTimesSet ("outdir_HDF5", CCTK_THORNSTRING) > 0) { myGH->outdir = strdup (outdir_HDF5); } else { myGH->outdir = strdup (outdir); } /* Create the output directory */ ioUtilGH = (ioGH *) CCTK_GHExtension (GH, "IO"); i = IOUtil_CreateDirectory (GH, myGH->outdir, ! CCTK_Equals (out3D_mode, "onefile"), ioUtilGH->ioproc); if (i < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Problem creating HDF5 output directory '%s'", myGH->outdir); } else if (i > 0 && CCTK_Equals (newverbose, "full")) { CCTK_VInfo (CCTK_THORNSTRING, "HDF5 output directory '%s' already exists", myGH->outdir); } for (i = 0; i < numvars; i++) { myGH->out_last [i] = -1; } myGH->open_output_files = NULL; /* create timers if timing info was requested */ myGH->print_timing_info = print_timing_info; if (myGH->print_timing_info) { for (i = 0; i < IOHDF5_NUM_TIMERS; i++) { if ((myGH->timers[i] = CCTK_TimerCreate (timer_names[i])) < 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]); } } return (myGH); }