/*@@ @file DumpVar.c @desc Do the actual writing of a 3D grid function, for output or for checkpointing @enddesc @history @hauthor Gabrielle Allen @hdate Oct 17 1998 @hdesc Split into subroutines and tidied. @hauthor Gabrielle Allen @hdate 19 Oct 1998 @hdesc Changed names ready for thorn_IO @hauthor Thomas Radke @hdate 16 Mar 1999 @hdesc Converted to Cactus 4.0 introduced separate downsample values for each dimension @hauthor Thomas Radke @hdate 17 Mar 1999 @hdesc Changed naming: IEEEIO -> IOFlexIO @hauthor Thomas Radke @hdate 17 Mar 1999 @hdesc fixed errors for MPI @hauthor Thomas Radke @hdate 12 Apr 1999 @hdesc Store full variable name in IOFlexIO_AddCommonAttributes() @hauthor Thomas Radke @hdate 16 Apr 1999 @hdesc Added groupname, grouptype, ntimelevels, and current timelevel as common attributes @hendhistory @version $Id$ @@*/ #include #include #ifdef SGI #include #endif #include "cctk.h" #include "cctk_Parameters.h" #include "CactusPUGH/PUGH/src/include/pugh.h" #include "CactusBase/IOUtil/src/ioGH.h" #include "ioFlexGH.h" #define IOTAGBASE 20000 /* This may break on more than 2000 processors */ /*#define IOFLEXIO_DEBUG 1 */ /* the rcs ID and its dummy funtion to use it */ static char *rcsid = "$Id$"; CCTK_FILEVERSION(CactusPUGHIO_IOFlexIO_DumpVar_c) /* info structure describing how to dump a given CCTK variable type */ typedef struct { int flexio_type; /* the FLEXIO type to use */ int element_size; /* size of a single data element */ #ifdef CCTK_MPI MPI_Datatype mpi_type; /* the data type for MPI communication */ #endif } dumpInfo_t; static char *char_time_date = NULL; /* local function prototypes */ static void IOFlexIO_DumpGS (cGH *GH, int index, int timelevel, IOFile iof, int flexio_type); static void IOFlexIO_DumpGA (cGH *GH, int index, int timelevel, IOFile iof, dumpInfo_t *info); static void IOFlexIO_getDumpData (cGH *GH, int index, int timelevel, void **outme, int *free_outme, CCTK_INT4 *geom, int element_size); static void IOFlexIO_eachProcDump (cGH *GH, int index, int timelevel, void *outme, CCTK_INT4 *geom, IOFile iof, int flexio_type); static void IOFlexIO_AddChunkAttributes (cGH *GH, int index, CCTK_INT4 *geom, IOFile iof); static void IOFlexIO_AddCommonAttributes (cGH *GH, int index, int timelevel, CCTK_INT4 *gsz, IOFile iof); #ifdef CCTK_MPI static void IOFlexIO_procDump (IOFile iof, cGH *GH, int index, void *outme, CCTK_INT4 *geom, int flexio_type); #endif /*@@ @routine IOFlexIO_DumpVar @date 16 Apr 1999 @author Thomas Radke @desc Generic dump routine, just calls the appropriate dump routine @enddesc @calls @calledby IOFlexIO_DumpGH IOFlexIO_Write3D @var GH @vdesc Pointer to CCTK grid hierarchy @vtype cGH @vio in @endvar @var index @vdesc global index of the variable to be dumped @vtype int @vio in @endvar @var timelevel @vdesc the timelevel to store @vtype int @vio in @endvar @var iof @vdesc the IEEEIO file to dump to @vtype IOFile @vio in @endvar @history @endhistory @@*/ void IOFlexIO_DumpVar (cGH *GH, int index, int timelevel, IOFile iof) { ioGH *ioUtilGH; int variable_type; dumpInfo_t info; /* Get the handle for IOUtil extensions */ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; variable_type = CCTK_VarTypeI (index); switch (variable_type) { case CCTK_VARIABLE_REAL: info.flexio_type = ioUtilGH->out_single ? FLEXIO_REAL4 : FLEXIO_REAL; info.element_size = ioUtilGH->out_single ? sizeof (CCTK_REAL4) : sizeof (CCTK_REAL); #ifdef CCTK_MPI info.mpi_type = ioUtilGH->out_single ? PUGH_MPI_REAL4 : PUGH_MPI_REAL; #endif break; case CCTK_VARIABLE_INT: info.flexio_type = FLEXIO_INT; info.element_size = sizeof (CCTK_INT); #ifdef CCTK_MPI info.mpi_type = PUGH_MPI_INT; #endif break; case CCTK_VARIABLE_CHAR: info.flexio_type = FLEXIO_CHAR; info.element_size = sizeof (CCTK_CHAR); #ifdef CCTK_MPI info.mpi_type = PUGH_MPI_CHAR; #endif break; #if 0 /* FIXME: Don't know how to support COMPLEX types too !! */ case CCTK_VARIABLE_COMPLEX: info.flexio_type = ioUtilGH->out_single ? FLEXIO_REAL4 : FLEXIO_REAL; info.element_size = ioUtilGH->out_single ? 2 * sizeof (CCTK_REAL4) : 2 * sizeof (CCTK_REAL); #ifdef CCTK_MPI info.mpi_type = ioUtilGH->out_single ? PUGH_MPI_REAL4 : PUGH_MPI_REAL; #endif break; #endif default: CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Unsupported variable type %d", variable_type); return; } switch (CCTK_GroupTypeFromVarI (index)) { case GROUP_SCALAR: IOFlexIO_DumpGS (GH, index, timelevel, iof, info.flexio_type); break; case GROUP_GF: case GROUP_ARRAY: IOFlexIO_DumpGA (GH, index, timelevel, iof, &info); break; default: CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "Invalid group type %d", CCTK_GroupTypeFromVarI (index)); return; } } /************************** local routines ******************************/ /*@@ @routine IOFlexIO_DumpGS @date 16 Apr 1999 @author Thomas Radke @desc Dumps a SCALAR type variable into a IEEEIO file @enddesc @calls @calledby IOFlexIO_DumpVar @var GH @vdesc Pointer to CCTK grid hierarchy @vtype cGH @vio in @endvar @var index @vdesc global index of the variable to be dumped @vtype int @vio in @endvar @var timelevel @vdesc the timelevel to store @vtype int @vio in @endvar @var iof @vdesc the IEEEIO file to dump to @vtype IOFile @vio in @endvar @var flexio_type @vdesc the IOFlexIO datatype to store @vtype int @vio in @endvar @history @endhistory @@*/ static void IOFlexIO_DumpGS (cGH *GH, int index, int timelevel, IOFile iof, int flexio_type) { ioGH *ioUtilGH; CCTK_INT gsz [] = {0, 0, 0}; /* not needed here ? */ const int dim [] = {1}; /* size of scalar */ /* Get the handle for IOUtil extensions */ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; if (CCTK_MyProc (GH) != ioUtilGH->ioproc) return; /* first dump the data then add the attributes */ CACTUS_IEEEIO_ERROR (IOwrite (iof, flexio_type, 1, dim, CCTK_VarDataPtrI (GH, timelevel, index))); IOFlexIO_AddCommonAttributes (GH, index, timelevel, gsz, iof); } /*@@ @routine IOFlexIO_DumpGA @date July 1998 @author Paul Walker @desc @enddesc @calls @calledby IOFlexIO_DumpVar @var GH @vdesc Pointer to CCTK grid hierarchy @vtype cGH @vio in @endvar @var index @vdesc global index of the variable to be dumped @vtype int @vio in @endvar @var timelevel @vdesc the timelevel to store @vtype int @vio in @endvar @var iof @vdesc the IEEEIO file to dump to @vtype IOFile @vio in @endvar @var info @vdesc info structure describing - the IOFlexIO datatype to store - the size of an element of variable - the MPI datatype to communicate @vtype dumpInfo_t @vio in @endvar @history @endhistory @@*/ static void IOFlexIO_DumpGA (cGH *GH, int index, int timelevel, IOFile iof, dumpInfo_t *info) { DECLARE_CCTK_PARAMETERS ioGH *ioUtilGH; pGH *pughGH; int myproc; int nprocs; int dim; CCTK_INT4 *geom; /* Lower bounds, size and global size of data we send */ void *outme; /* pointer to the data to be dumped */ int free_outme; /* indicates whether data buffer needs freeing */ #ifdef SGI /* Get the date if we can */ time_t t = time (NULL); char_time_date = asctime (localtime (&t)); #endif #ifdef CCTK_MPI int i, j; MPI_Status ms; #endif /* Get the handles for PUGH and IO extensions */ pughGH = PUGH_pGH (GH); ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; myproc = CCTK_MyProc (GH); nprocs = CCTK_nProcs (GH); /* get the dimension of the variable */ dim = CCTK_GroupDimI (CCTK_GroupIndexFromVarI (index)); /* allocate the geometry buffer */ geom = (CCTK_INT *) malloc (3*dim * sizeof (CCTK_INT)); /* Get the pointer to the data we want to output (includes downsampling) */ IOFlexIO_getDumpData (GH, index, timelevel, &outme, &free_outme, geom, info->element_size); if (ioUtilGH->ioproc_every == 1) { /* * OUTPUT ON EVERY PROCESSOR */ IOFlexIO_eachProcDump (GH, index, timelevel, outme, geom, iof, info->flexio_type); } #ifdef CCTK_MPI else if (myproc != ioUtilGH->ioproc) { int outgoing = geom [dim]; for (i = 1; i < dim; i++) outgoing *= geom [dim + i]; /* * OUTPUT ON A SUBSET OF PROCESSORS */ /* Send the geometry and data from the processors which aren't * outputing to the ones that are */ /* GEOMETRY SEND */ CACTUS_MPI_ERROR (MPI_Send (geom, 3*dim, PUGH_MPI_INT4, ioUtilGH->ioproc, 2*myproc+IOTAGBASE+1, pughGH->PUGH_COMM_WORLD)); /* DATA SEND */ CACTUS_MPI_ERROR (MPI_Send (outme, outgoing, info->mpi_type, ioUtilGH->ioproc, 2*myproc+IOTAGBASE, pughGH->PUGH_COMM_WORLD)); #ifdef IOFLEXIO_DEBUG printf ("Sent %d data points\n", outgoing); fflush (stdout); #endif } else if (myproc == ioUtilGH->ioproc) { int *lsz = (int *) malloc (dim * sizeof (int)); /* First calculate the local size and reserve the chunk */ if (ioUtilGH->ioproc_every >= nprocs) { /* One output file ... the local chunk size is the global size */ for (i = 0; i < dim; i++) lsz [i] = geom [2*dim + i]; } /* Dump data held on output processor */ if (ioUtilGH->unchunked) IOreserveChunk (iof, info->flexio_type, dim, lsz); free (lsz); /* first the data then the attributes */ IOFlexIO_procDump (iof, GH, index, outme, geom, info->flexio_type); /* delay adding attributes for unchunked files until all chunks were written (otherwise attributes get lost !) */ if (! ioUtilGH->unchunked) IOFlexIO_AddCommonAttributes (GH, index, timelevel, &geom [dim], iof); /* Dump data from all other processors */ for (i = myproc+1; i < myproc+ioUtilGH->ioproc_every && i < nprocs; i++) { /* Allocate temp to the right size (based on GH->ub [i] et..) */ void *tmpd; int incoming; /* Receive bounds information */ CACTUS_MPI_ERROR (MPI_Recv (geom, 3*dim, PUGH_MPI_INT4, i,2*i+IOTAGBASE+1, pughGH->PUGH_COMM_WORLD, &ms)); incoming = geom [dim]; for (j = 1; j < dim; j++) incoming *= geom [dim + j]; tmpd = malloc (incoming * info->element_size); CACTUS_MPI_ERROR (MPI_Recv (tmpd, incoming, info->mpi_type, i, 2*i+IOTAGBASE, pughGH->PUGH_COMM_WORLD, &ms)); IOFlexIO_procDump (iof, GH, index, tmpd, geom, info->flexio_type); free (tmpd); } /* End loop over processors */ /* now add the attributes for unchunked files */ if (ioUtilGH->unchunked) IOFlexIO_AddCommonAttributes (GH, index, timelevel, &geom [dim], iof); } /* End myproc = 0 */ CCTK_Barrier (GH); #endif /* MPI */ if (free_outme) free (outme); free (geom); } /*@@ @routine IOFlexIO_AddCommonAttributes @date July 1998 @author Paul Walker @desc Add "Common" attributes, these are the GF name, the current date, simulation time, origin, bounding box, gridspacings (both downsampled and evolution), global grid size, number of processors and iteration number. Note that the datestamp should be turned of if you are byte comparing two output files. @enddesc @calls @calledby @history @hdate Wed Sep 2 10:15:22 1998 @hauthor Tom Goodale @hdesc Abstracted WRITE_ATTRIBUTE to merge in Szu-Wen's Panda changes. @hdate Apr 16 1999 @hauthor Thomas Radke @hdesc Added attributes groupname, grouptype, ntimelevels, and current timelevel to be stored @hdate May 02 1999 @hauthor Thomas Radke @hdesc Made chunked attribute nioprocs common so that it can be found by the recombiner even for unchunked datasets (eg. SCALARs) @hdate May 05 1999 @hauthor Thomas Radke @hdesc Added "unchunked" attribute to distinguish between chunked/unchunked output files @endhistory @@*/ static void IOFlexIO_AddCommonAttributes (cGH *GH, int index, int timelevel, CCTK_INT4 *gsz, IOFile iof) { DECLARE_CCTK_PARAMETERS int dim; CCTK_REAL d3_to_IO [6]; /* buffer for writing doubles to IEEEIO */ CCTK_INT4 i_to_IO; /* buffer for writing an int to IEEEIO */ char *name, *gname; ioGH *ioUtilGH; /* Get the handle for IO extensions */ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; /* get the dimension of the variable */ dim = CCTK_GroupDimI (CCTK_GroupIndexFromVarI (index)); name = CCTK_FullName (index); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "name", FLEXIO_CHAR, strlen (name) + 1, name)); free (name); gname = CCTK_GroupNameFromVarI (index); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "groupname", FLEXIO_CHAR, strlen (gname) + 1, gname)); free (gname); i_to_IO = CCTK_GroupTypeFromVarI (index); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "grouptype", FLEXIO_INT4, 1, &i_to_IO)); i_to_IO = CCTK_NumTimeLevelsFromVarI (index); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "ntimelevels", FLEXIO_INT4, 1, &i_to_IO)); i_to_IO = timelevel; CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "timelevel", FLEXIO_INT4, 1, &i_to_IO)); if (char_time_date && out3D_datestamp) CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "date", FLEXIO_CHAR, strlen (char_time_date) + 1, char_time_date)); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "time", FLEXIO_REAL, 1,&GH->cctk_time)); d3_to_IO [0] = CCTK_CoordOrigin ("x"); d3_to_IO [1] = CCTK_CoordOrigin ("y"); d3_to_IO [2] = CCTK_CoordOrigin ("z"); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "origin", FLEXIO_REAL,3,d3_to_IO)); CCTK_CoordRange (GH, &d3_to_IO [0], &d3_to_IO [3], "x"); CCTK_CoordRange (GH, &d3_to_IO [1], &d3_to_IO [4], "y"); CCTK_CoordRange (GH, &d3_to_IO [2], &d3_to_IO [5], "z"); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "min_ext",FLEXIO_REAL,3,d3_to_IO)); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "max_ext",FLEXIO_REAL,3,d3_to_IO + 3)); d3_to_IO [0] = GH->cctk_delta_space [0] * ioUtilGH->downsample [0]; d3_to_IO [1] = GH->cctk_delta_space [1] * ioUtilGH->downsample [1]; d3_to_IO [2] = GH->cctk_delta_space [2] * ioUtilGH->downsample [2]; CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "delta", FLEXIO_REAL, 3,d3_to_IO)); if (ioUtilGH->downsample [0] > 1 || ioUtilGH->downsample [1] > 1 || ioUtilGH->downsample [2] > 1) { d3_to_IO [0] = GH->cctk_delta_space [0]; d3_to_IO [1] = GH->cctk_delta_space [1]; d3_to_IO [2] = GH->cctk_delta_space [2]; CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "evolution_delta", FLEXIO_REAL, 3, d3_to_IO)); } CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "global_size", FLEXIO_INT4, dim, gsz)); i_to_IO = CCTK_nProcs (GH); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "nprocs", FLEXIO_INT4, 1, &i_to_IO)); i_to_IO = ioUtilGH->ioproc_every; CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "ioproc_every", FLEXIO_INT4, 1, &i_to_IO)); i_to_IO = ioUtilGH->unchunked; CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "unchunked", FLEXIO_INT4, 1, &i_to_IO)); i_to_IO = GH->cctk_iteration; CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "iteration", FLEXIO_INT4, 1, &i_to_IO)); } /*@@ @routine IOFlexIO_AddChunkAttributes @author Paul Walker @date Feb 1997 @desc This routine adds chunk attributes to a data set. That is, is adds attributes to the chunks of data passed to the io processors. @enddesc @history @hauthor Gabrielle Allen @hdate Jul 10 1998 @hdesc Added the name of the grid function @hdate Wed Sep 2 10:08:31 1998 @hauthor Tom Goodale @hdesc Abstracted WRITE_ATTRIBUTE to merge in Szu-Wen's Panda calls. @endhistory @@*/ static void IOFlexIO_AddChunkAttributes (cGH *GH, int index, CCTK_INT4 *geom, IOFile iof) { int dim; char *name; CCTK_INT4 i_to_IO; /* there is nothing to do for a serial run */ if (CCTK_nProcs (GH) == 1) return; /* get the dimension of the variable */ dim = CCTK_GroupDimI (CCTK_GroupIndexFromVarI (index)); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "chunk_origin", FLEXIO_INT4, dim, &geom [0])); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "subchunk_lb", FLEXIO_INT4, dim, &geom [0])); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "global_size", FLEXIO_INT4, dim, &geom [2*dim])); i_to_IO = GH->cctk_iteration; CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "chunk_dataset", FLEXIO_INT4, 1, &i_to_IO)); name = CCTK_FullName (index); CACTUS_IEEEIO_ERROR (IOwriteAttribute (iof, "name", FLEXIO_CHAR, strlen (name)+1, name)); free (name); } /*@@ @routine IOFlexIO_getDumpData @author Paul Walker @date Feb 1997 @desc Bounds and data to be output, takes into account downsampling @enddesc @history @hauthor Gabrielle Allen @hdate Oct 5 1998 @hdesc Made into subroutine @endhistory @var GH @vdesc Identifies grid hierachy @vtype cGH * @vio in @vcomment @endvar @var index @vdesc index of the variable to dump @vtype int @vio in @vcomment @endvar @var timelevel @vdesc timelevel of the variable to dump @vtype int @vio in @vcomment @endvar @var outme @vdesc data segment to output @vtype void ** @vio out @vcomment This is just GF->data if there is no downsampling @endvar @var free_outme @vdesc Specifies whether or not to free the storage associated with outme @vtype int * @vio out @vcomment 1: free storage; 0: don't free storage @endvar @var geom @vdesc bounds, local size and global shape of the output @vtype CCTK_INT4 [3*dim] @vio out @vcomment geom [0*dim..1*dim-1] lower bounds and geom[3],geom[4],geom[5] geom [1*dim..2*dim-1] local size of data to send geom [2*dim..3*dim-1] global shape @endvar @var element_size @vdesc the size of an element of variable @vtype int @vio in @endvar @@*/ static void IOFlexIO_getDumpData (cGH *GH, int index, int timelevel, void **outme, int *free_outme, CCTK_INT4 *geom, int element_size) { DECLARE_CCTK_PARAMETERS int i, myproc, do_downsample, dim; ioGH *ioUtilGH; pGExtras *extras; CCTK_REAL4 *single_ptr; CCTK_REAL *real_ptr; CCTK_CHAR *char_ptr; CCTK_INT *int_ptr; void *data = CCTK_VarDataPtrI (GH, timelevel, index); /* to make the compiler happy */ single_ptr = NULL; real_ptr = NULL; char_ptr = NULL; int_ptr = NULL; myproc = CCTK_MyProc (GH); /* get GH extensions for IO */ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; /* get the pGExtras pointer as a shortcut */ extras = ((pGA ***)PUGH_pGH (GH)->variables)[index][timelevel]->extras; /* get the dimension of the variable */ dim = CCTK_GroupDimI (CCTK_GroupIndexFromVarI (index)); do_downsample = 0; for (i = 0; i < dim; i++) do_downsample |= ioUtilGH->downsample [i] > 1; /* All the downsampling code is hard-coded for 3D data. For other-dimensional variables we print a warning and return the non-downsampled data. */ if (do_downsample && dim != 3) { char *fullname = CCTK_FullName (index); CCTK_VWarn (1, __LINE__, __FILE__, CCTK_THORNSTRING, "No downsampling for %dD variable '%s' ! Downsampling is only " "supported for 3D variables.", dim, fullname); free (fullname); do_downsample = 0; } /* Simple case if no downsampling */ if (! do_downsample) { if (ioUtilGH->out_single) { single_ptr = (CCTK_REAL4 *) malloc (extras->npoints*sizeof (CCTK_REAL4)); for (i = 0; i < extras->npoints; i++) { single_ptr [i] = (CCTK_REAL4) ((CCTK_REAL *) data) [i]; } *outme = single_ptr; *free_outme = 1; } else { *outme = data; *free_outme = 0; } for (i = 0; i < dim; i++) { geom [i + 0*dim] = extras->lb [myproc][i];; /* the bounds */ geom [i + 1*dim] = extras->lnsize [i]; /* the sizes */ geom [i + 2*dim] = extras->nsize [i]; /* the global space */ } } else { /* NOTE: the following downsampling code is hard-coded for 3D data */ int start [3], end [3]; int i, j, k, l; /* Downsampling code ... */ for (i = 0; i < 3; i++) { geom [i + 6] = extras->nsize [i] / ioUtilGH->downsample [i]; if (extras->nsize [i] % ioUtilGH->downsample [i]) geom [i + 6]++; } if (verbose) CCTK_VInfo (CCTK_THORNSTRING, "Downsampled sizes (%d, %d, %d) -> " "(%d, %d, %d)", extras->nsize [0], extras->nsize [1], extras->nsize [2], (int) geom [6], (int) geom [7], (int) geom [8]); /* Now figure out the local downsampling */ /* The local starts are the lb modded into the downsample */ for (i = 0; i < 3; i++) { geom [i] = extras->lb [myproc][i] / ioUtilGH->downsample [i]; start [i] = geom [i] * ioUtilGH->downsample [i]; if (start [i] < extras->lb [myproc][i] + extras->ownership [PUGH_NO_STAGGER][0][i]) { start [i] += ioUtilGH->downsample [i]; geom [i] ++; } end [i] = ((extras->lb [myproc][i] + extras->ownership [PUGH_NO_STAGGER][1][i] - 1) / ioUtilGH->downsample [i]) * ioUtilGH->downsample [i]; geom [i+3] = (end [i] - start [i]) / ioUtilGH->downsample [i] + 1; } if (verbose) { CCTK_VInfo (CCTK_THORNSTRING, "Downsample ranges (%d, %d, %d) -> " "(%d, %d, %d)", start [0], start [1], start [2], end [0], end [1], end [2]); CCTK_VInfo (CCTK_THORNSTRING, "Local size/bound (%d, %d, %d) " "(%d, %d, %d)", (int) geom [3], (int) geom [4], (int) geom [5], (int) geom [0], (int) geom [1], (int) geom [2]); } /* compute local ranges */ for (i = 0; i < 3; i++) { start [i] -= extras->lb [myproc][i]; end [i] -= extras->lb [myproc][i]; } *outme = malloc (geom [3] * geom [4] * geom [5] * element_size); *free_outme = 1; /* I hate it to repeat the loops for each case label but that way produces much more efficient code */ l = 0; switch (CCTK_VarTypeI (index)) { case CCTK_VARIABLE_CHAR: char_ptr = (CCTK_CHAR *) *outme; for (k = start [2]; k <= end [2]; k += ioUtilGH->downsample [2]) for (j = start [1]; j <= end [1]; j += ioUtilGH->downsample [1]) for (i = start [0]; i <= end [0]; i += ioUtilGH->downsample [0]) char_ptr [l++] = ((CCTK_CHAR *) data) [DATINDEX (extras, i, j, k)]; break; case CCTK_VARIABLE_INT: int_ptr = (CCTK_INT *) *outme; for (k = start [2]; k <= end [2]; k += ioUtilGH->downsample [2]) for (j = start [1]; j <= end [1]; j += ioUtilGH->downsample [1]) for (i = start [0]; i <= end [0]; i += ioUtilGH->downsample [0]) int_ptr [l++] = ((CCTK_INT *) data) [DATINDEX (extras, i, j, k)]; break; case CCTK_VARIABLE_REAL: if (ioUtilGH->out_single) single_ptr = (CCTK_REAL4 *) *outme; else real_ptr = (CCTK_REAL *) *outme; for (k = start [2]; k <= end [2]; k += ioUtilGH->downsample [2]) for (j = start [1]; j <= end [1]; j += ioUtilGH->downsample [1]) for (i = start [0]; i <= end [0]; i += ioUtilGH->downsample [0]) if (ioUtilGH->out_single) single_ptr [l++] = (CCTK_REAL4) (((CCTK_REAL *) data) [DATINDEX (extras, i, j, k)]); else real_ptr [l++] = ((CCTK_REAL *) data) [DATINDEX (extras, i, j, k)]; break; #if 0 /* FIXME: Don't know how to support COMPLEX type too !! */ case CCTK_VARIABLE_COMPLEX: if (ioUtilGH->out_single) single_ptr = (CCTK_REAL4 *) *outme; else cmplx_ptr = (CCTK_COMPLEX *) *outme; for (k = start [2]; k <= end [2]; k += ioUtilGH->downsample [2]) for (j = start [1]; j <= end [1]; j += ioUtilGH->downsample [1]) for (i = start [0]; i <= end [0]; i += ioUtilGH->downsample [0]) if (ioUtilGH->out_single) { single_ptr [l++] = (CCTK_REAL4) (((CCTK_REAL *) data) [0 + DATINDEX (extras, i, j, k)]); single_ptr [l++] = (CCTK_REAL4) (((CCTK_REAL *) data) [1 + DATINDEX (extras, i, j, k)]); } else cmplx_ptr [l++] = ((CCTK_COMPLEX *) data) [DATINDEX (extras, i, j, k)]; break; #endif default: CCTK_WARN (1, "Unsupported variable type in IOFlexIO_getDumpData"); return; } } #ifdef IOFLEXIO_DEBUG printf ("Lower bound: %d", (int) geom [0]); for (i = 1; i < dim; i++) printf (" %d", (int) geom [i]); printf ("\n"); printf ("Chunk size : %d", (int) geom [1*dim + 0]); for (i = 1; i < dim; i++) printf (" %d", (int) geom [1*dim + i]); printf ("\n"); printf ("Global size: %d", (int) geom [2*dim + 0]); for (i = 1; i < dim; i++) printf (" %d", (int) geom [2*dim + i]); printf ("\n"); #endif } /*@@ @routine IOFlexIO_eachProcDump @author Paul Walker @date Feb 1997 @desc Dump data from each processor @enddesc @history @hauthor Gabrielle Allen @hdate Oct 5 1998 @hdesc Made into subroutine @endhistory @@*/ static void IOFlexIO_eachProcDump (cGH *GH, int index, int timelevel, void *outme, CCTK_INT4 *geom, IOFile iof, int flexio_type) { int i, dim, *chunk_dims; /* get the dimension of the variable */ dim = CCTK_GroupDimI (CCTK_GroupIndexFromVarI (index)); chunk_dims = (int *) malloc (dim * sizeof (int)); /* So set up the local shape. */ for (i = 0; i < dim; i++) chunk_dims [i] = geom [dim + i]; /* Dump the data */ CACTUS_IEEEIO_ERROR (IOwrite (iof, flexio_type, dim, chunk_dims, outme)); /* Add attributes for global space */ IOFlexIO_AddCommonAttributes (GH, index, timelevel, &geom [2*dim], iof); /* Add chunk attributes */ IOFlexIO_AddChunkAttributes (GH, index, geom, iof); free (chunk_dims); } /*@@ @routine IOFlexIO_procDump @author Paul Walker @date Feb 1997 @desc Dump data @enddesc @history @hauthor Gabrielle Allen @hdate Oct 5 1998 @hdesc Made into subroutine @endhistory @@*/ #ifdef CCTK_MPI static void IOFlexIO_procDump (IOFile iof, cGH *GH, int index, void *outme, CCTK_INT4 *geom, int flexio_type) { ioGH *ioUtilGH; int i, dim, *chunk_dims, *chunk_origin; /* Chunk dim and origin */ ioUtilGH = (ioGH *) GH->extensions [CCTK_GHExtensionHandle ("IO")]; /* get the dimension of the variable */ dim = CCTK_GroupDimI (CCTK_GroupIndexFromVarI (index)); chunk_origin = (int *) malloc (2*dim * sizeof (int)); chunk_dims = chunk_origin + dim; for (i = 0; i < dim; i++) { chunk_origin [i] = geom [i]; chunk_dims [i] = geom [dim + i]; } if (ioUtilGH->unchunked) { /* Unchunked data */ CACTUS_IEEEIO_ERROR (IOwriteChunk (iof, chunk_dims, chunk_origin, outme)); } else { /* Chunked data */ CACTUS_IEEEIO_ERROR (IOwrite (iof, flexio_type, dim, chunk_dims, outme)); /* Write chunk attributes */ IOFlexIO_AddChunkAttributes (GH, index, geom, iof); } free (chunk_origin); } #endif