/*@@ @file Write.c @date Tue Oct 10 2000 @author Thomas Radke @desc File handling routines for IOStreamedHDF5. @enddesc @version $Id$ @@*/ #include #include "cctk.h" #include "cctk_Parameters.h" #include "StoreNamedData.h" #include "CactusBase/IOUtil/src/ioGH.h" #include "BetaThorns/IOHDF5Util/src/ioHDF5UtilGH.h" #include "ioStreamedHDF5GH.h" /* the rcs ID and its dummy function to use it */ static char *rcsid = "$Id$"; CCTK_FILEVERSION(BetaThorns_IOStreamedHDF5_Write_c) /*@@ @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 vindex @vdesc index of variable @vtype int @vio in @endvar @var alias @vdesc alias name of variable to output @vtype const char * @vio unused @endvar @@*/ void IOStreamedHDF5_Write (cGH *GH, int vindex, const char *alias) { DECLARE_CCTK_PARAMETERS int timelevel; 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; /* suppress compiler warnings about unused variables */ alias = alias; /* first, 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 IOStreamedHDF5 output for '%s' (no storage)", fullname); free (fullname); return; } /* 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) { CCTK_WARN (2, "Output into multiple chunked files not yet implemented. " "Switching to IO mode \"oneproc\"."); } 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) { if (verbose) { 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->data_socket; fapl.do_socket_io = 1; fapl.backlog = 5; fapl.broadcast_fn = NULL; fapl.broadcast_arg = NULL; 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 (vindex) - 1; /* output the data */ IOHDF5Util_DumpVar (GH, vindex, timelevel, myGH->geo_output[vindex], file, 0); /* close the file */ if (file >= 0) { if (verbose) { CCTK_INFO ("Closing HDF5 output file from this iteration"); } IOHDF5_ERROR (H5Fclose (file)); } /* restore original IO mode */ ioUtilGH->ioproc = old_ioproc; ioUtilGH->nioprocs = old_nioprocs; ioUtilGH->ioproc_every = old_ioproc_every; }