/*@@ @file Startup.c @date Sat Feb 6 1999 @author Gabrielle Allen @desc Startup routines for IOUtil. @enddesc @version $Id$ @@*/ #include "cctk.h" #include "cctk_Misc.h" #include "cctk_Version.h" #include "cctk_Parameters.h" #include "util_Network.h" #include #include #include #include #include #ifdef HAVE_SYS_STAT_H #include #endif #ifdef HAVE_UNISTD_H #include #endif #include "ioGH.h" #include "ioutil_Utils.h" #include "ioutil_AdvertisedFiles.h" /* the rcs ID and its dummy funtion to use it */ static const char *rcsid="$Header$"; CCTK_FILEVERSION(CactusBase_IOUtil_Startup_c) /******************************************************************** ********************* External Routines ********************** ********************************************************************/ void IOUtil_Startup (void); int IOUtil_UpdateParFile (const cGH *GH); int IOUtil_FixParameters (void); int IOUtil_FixRecoveryParameters (void); /******************************************************************** ********************* Internal Typedefs ********************** ********************************************************************/ /* structure defining a single-linked list of parameters (stores the name of the parameter, its stringified value, and its type) */ typedef struct t_param_list { char *name; char *value; const char *format_string; struct t_param_list *next; } t_param_list; /******************************************************************** ********************** Static Routines ********************* ********************************************************************/ static void *SetupGH (tFleshConfig *config, int convergence_level, cGH *GH); static int CopyParFile (int recovered); static int GenerateParFile (int recovered); static int DumpParameters (FILE *outfile); /*@@ @routine IOUtil_Startup @date Sat Feb 6 1999 @author Gabrielle Allen @desc The startup registration routine for IOUtil.
It registers the GH extension "IO" for IOUtil, along with its setup routine. It also advertises the original parameter file. @enddesc @calls CCTK_RegisterGHExtension CCTK_RegisterGHExtensionSetupGH CCTK_ParameterFilename IOUtil_AdvertiseFile @@*/ void IOUtil_Startup (void) { char parfile[256]; ioAdvertisedFileDesc advertised_file; DECLARE_CCTK_PARAMETERS CCTK_RegisterGHExtensionSetupGH (CCTK_RegisterGHExtension ("IO"), SetupGH); /* advertise the parameter file */ parfile[0] = 0; CCTK_ParameterFilename (sizeof (parfile), parfile); advertised_file.slice = ""; advertised_file.thorn = CCTK_THORNSTRING; advertised_file.varname = ""; advertised_file.description = "Parameter File"; advertised_file.mimetype = "text/plain"; IOUtil_AdvertiseFile (NULL, parfile, &advertised_file); } /*@@ @routine IOUtil_UpdateParFile @date Tue 18 Dec 2001 @author Thomas Radke @desc Updates the parameter file for all parameters which got steered during its last invocation. @enddesc @var GH @vdesc pointer to grid hierarchy @vtype const cGH * @vio in @endvar @returntype int @returndesc 0 for success @endreturndesc @@*/ int IOUtil_UpdateParFile (const cGH *GH) { DECLARE_CCTK_PARAMETERS /* check if it's time to update */ if (CCTK_MyProc (GH) > 0 || GH->cctk_iteration % parfile_update_every) { return (0); } CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Not yet implemented: updating parameter file for steered " "parameters up to iteration %d", GH->cctk_iteration); return (0); } int IOUtil_FixRecoveryParameters (void) { static int already_called = 0; DECLARE_CCTK_PARAMETERS if (! already_called) { if (CCTK_ParameterQueryTimesSet ("recovery_dir", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("recover_dir", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::recovery_dir' is deprecated in BETA12, please use " "'IO::recover_dir' instead"); CCTK_ParameterSet ("recover_dir", CCTK_THORNSTRING, recovery_dir); } /* call IOUtil_FixParameters() now if no recovery was requested */ if (CCTK_Equals (recover, "no") || *recover_file == 0 || ! (CCTK_IsThornActive ("IOHDF5") || CCTK_IsThornActive ("IOFlexIO"))) { IOUtil_FixParameters (); } already_called = 1; } return (0); } int IOUtil_FixParameters (void) { char buffer[20]; DECLARE_CCTK_PARAMETERS if (CCTK_ParameterQueryTimesSet ("outdir", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_dir", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::outdir' is deprecated in BETA12, please use " "'IO::out_dir' instead"); CCTK_ParameterSet ("out_dir", CCTK_THORNSTRING, outdir); } if (CCTK_ParameterQueryTimesSet ("out3D_mode", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_mode", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::out3D_mode' is deprecated in BETA12, please use " "'IO::out_mode' instead"); CCTK_ParameterSet ("out_mode", CCTK_THORNSTRING, out3D_mode); } if (CCTK_ParameterQueryTimesSet ("out3D_unchunked", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_unchunked", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::out3D_unchunked' is deprecated in BETA12, please use " "'IO::out_unchunked' instead"); CCTK_ParameterSet ("out_unchunked", CCTK_THORNSTRING, out3D_unchunked ? "yes" : "no"); } if (CCTK_ParameterQueryTimesSet ("out3D_downsample_x", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_downsample_x", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::out3D_downsample_x' is deprecated in BETA12, please use " "'IO::out_downsample_x' instead"); sprintf (buffer, "%d", out3D_downsample_x); CCTK_ParameterSet ("out_downsample_x", CCTK_THORNSTRING, buffer); } if (CCTK_ParameterQueryTimesSet ("out3D_downsample_y", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_downsample_y", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::out3D_downsample_y' is deprecated in BETA12, please use " "'IO::out_downsample_y' instead"); sprintf (buffer, "%d", out3D_downsample_y); CCTK_ParameterSet ("out_downsample_y", CCTK_THORNSTRING, buffer); } if (CCTK_ParameterQueryTimesSet ("out3D_downsample_z", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_downsample_z", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::out3D_downsample_z' is deprecated in BETA12, please use " "'IO::out_downsample_z' instead"); sprintf (buffer, "%d", out3D_downsample_z); CCTK_ParameterSet ("out_downsample_z", CCTK_THORNSTRING, buffer); } if (CCTK_ParameterQueryTimesSet ("out3D_single", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_single_precision", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::out3D_single' is deprecated in BETA12, please use " "'IO::out_single_precision' instead"); CCTK_ParameterSet ("out_single_precision", CCTK_THORNSTRING, out3D_single ? "yes" : "no"); } if (CCTK_ParameterQueryTimesSet ("out3D_parameters", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_save_parameters", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::out3D_parameters' is deprecated in BETA12, please use " "'IO::out_save_parameters' instead"); CCTK_ParameterSet ("out_save_parameters", CCTK_THORNSTRING, out3D_parameters); } if (CCTK_ParameterQueryTimesSet ("out3D_procs", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_proc_every", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::out3D_procs' is deprecated in BETA12, please use " "'IO::out_proc_every' instead"); sprintf (buffer, "%d", out3D_procs); CCTK_ParameterSet ("out_proc_every", CCTK_THORNSTRING, buffer); } if (CCTK_ParameterQueryTimesSet ("out3D_septimefiles", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("out_timesteps_per_file", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::out3D_septimefiles' is deprecated in BETA12, please use " "'IO::out_timesteps_per_file' instead"); CCTK_ParameterSet ("out_timesteps_per_file", CCTK_THORNSTRING, out3D_septimefiles ? "1" : "-1"); } if (CCTK_ParameterQueryTimesSet ("recover_ID_files", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("filereader_ID_files", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::recover_ID_files' is deprecated in BETA12, please use " "'IO::filereader_ID_files' instead"); CCTK_ParameterSet ("filereader_ID_files", CCTK_THORNSTRING, recover_ID_files); } if (CCTK_ParameterQueryTimesSet ("recover_ID_vars", CCTK_THORNSTRING) > CCTK_ParameterQueryTimesSet ("filereader_ID_vars", CCTK_THORNSTRING)) { CCTK_WARN (1, "Parameter 'IO::recover_ID_vars' is deprecated in BETA12, please use " "'IO::filereader_ID_vars' instead"); CCTK_ParameterSet ("filereader_ID_vars", CCTK_THORNSTRING, recover_ID_vars); } if (CCTK_Equals (verbose, "yes") || CCTK_Equals (verbose, "no")) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Setting '%s' for parameter 'IO::verbose' is deprecated in " "BETA12, please use 'none|standard|full' instead", verbose); if (CCTK_Equals (verbose, "yes")) { CCTK_ParameterSet ("verbose", CCTK_THORNSTRING, "standard"); } else { CCTK_ParameterSet ("verbose", CCTK_THORNSTRING, "none"); } } /* parameters of IOASCII */ if (CCTK_IsThornActive ("IOASCII")) { if (CCTK_ParameterQueryTimesSet ("outdir1D", "IOASCII") > CCTK_ParameterQueryTimesSet ("out1D_dir", "IOASCII")) { CCTK_WARN (1, "Parameter 'IOASCII::outdir1D' is deprecated in BETA12, " "please use 'IOASCII::out1D_dir' instead"); CCTK_ParameterSet ("out1D_dir", "IOASCII", *(const char **) CCTK_ParameterGet ("outdir1D", "IOASCII", NULL)); } if (CCTK_ParameterQueryTimesSet ("outdir2D", "IOASCII") > CCTK_ParameterQueryTimesSet ("out2D_dir", "IOASCII")) { CCTK_WARN (1, "Parameter 'IOASCII::outdir2D' is deprecated in BETA12, " "please use 'IOASCII::out2D_dir' instead"); CCTK_ParameterSet ("out2D_dir", "IOASCII", *(const char **) CCTK_ParameterGet ("outdir2D", "IOASCII", NULL)); } if (CCTK_ParameterQueryTimesSet ("outdir3D", "IOASCII") > CCTK_ParameterQueryTimesSet ("out3D_dir", "IOASCII")) { CCTK_WARN (1, "Parameter 'IOASCII::outdir3D' is deprecated in BETA12, " "please use 'IOASCII::out3D_dir' instead"); CCTK_ParameterSet ("out3D_dir", "IOASCII", *(const char **) CCTK_ParameterGet ("outdir3D", "IOASCII", NULL)); } if (CCTK_ParameterQueryTimesSet ("out_style", "IOASCII") > CCTK_ParameterQueryTimesSet ("out1D_style", "IOASCII")) { CCTK_WARN (1, "Parameter 'IOASCII::out_style' is deprecated in BETA12, " "please use 'IOASCII::out1D_style' instead"); CCTK_ParameterSet ("out1D_style", "IOASCII", *(const char **) CCTK_ParameterGet ("out_style", "IOASCII", NULL)); } } /* IOBasic parameters */ if (CCTK_IsThornActive ("IOBasic")) { if (CCTK_ParameterQueryTimesSet ("outdirScalar", "IOBasic") > CCTK_ParameterQueryTimesSet ("out_dir", "IOBasic")) { CCTK_WARN (1, "Parameter 'IOBasic::outdirScalar' is deprecated in BETA12, " "please use 'IOBasic::out_dir' instead"); CCTK_ParameterSet ("out_dir", "IOBasic", *(const char **) CCTK_ParameterGet ("outdirScalar", "IOBasic", NULL)); } } /* IOJpeg parameters */ if (CCTK_IsThornActive ("IOJpeg")) { if (CCTK_ParameterQueryTimesSet ("out2D_dir", "IOJpeg") > CCTK_ParameterQueryTimesSet ("out_dir", "IOJpeg")) { CCTK_WARN (1, "Parameter 'IOJPeg::out2D_dir' is deprecated in BETA12, " "please use 'IOJPeg::out_dir' instead"); CCTK_ParameterSet ("out_dir", "IOJpeg", *(const char **) CCTK_ParameterGet ("out2D_dir", "IOJPeg", NULL)); } if (CCTK_ParameterQueryTimesSet ("out2D_every", "IOJpeg") > CCTK_ParameterQueryTimesSet ("out_every", "IOJpeg")) { CCTK_WARN (1, "Parameter 'IOJPeg::out2D_every' is deprecated in BETA12, " "please use 'IOJPeg::out_every' instead"); sprintf (buffer, "%d", *(const CCTK_INT *) CCTK_ParameterGet ("out2D_every", "IOJPeg", NULL)); CCTK_ParameterSet ("out_every", "IOJpeg", buffer); } if (CCTK_ParameterQueryTimesSet ("out2D_vars", "IOJpeg") > CCTK_ParameterQueryTimesSet ("out_vars", "IOJpeg")) { CCTK_WARN (1, "Parameter 'IOJPeg::out2D_vars' is deprecated in BETA12, " "please use 'IOJPeg::out_vars' instead"); CCTK_ParameterSet ("out_vars", "IOJpeg", *(const char **) CCTK_ParameterGet ("out2D_vars", "IOJPeg", NULL)); } } /* IsoSurfacer parameters */ if (CCTK_IsThornActive ("IsoSurfacer")) { if (CCTK_ParameterQueryTimesSet ("outdir", "IsoSurfacer") > CCTK_ParameterQueryTimesSet ("out_dir", "IsoSurfacer")) { CCTK_WARN (1, "Parameter 'IsoSurfacer::outdir' is deprecated in BETA12, " "please use 'IsoSurfacer::out_dir' instead"); CCTK_ParameterSet ("out_dir", "IsoSurfacer", *(const char **) CCTK_ParameterGet ("outdir", "IsoSurfacer", NULL)); } if (CCTK_ParameterQueryTimesSet ("output_var", "IsoSurfacer") > CCTK_ParameterQueryTimesSet ("out_vars", "IsoSurfacer")) { CCTK_WARN (1, "Parameter 'IsoSurfacer::output_var' is deprecated in BETA12, " "please use 'IsoSurfacer::out_vars' instead"); CCTK_ParameterSet ("out_vars", "IsoSurfacer", *(const char **) CCTK_ParameterGet ("output_var", "IsoSurfacer", NULL)); } if (CCTK_ParameterQueryTimesSet ("output_frequency", "IsoSurfacer") > CCTK_ParameterQueryTimesSet ("out_every", "IsoSurfacer")) { CCTK_WARN (1, "Parameter 'IsoSurfacer::output_frequency' is deprecated in BETA12, " "please use 'IsoSurfacer::out_every' instead"); sprintf (buffer, "%d", *(const CCTK_INT *) CCTK_ParameterGet ("output_frequency", "IsoSurfacer", NULL)); CCTK_ParameterSet ("out_every", "IsoSurfacer", buffer); } if (CCTK_ParameterQueryTimesSet ("output_start", "IsoSurfacer") > CCTK_ParameterQueryTimesSet ("out_start", "IsoSurfacer")) { CCTK_WARN (1, "Parameter 'IsoSurfacer::output_start' is deprecated in BETA12, " "please use 'IsoSurfacer::out_start' instead"); sprintf (buffer, "%d", *(const CCTK_INT *) CCTK_ParameterGet ("output_start", "IsoSurfacer", NULL)); CCTK_ParameterSet ("out_start", "IsoSurfacer", buffer); } if (CCTK_ParameterQueryTimesSet ("output_format", "IsoSurfacer") > CCTK_ParameterQueryTimesSet ("out_format", "IsoSurfacer")) { CCTK_WARN (1, "Parameter 'IsoSurfacer::output_format' is deprecated in BETA12, " "please use 'IsoSurfacer::out_format' instead"); CCTK_ParameterSet ("out_format", "IsoSurfacer", *(const char **) CCTK_ParameterGet ("output_format", "IsoSurfacer", NULL)); } } /* IOFlexIO parameters */ if (CCTK_IsThornActive ("IOFlexIO")) { if (CCTK_ParameterQueryTimesSet ("outdir2D", "IOFlexIO") > CCTK_ParameterQueryTimesSet ("out2D_dir", "IOFlexIO")) { CCTK_WARN (1, "Parameter 'IOFlexIO::outdir2D' is deprecated in BETA12, " "please use 'IOFlexIO::out2D_dir' instead"); CCTK_ParameterSet ("out2D_dir", "IOFlexIO", *(const char **) CCTK_ParameterGet ("outdir2D", "IOFlexIO", NULL)); } if (CCTK_ParameterQueryTimesSet ("outdir3D", "IOFlexIO") > CCTK_ParameterQueryTimesSet ("out_dir", "IOFlexIO")) { CCTK_WARN (1, "Parameter 'IOFlexIO::outdir3D' is deprecated in BETA12, " "please use 'IOFlexIO::out_dir' instead"); CCTK_ParameterSet ("out_dir", "IOFlexIO", *(const char **) CCTK_ParameterGet ("outdir3D", "IOFlexIO", NULL)); } if (CCTK_ParameterQueryTimesSet ("out3D_every", "IOFlexIO") > CCTK_ParameterQueryTimesSet ("out_every", "IOFlexIO")) { CCTK_WARN (1, "Parameter 'IOFlexIO::out3D_every' is deprecated in BETA12, " "please use 'IOFlexIO::out_every' instead"); sprintf (buffer, "%d", *(const CCTK_INT *) CCTK_ParameterGet ("out3D_every", "IOFlexIO", NULL)); CCTK_ParameterSet ("out_every", "IOFlexIO", buffer); } if (CCTK_ParameterQueryTimesSet ("out3D_vars", "IOFlexIO") > CCTK_ParameterQueryTimesSet ("out_vars", "IOFlexIO")) { CCTK_WARN (1, "Parameter 'IOFlexIO::out3D_vars' is deprecated in BETA12, " "please use 'IOFlexIO::out_vars' instead"); CCTK_ParameterSet ("out_vars", "IOFlexIO", *(const char **) CCTK_ParameterGet ("out3D_vars", "IOFlexIO", NULL)); } } /* IOHDF5 parameters */ if (CCTK_IsThornActive ("IOHDF5")) { if (CCTK_ParameterQueryTimesSet ("out3D_vars", "IOHDF5") > CCTK_ParameterQueryTimesSet ("out_vars", "IOHDF5")) { CCTK_WARN (1, "Parameter 'IOHDF5::out3D_vars' is deprecated in BETA12, " "please use 'IOHDF5::out_vars' instead"); CCTK_ParameterSet ("out_vars", "IOHDF5", *(const char **) CCTK_ParameterGet ("out3D_vars", "IOHDF5", NULL)); } if (CCTK_ParameterQueryTimesSet ("outdir3D", "IOHDF5") > CCTK_ParameterQueryTimesSet ("out_dir", "IOHDF5")) { CCTK_WARN (1, "Parameter 'IOHDF5::outdir3D' is deprecated in BETA12, " "please use 'IOHDF5::out_dir' instead"); CCTK_ParameterSet ("out_dir", "IOHDF5", *(const char **) CCTK_ParameterGet ("outdir3D", "IOHDF5", NULL)); } if (CCTK_ParameterQueryTimesSet ("outdir_HDF5", "IOHDF5") > CCTK_ParameterQueryTimesSet ("out_dir", "IOHDF5")) { CCTK_WARN (1, "Parameter 'IOHDF5::outdir_HDF5' is deprecated in BETA12, " "please use 'IOHDF5::out_dir' instead"); CCTK_ParameterSet ("out_dir", "IOHDF5", *(const char **) CCTK_ParameterGet ("outdir_HDF5", "IOHDF5", NULL)); } if (CCTK_ParameterQueryTimesSet ("outHDF5_every", "IOHDF5") > CCTK_ParameterQueryTimesSet ("out_every", "IOHDF5")) { CCTK_WARN (1, "Parameter 'IOHDF5::outHDF5_every' is deprecated in BETA12, " "please use 'IOHDF5::out_every' instead"); sprintf (buffer, "%d", *(const CCTK_INT *) CCTK_ParameterGet ("outHDF5_every", "IOHDF5", NULL)); CCTK_ParameterSet ("out_every", "IOHDF5", buffer); } if (CCTK_ParameterQueryTimesSet ("out3D_every", "IOHDF5") > CCTK_ParameterQueryTimesSet ("out_every", "IOHDF5")) { CCTK_WARN (1, "Parameter 'IOHDF5::out3D_every' is deprecated in BETA12, " "please use 'IOHDF5::out_every' instead"); sprintf (buffer, "%d", *(const CCTK_INT *) CCTK_ParameterGet ("out3D_every", "IOHDF5", NULL)); CCTK_ParameterSet ("out_every", "IOHDF5", buffer); } } return (0); } /******************************************************************** *********************** Local Functions *********************** ********************************************************************/ /*@@ @routine SetupGH @date Tue May 09 2000 @author Thomas Radke @desc The GH allocation and initialization routine for IOUtil.
Necessary output dirs are created, checkpoint/recovery timers are created if timing information is wanted, and a parameter file is written to 'IO::out_dir' if requested. @enddesc @calls IOUtil_CreateDirectory CopyParFile GenerateParFile @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 the pointer to IOUtil's GH extension structure, or
NULL if memory allocation failed @endreturndesc @@*/ static void *SetupGH (tFleshConfig *config, int convergence_level, cGH *GH) { int i, maxdim, myproc; ioGH *newGH; DECLARE_CCTK_PARAMETERS /* avoid compiler warnings about unused parameters */ convergence_level = convergence_level; myproc = CCTK_MyProc (GH); newGH = (ioGH *) malloc (sizeof (ioGH)); if (! newGH) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Couldn't allocate GH extension structure for IOUtil"); return (NULL); } if (CCTK_Equals (out_mode, "proc")) { newGH->ioproc = myproc; newGH->nioprocs = CCTK_nProcs (GH); newGH->ioproc_every = 1; } else if (CCTK_Equals (out_mode, "np")) { if (out_proc_every > CCTK_nProcs (GH)) { newGH->ioproc_every = CCTK_nProcs (GH); CCTK_VInfo (CCTK_THORNSTRING, "Reducing 'IO::out_proc_every' to %d", newGH->ioproc_every); } else { newGH->ioproc_every = out_proc_every; } newGH->nioprocs = CCTK_nProcs (GH) / newGH->ioproc_every + (CCTK_nProcs (GH) % newGH->ioproc_every ? 1 : 0); newGH->ioproc = myproc - (myproc % newGH->ioproc_every); } else /* IO::out_mode = "onefile" */ { newGH->ioproc = 0; newGH->nioprocs = 1; newGH->ioproc_every = CCTK_nProcs (GH); } /* For now we can only have unchunked for a single output file */ if (out_unchunked || CCTK_nProcs (GH) == 1) { if (newGH->ioproc_every >= CCTK_nProcs (GH)) { newGH->unchunked = 1; } else { CCTK_INFO ("Unchunked output not supported for multiple " "output files. Output will be chunked."); newGH->unchunked = 0; } } else { newGH->unchunked = 0; } /* create the default output and checkpoint directories */ i = IOUtil_CreateDirectory (GH, out_dir, 0, 0); if (i < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Problem creating default output directory '%s'", out_dir); } else if (i > 0 && CCTK_Equals (verbose, "full")) { CCTK_VInfo (CCTK_THORNSTRING, "default output directory '%s' already exists", out_dir); } i = IOUtil_CreateDirectory (GH, checkpoint_dir, ! CCTK_Equals (out_mode, "onefile"), newGH->ioproc); if (i < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Problem creating checkpoint directory '%s'", checkpoint_dir); } else if (i > 0 && CCTK_Equals (verbose, "full")) { CCTK_VInfo (CCTK_THORNSTRING, "checkpoint directory '%s' already exists", checkpoint_dir); } /* save downsampling parameters in ioUtilGH because they are temporarily reset during checkpointing */ /* for now we have only parameters for the first 3 dimensions the rest is constantly initialized to 1 */ maxdim = CCTK_MaxDim (); newGH->downsample = (int *) malloc (maxdim * sizeof (int)); switch (maxdim > 3 ? 3 : maxdim) { case 3 : newGH->downsample [2] = out_downsample_z; case 2 : newGH->downsample [1] = out_downsample_y; case 1 : newGH->downsample [0] = out_downsample_x; } for (i = 3; i < maxdim; i++) { newGH->downsample [i] = 1; } /* evaluate the 'IO::out_single_precision' parameter only if Cactus was compiled with double precision */ #ifdef SINGLE_PRECISION newGH->out_single = 0; #else newGH->out_single = out_single_precision; #endif /* copy the 'recovered' flag to this GH extension */ newGH->recovered = config->recovered; /* reset the flags array for the file reader */ newGH->do_inVars = NULL; /* write the parameter file if requested */ if (myproc == 0) { if (CCTK_Equals (parfile_write, "copy")) { CopyParFile (newGH->recovered); } else if (CCTK_Equals (parfile_write, "generate")) { GenerateParFile (newGH->recovered); } } return (newGH); } /*@@ @routine CopyParFile @date Tue 18 Dec 2001 @author Thomas Radke @desc Copies the original parameter file to a new one in 'IO::out_dir'. Note that the new parameter file will usually overwrite an existing file unless - the new parameter file is identical with the original one - this is a recovery run @enddesc @calls CCTK_ParameterFilename @returntype int @returndesc 0 for success, or
-1 if original parameter file couldn't be opened for reading,
-2 if new parameter file couldn't be opened for writing
@endreturndesc @@*/ static int CopyParFile (int recovered) { int in_parfile, out_parfile, bytes, flags; char *out_parfilename, buffer[256]; const char *my_parfile_name; struct stat in_stat_buf, out_stat_buf; DECLARE_CCTK_PARAMETERS /* get the name of the original parfile and open it for reading */ CCTK_ParameterFilename (sizeof (buffer), buffer); in_parfile = open (buffer, O_RDONLY); if (in_parfile < 0) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Couldn't open original parameter file '%s' (%s)", buffer, strerror (errno)); return (-1); } /* use the file mode of the original parfile to create the new one */ if (fstat (in_parfile, &in_stat_buf)) { in_stat_buf.st_mode = 0644; } /* build the name of the output parfile */ my_parfile_name = parfile_name; if (! *my_parfile_name) { /* cut off any path names */ my_parfile_name = strrchr (buffer, '/'); if (my_parfile_name) { my_parfile_name++; } else { my_parfile_name = buffer; } } out_parfilename = malloc (strlen (out_dir) + strlen (my_parfile_name) + 2); sprintf (out_parfilename, "%s/%s", out_dir, my_parfile_name); /* check whether input and output files are identical */ if (! stat (out_parfilename, &out_stat_buf) && in_stat_buf.st_ino == out_stat_buf.st_ino) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Parameter file '%s' to be written into directory '%s' is " "identical with original parameter file. Parameter file will " "not be copied.", my_parfile_name, out_dir); out_parfile = 0; } else { /* binary-copy the input parfile to the output parfile */ flags = O_CREAT | O_TRUNC | O_WRONLY; if (recovered) { flags |= O_EXCL; } out_parfile = open (out_parfilename, flags, in_stat_buf.st_mode); if (out_parfile >= 0) { while ((bytes = read (in_parfile, buffer, sizeof (buffer))) > 0) { write (out_parfile, buffer, bytes); } close (out_parfile); } else { CCTK_VWarn (3, __LINE__, __FILE__, CCTK_THORNSTRING, "Couldn't write parameter file '%s' (%s)", out_parfilename, strerror (errno)); } } /* clean up */ close (in_parfile); free (out_parfilename); return (out_parfile >= 0 ? 0 : -2); } /*@@ @routine DumpParameters @date Tue 18 Dec 2001 @author Thomas Radke @desc Generates a new parameter file in 'IO::out_dir' with an ActiveThorns list and a sorted list of all active parameters which have been set in the original parameter file.
Note that the new parameter file will usually overwrite an existing file unless - the new parameter file is identical with the original one - this is a recovery run @enddesc @calls CCTK_ParameterFilename @var recovered @vdesc flag indicating whether this is a recovery run @vtype int @vio in @endvar @returntype int @returndesc 0 for success, or
-1 if original parameter file couldn't be stat(2),
-2 if new parameter file couldn't be opened for writing
@endreturndesc @@*/ static int GenerateParFile (int recovered) { FILE *outfile; int out_parfile, flags; char *out_parfilename, buffer[256]; const char *my_parfile_name; struct stat in_stat_buf, out_stat_buf; DECLARE_CCTK_PARAMETERS /* get the name of the original parfile and stat(2) it */ CCTK_ParameterFilename (sizeof (buffer), buffer); if (stat (buffer, &in_stat_buf)) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Couldn't stat(2) original parameter file '%s' (%s)", buffer, strerror (errno)); return (-1); } /* build the name of the output parfile */ my_parfile_name = parfile_name; if (! *my_parfile_name) { /* cut off any path names */ my_parfile_name = strrchr (buffer, '/'); if (my_parfile_name) { my_parfile_name++; } else { my_parfile_name = buffer; } } out_parfilename = malloc (strlen (out_dir) + strlen (my_parfile_name) + 2); sprintf (out_parfilename, "%s/%s", out_dir, my_parfile_name); /* check whether input and output files are identical */ if (! stat (out_parfilename, &out_stat_buf) && in_stat_buf.st_ino == out_stat_buf.st_ino) { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Parameter file '%s' to be written into directory '%s' is " "identical with original parameter file. Parameter file will " "not be generated.", my_parfile_name, out_dir); out_parfile = 0; } else { flags = O_CREAT | O_TRUNC | O_WRONLY; if (recovered) { flags |= O_EXCL; } out_parfile = open (out_parfilename, flags, in_stat_buf.st_mode); if (out_parfile >= 0) { outfile = fdopen (out_parfile, "w"); } if (out_parfile >= 0 && outfile) { fprintf (outfile, "# '%s' automatically generated by Cactus version %s\n", out_parfilename, CCTK_FullVersion ()); fprintf (outfile, "# Original parameter file was '%s'\n", buffer); Util_CurrentTime (sizeof (buffer), buffer); fprintf (outfile, "# Run time/date was %s ", buffer); Util_CurrentDate (sizeof (buffer), buffer); fprintf (outfile, "%s ", buffer); Util_GetHostName (buffer, sizeof (buffer)); fprintf (outfile, "on host '%s' with %d processor(s)\n\n", buffer, CCTK_nProcs (NULL)); DumpParameters (outfile); fclose (outfile); } else { CCTK_VWarn (3, __LINE__, __FILE__, CCTK_THORNSTRING, "Couldn't write parameter file '%s' (%s)", out_parfilename, strerror (errno)); } if (out_parfile >= 0) { close (out_parfile); } } /* clean up */ free (out_parfilename); return (out_parfile >= 0 ? 0 : -2); } /*@@ @routine DumpParameters @date Thu Oct 25 2001 @author Thomas Radke @desc Dumps parameter settings of all active thorns into a file. @enddesc @calls CCTK_NumCompiledThorns CCTK_CompiledThorn CCTK_IsThornActive CCTK_ParameterWalk CCTK_ParameterValString @var parfile @vdesc open file descriptor for the output file @vtype FILE * @vio out @endvar @returntype int @returndesc 0 for success, or
-1 if file descriptor is invalid @endreturndesc @@*/ static int DumpParameters (FILE *outfile) { int thorn, first, num_thorns; int len, maxname_len; const char *thornname; char *param; const cParamData *pdata; t_param_list *list, *last, *new; const char *quoted_format = "%s::%-*s = \"%s\"\n", *non_quoted_format = "%s::%-*s = %s\n"; /* check passed file descriptor */ if (outfile == NULL) { return (-1); } num_thorns = CCTK_NumCompiledThorns (); /* loop over all thorns to print the 'ActiveThorns' list */ first = 1; fputs ("ActiveThorns = \"", outfile); for (thorn = 0; thorn < num_thorns; thorn++) { thornname = CCTK_CompiledThorn (thorn); /* skip all inactive thorns and "Cactus" */ if (strcmp ("Cactus", thornname) && CCTK_IsThornActive (thornname)) { if (! first) { putc (' ', outfile); } fputs (thornname, outfile); first = 0; } } fputs ("\"\n", outfile); /* loop over all thorns */ for (thorn = 0; thorn < num_thorns; thorn++) { thornname = CCTK_CompiledThorn (thorn); /* skip all inactive thorns */ if (! CCTK_IsThornActive (thornname)) { continue; } /* now walk through all parameters of given thorn */ maxname_len = 0; list = last = NULL; first = 1; while (CCTK_ParameterWalk (first, thornname, ¶m, &pdata) == 0) { first = 0; /* skip the parameters which weren't explicitely set */ if (pdata->n_set > 0) { new = (t_param_list *) malloc (sizeof (t_param_list)); if (new) { new->value = CCTK_ParameterValString (pdata->name, pdata->thorn); if (new->value) { new->format_string = pdata->type == PARAMETER_INT || pdata->type == PARAMETER_REAL ? non_quoted_format : quoted_format; new->name = pdata->name; len = strlen (new->name); if (len > maxname_len) { maxname_len = len; } if (last) { last->next = new; last = new; } else { list = last = new; } last->next = NULL; } else { CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Couldn't get value for parameter '%s'", param); free (new); } } else { CCTK_WARN (1, "Couldn't allocate list element"); } } free (param); } /* end of loop walking over all parameters of given thorn */ /* finally dump out the list for this thorn */ if (list) { fprintf (outfile, "\n# Parameters of thorn %s (implementing %s)\n", thornname, CCTK_ThornImplementation (thornname)); } while (list) { fprintf (outfile, list->format_string, thornname, maxname_len, list->name, list->value); free (list->value); last = list->next; free (list); list = last; } } /* end of looping over all thorns */ return (0); }