aboutsummaryrefslogtreecommitdiff
path: root/src/RestoreFile.c
diff options
context:
space:
mode:
authortradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2000-04-18 12:56:25 +0000
committertradke <tradke@ebee0441-1374-4afa-a3b5-247f3ba15b9a>2000-04-18 12:56:25 +0000
commitee28234767b04fb1cbd05c95378bc8f440ebd8a5 (patch)
tree7bef127550ed3f3b28addc79e0b2d0ab8298d798 /src/RestoreFile.c
parentb0ed0e3770c1dfad68bef66a4a01ec530fc32fa6 (diff)
Several things which I missed to commit individually but rather do it in
one go now: - checkpoint/recover parameters as a single string which could also be used for writing a parameter file - added routine to be scheduled at CCTK_RECOVER_PARAMETERS - automatically select the latest checkpoint file for recovery if IO::recover = "auto" was set - Use IOFlexIO::reuse_filehandles with a different meaning now: By default all IEEEIO output files are kept open all the time. This is the most efficient method for writing data. If you run out of system file handles you can enable this parameter then to use the pause/resume scheme of the IEEEIO lib. - automatically append data sets to already exisiting output files after restart from recovery; duplicate timesteps are **NOT** removed from the output files because IEEEIO lib cannot delete/overwrite individual data sets So the reader has to handle this, it should always choose the latest data set of a given timestep. - fixed rcsid warnings - use CCTK_Info() rather than printf() for giving verbose output git-svn-id: http://svn.cactuscode.org/arrangements/CactusPUGHIO/IOFlexIO/trunk@107 ebee0441-1374-4afa-a3b5-247f3ba15b9a
Diffstat (limited to 'src/RestoreFile.c')
-rw-r--r--src/RestoreFile.c138
1 files changed, 64 insertions, 74 deletions
diff --git a/src/RestoreFile.c b/src/RestoreFile.c
index b3e92d0..43aac82 100644
--- a/src/RestoreFile.c
+++ b/src/RestoreFile.c
@@ -12,7 +12,6 @@
@version $Id$
@@*/
-static char *rcsid = "$Id$";
#include <stdio.h>
#include <stdlib.h>
@@ -32,16 +31,21 @@ static char *rcsid = "$Id$";
#define MAXDIM 10
+/* the rcs ID and its dummy funtion to use it */
+static char *rcsid = "$Id$";
+CCTK_FILEVERSION (CactusPUGHIO_IOFlexIO_RestoreFile_c);
+
+
/* local function prototypes */
-static int GetCommonAttributes (cGH *GH, IOFile ifp, int unchunked, int *index,
+static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *index,
int *grouptype, int *timelevel);
#ifdef CCTK_MPI
-static int GetChunkAttributes (cGH *GH, IOFile ifp, int index);
+static int GetChunkAttributes (cGH *GH, IOFile fid, int index);
#endif
/*@@
- @routine IOFlexIO_RestoreIEEEIOfile
+ @routine IOFlexIO_RecoverVariables
@date Fri Jun 19 09:19:48 1998
@author Tom Goodale
@desc
@@ -65,30 +69,13 @@ static int GetChunkAttributes (cGH *GH, IOFile ifp, int index);
@vtype cGH
@vio in
@endvar
- @var ifp
- @vdesc IEEEIO file pointer
- @vtype IOFile
- @vio in
- @endvar
- @var file_ioproc
- @vdesc for the current processor: the IO processor to receive my data
- from
- @vtype int
- @vio in
- @endvar
- @var file_ioproc_every
- @vdesc number of IO processors to use to read the file
- @vtype int
- @vio in
- @endvar
- @var file_unchunked
- @vdesc flag indicating whether we read from an unchunked file or not
- @vtype int
+ @var file
+ @vdesc IEEEIO file info structure
+ @vtype fileinfo_t *
@vio in
@endvar
@@*/
-int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
- int file_ioproc_every, int file_unchunked)
+int IOFlexIOi_RecoverVariables (cGH *GH, fileinfo_t *file)
{
DECLARE_CCTK_PARAMETERS
int index, gtype;
@@ -103,6 +90,9 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
#endif
+ /* to make the compiler happy */
+ nDatasets = 0;
+
/* Get the handles for PUGH extensions */
pughGH = pugh_pGH (GH);
@@ -110,12 +100,12 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
nprocs = CCTK_nProcs (GH);
/* all IO procs determine the number of datasets in their checkpoint files */
- if (myproc == file_ioproc) {
+ if (myproc == file->ioproc) {
/* Get the number of sets */
- nDatasets = IOnDatasets (ifp);
+ nDatasets = IOnDatasets (file->fid);
if (verbose)
- printf (" Input file has %d datasets\n", nDatasets);
+ CCTK_VInfo (CCTK_THORNSTRING, " Input file has %d datasets", nDatasets);
}
@@ -130,7 +120,7 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
and they are just distributed to the non-IO processors again
during recovery.
- if (nDatasets % file_ioproc_every != 0)
+ if (nDatasets % file->ioproc_every != 0)
CCTK_WARN (0, "Number of datasets isn't a multiple of nioprocs");
*/
@@ -139,18 +129,18 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
verify their contents and communicate them to the non-IO processors. */
/* At first the code for the IO processors ... */
- if (myproc == file_ioproc) {
+ if (myproc == file->ioproc) {
/* 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 (ifp, 0));
+ CACTUS_IEEEIO_ERROR (IOseek (file->fid, 0));
/* Each IO processor loops over all available datasets, checks their
consistency and broadcasts them to the non-IO processors. */
for (currentDataset = 0; currentDataset < nDatasets; currentDataset++) {
/* read in the next dataset's attributes and verify them */
- if (GetCommonAttributes (GH, ifp, file_unchunked, &index,
+ if (GetCommonAttributes (GH, file->fid, file->unchunked, &index,
&gtype, &timelevel) < 0) {
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Ignoring dataset %d", currentDataset);
@@ -161,14 +151,14 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
if (verbose) {
char *fullname = CCTK_FullName (index);
- printf (" dataset %d: %s (timelevel %d)\n", currentDataset,
- fullname, timelevel);
+ CCTK_VInfo (CCTK_THORNSTRING, " dataset %d: %s (timelevel %d)",
+ currentDataset, fullname, timelevel);
free (fullname);
}
- if (file_ioproc_every == 1)
+ if (file->ioproc_every == 1)
CACTUS_IEEEIO_ERROR (
- IOread (ifp, CCTK_VarDataPtrI (GH, timelevel, index)));
+ IOread (file->fid, CCTK_VarDataPtrI (GH, timelevel, index)));
#ifdef CCTK_MPI
else {
int dim, npoints;
@@ -210,16 +200,16 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
/* read my own data directly into data,
read others data into buffer and communicate it */
- if (! file_unchunked || gtype == GROUP_SCALAR)
- CACTUS_IEEEIO_ERROR (
- IOread (ifp, CCTK_VarDataPtrI (GH, timelevel, index)));
+ if (! file->unchunked || gtype == GROUP_SCALAR)
+ CACTUS_IEEEIO_ERROR (IOread (file->fid,
+ CCTK_VarDataPtrI (GH, timelevel, index)));
else {
for (i = 0; i < dim; i++) {
- chunkdims [i] = extras->rnsize [file_ioproc][i];
- chunkorigin [i] = extras->lb [file_ioproc][i];
+ chunkdims [i] = extras->rnsize [file->ioproc][i];
+ chunkorigin [i] = extras->lb [file->ioproc][i];
}
- CACTUS_IEEEIO_ERROR (IOreadChunk (ifp, chunkdims, chunkorigin,
+ CACTUS_IEEEIO_ERROR (IOreadChunk (file->fid, chunkdims, chunkorigin,
CCTK_VarDataPtrI (GH, timelevel, index)));
}
@@ -229,38 +219,38 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
buffer = CCTK_VarDataPtrI (GH, timelevel, index);
} else {
/* allocate memory for the biggest chunk */
- npoints = extras->rnpoints [file_ioproc + 1];
- for (proc = 2; proc < file_ioproc_every; proc++)
- if (npoints < extras->rnpoints [file_ioproc + proc])
- npoints = extras->rnpoints [file_ioproc + proc];
+ npoints = extras->rnpoints [file->ioproc + 1];
+ for (proc = 2; proc < file->ioproc_every; proc++)
+ if (npoints < extras->rnpoints [file->ioproc + proc])
+ npoints = extras->rnpoints [file->ioproc + proc];
buffer = malloc (npoints * element_size);
}
- for (proc = file_ioproc + 1;
- proc < file_ioproc + file_ioproc_every && proc < nprocs;
+ for (proc = file->ioproc + 1;
+ proc < file->ioproc + file->ioproc_every && proc < nprocs;
proc++) {
if (gtype != GROUP_SCALAR) {
- if (! file_unchunked) {
+ if (! file->unchunked) {
/* Also increment dataset counter here !!! */
currentDataset++;
- if (GetChunkAttributes (GH, ifp, index) < 0) {
+ if (GetChunkAttributes (GH, file->fid, index) < 0) {
CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING,
"Ignoring chunk in dataset %d", currentDataset+1);
continue;
}
- CACTUS_IEEEIO_ERROR (IOread (ifp, buffer));
+ CACTUS_IEEEIO_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 (ifp, chunkdims, chunkorigin, buffer));
+ CACTUS_IEEEIO_ERROR (IOreadChunk (file->fid, chunkdims,
+ chunkorigin, buffer));
}
npoints = extras->rnpoints [proc];
@@ -281,7 +271,7 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
free (chunkorigin);
- } /* reading data for file_ioproc_every processors */
+ } /* reading data for file->ioproc_every processors */
#endif
} /* end of loop over all datasets */
@@ -290,8 +280,8 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
/* Finally an invalid variable index is communicated
to indicate completion to the non-IO processors. */
info [0] = -1;
- for (proc = 1; proc < file_ioproc_every; proc++)
- CACTUS_MPI_ERROR (MPI_Send (info, 3, PUGH_MPI_INT, proc + file_ioproc,
+ for (proc = 1; proc < file->ioproc_every; proc++)
+ CACTUS_MPI_ERROR (MPI_Send (info, 3, PUGH_MPI_INT, proc + file->ioproc,
STARTUPBASE, pughGH->PUGH_COMM_WORLD));
#endif
@@ -311,7 +301,7 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
*/
while (1) {
/* receive the next variable index from the IO processor */
- CACTUS_MPI_ERROR (MPI_Recv (info, 3, PUGH_MPI_INT, file_ioproc,
+ CACTUS_MPI_ERROR (MPI_Recv (info, 3, PUGH_MPI_INT, file->ioproc,
STARTUPBASE, pughGH->PUGH_COMM_WORLD, &ms));
index = info [0]; timelevel = info [1]; npoints = info [2];
@@ -334,7 +324,7 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
/* receive following data from my IO processor */
CACTUS_MPI_ERROR (MPI_Recv (CCTK_VarDataPtrI (GH, timelevel, index),
- npoints, mpi_type, file_ioproc,
+ npoints, mpi_type, file->ioproc,
STARTUPBASE, pughGH->PUGH_COMM_WORLD, &ms));
}
#endif
@@ -362,7 +352,7 @@ int IOFlexIO_RestoreIEEEIOfile (cGH *GH, IOFile ifp, int file_ioproc,
to restore are stored in {*index, *grouptype, *timelevel}, and 0 is returned.
*/
-static int GetCommonAttributes (cGH *GH, IOFile ifp, int unchunked, int *index,
+static int GetCommonAttributes (cGH *GH, IOFile fid, int unchunked, int *index,
int *grouptype, int *timelevel)
{
int i, flag;
@@ -378,7 +368,7 @@ static int GetCommonAttributes (cGH *GH, IOFile ifp, int unchunked, int *index,
/* read the next dataset's info from the file */
- result = IOreadInfo (ifp, &vartype_stored, &rank_stored, dims_stored, MAXDIM);
+ result = IOreadInfo (fid, &vartype_stored, &rank_stored, dims_stored, MAXDIM);
CACTUS_IEEEIO_ERROR (result);
if (result == 0) {
CCTK_WARN (1, "Can't read dataset info");
@@ -386,12 +376,12 @@ static int GetCommonAttributes (cGH *GH, IOFile ifp, int unchunked, int *index,
}
/* retrieve the name attribute */
- i = IOreadAttributeInfo (ifp, "name", &atype, &asize);
+ i = IOreadAttributeInfo (fid, "name", &atype, &asize);
if (i < 0 || atype != FLEXIO_CHAR || asize >= sizeof (fullname)) {
CCTK_WARN (2, "Can't read name attribute");
return (-1);
}
- CACTUS_IEEEIO_ERROR (IOreadAttribute (ifp, i, fullname));
+ CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, fullname));
/* check if there is a matching variable */
*index = CCTK_VarIndex (fullname);
@@ -402,13 +392,13 @@ static int GetCommonAttributes (cGH *GH, IOFile ifp, int unchunked, int *index,
}
/* read and verify the group name */
- i = IOreadAttributeInfo (ifp, "groupname", &atype, &asize);
+ i = IOreadAttributeInfo (fid, "groupname", &atype, &asize);
if (i < 0 || atype != FLEXIO_CHAR || asize >= sizeof (groupname_stored)) {
CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
"Can't read groupname attribute of '%s'", fullname);
return (-1);
}
- CACTUS_IEEEIO_ERROR (IOreadAttribute (ifp, i, groupname_stored));
+ CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, groupname_stored));
groupname = CCTK_GroupNameFromVarI (*index);
if (! CCTK_Equals (groupname_stored, groupname)) {
CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
@@ -418,31 +408,31 @@ static int GetCommonAttributes (cGH *GH, IOFile ifp, int unchunked, int *index,
free (groupname);
/* read the group type */
- i = IOreadAttributeInfo (ifp, "grouptype", &atype, &asize);
+ i = IOreadAttributeInfo (fid, "grouptype", &atype, &asize);
if (i < 0 || atype != FLEXIO_INT4 || asize != 1) {
CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
"Can't read grouptype attribute for '%s'", fullname);
return (-1);
}
- CACTUS_IEEEIO_ERROR (IOreadAttribute (ifp, i, &grouptype_stored));
+ CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, &grouptype_stored));
/* read the number of timelevels */
- i = IOreadAttributeInfo (ifp, "ntimelevels", &atype, &asize);
+ i = IOreadAttributeInfo (fid, "ntimelevels", &atype, &asize);
if (i < 0 || atype != FLEXIO_INT4 || asize != 1) {
CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
"Can't read ntimelevels attribute for '%s'", fullname);
return (-1);
}
- CACTUS_IEEEIO_ERROR (IOreadAttribute (ifp, i, &numtimelevels_stored));
+ CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, &numtimelevels_stored));
/* read the timelevel to restore */
- i = IOreadAttributeInfo (ifp, "timelevel", &atype, &asize);
+ i = IOreadAttributeInfo (fid, "timelevel", &atype, &asize);
if (i < 0 || atype != FLEXIO_INT4 || asize != 1) {
CCTK_VWarn (2, __LINE__, __FILE__, CCTK_THORNSTRING,
"Can't read timelevel attribute for '%s'", fullname);
return (-1);
}
- CACTUS_IEEEIO_ERROR (IOreadAttribute (ifp, i, &timelevel_stored));
+ CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, &timelevel_stored));
*timelevel = (int) timelevel_stored;
/* verify group type, variable type, dims, sizes and ntimelevels */
@@ -525,7 +515,7 @@ static int GetCommonAttributes (cGH *GH, IOFile ifp, int unchunked, int *index,
current variable given by its index. */
#ifdef CCTK_MPI
-static int GetChunkAttributes (cGH *GH, IOFile ifp, int index)
+static int GetChunkAttributes (cGH *GH, IOFile fid, int index)
{
int i;
int atype;
@@ -536,7 +526,7 @@ static int GetChunkAttributes (cGH *GH, IOFile ifp, int index)
/* read the next dataset's info from the file */
- result = IOreadInfo (ifp, &vtype_stored, &rank_stored, dims_stored, MAXDIM);
+ result = IOreadInfo (fid, &vtype_stored, &rank_stored, dims_stored, MAXDIM);
CACTUS_IEEEIO_ERROR (result);
if (result == 0) {
CCTK_WARN (1, "Can't read dataset info");
@@ -544,12 +534,12 @@ static int GetChunkAttributes (cGH *GH, IOFile ifp, int index)
}
/* retrieve the name attribute */
- i = IOreadAttributeInfo (ifp, "name", &atype, &asize);
+ i = IOreadAttributeInfo (fid, "name", &atype, &asize);
if (i < 0 || atype != FLEXIO_CHAR || asize >= sizeof (fullname)) {
CCTK_WARN (2, "Can't read name attribute");
return (-1);
}
- CACTUS_IEEEIO_ERROR (IOreadAttribute (ifp, i, fullname));
+ CACTUS_IEEEIO_ERROR (IOreadAttribute (fid, i, fullname));
/* check if there is a matching variable */
if (index != CCTK_VarIndex (fullname)) {