diff options
Diffstat (limited to 'src/GetHyperslab.c')
-rw-r--r-- | src/GetHyperslab.c | 52 |
1 files changed, 34 insertions, 18 deletions
diff --git a/src/GetHyperslab.c b/src/GetHyperslab.c index b1206e2..da835f4 100644 --- a/src/GetHyperslab.c +++ b/src/GetHyperslab.c @@ -29,18 +29,23 @@ CCTK_FILEVERSION(CactusPUGH_PUGHSlab_GetHyperslab_c) /* define this if you want debugging output */ /* #define DEBUG 1 */ +/* define some defaults for optional parameters */ +#define DEFAULT_PROCESSOR 0 +#define DEFAULT_TIMELEVEL 0 /******************************************************************** ******************** Internal Routines ************************ ********************************************************************/ static int GetLocalHyperslab (const cGH *GH, const hslab_mapping_t *mapping, + int proc, int vindex, int timelevel, int hdatatype, void *hdata); static int GetDiagonalFromFrom3D (const cGH *GH, const hslab_mapping_t *mapping, + int proc, int vindex, int timelevel, int hdatatype, @@ -49,6 +54,7 @@ static int GetDiagonalFromFrom3D (const cGH *GH, CCTK_INT Hyperslab_Get (const cGH *GH, CCTK_INT mapping_handle, + CCTK_INT proc, CCTK_INT vindex, CCTK_INT timelevel, CCTK_INT hdatatype, @@ -58,17 +64,23 @@ CCTK_INT Hyperslab_Get (const cGH *GH, hslab_mapping_t *mapping; + if (proc >= CCTK_nProcs (GH)) + { + return (-1); + } + mapping = PUGHSlabi_GetMapping (mapping_handle); if (mapping == NULL) { - return (-1); + return (-2); } /* check mapping consistency */ /*** FIXME ***/ /* get the processor-local hyperslab */ - retval = GetLocalHyperslab (GH, mapping, vindex, timelevel, hdatatype, hdata); + retval = GetLocalHyperslab (GH, mapping, proc, vindex, timelevel, + hdatatype, hdata); return (retval); } @@ -77,10 +89,11 @@ CCTK_INT Hyperslab_Get (const cGH *GH, CCTK_INT Hyperslab_GetList (const cGH *GH, CCTK_INT mapping_handle, CCTK_INT num_arrays, - const CCTK_INT *vindices /* num_arrays */, - const CCTK_INT *timelevels /* num_arrays */, - const CCTK_INT *hdatatypes /* num_arrays */, - void *const *hdata /* num_arrays */) + const CCTK_INT *procs /* num_arrays */, + const CCTK_INT *vindices /* num_arrays */, + const CCTK_INT *timelevels /* num_arrays */, + const CCTK_INT *hdatatypes /* num_arrays */, + void *const *hdata /* num_arrays */) { int i, retval; @@ -88,8 +101,10 @@ CCTK_INT Hyperslab_GetList (const cGH *GH, retval = 0; for (i = 0; i < num_arrays; i++) { - if (Hyperslab_Get (GH, mapping_handle, vindices[i], - timelevels ? timelevels[i] : 0, + if (Hyperslab_Get (GH, mapping_handle, + procs ? procs[i] : DEFAULT_PROCESSOR, + vindices[i], + timelevels ? timelevels[i] : DEFAULT_TIMELEVEL, hdatatypes ? hdatatypes[i] : -1, hdata[i]) == 0) { @@ -202,6 +217,7 @@ CCTK_INT Hyperslab_GetList (const cGH *GH, @@*/ static int GetLocalHyperslab (const cGH *GH, const hslab_mapping_t *mapping, + int proc, int vindex, int timelevel, int hdatatype, @@ -270,8 +286,8 @@ static int GetLocalHyperslab (const cGH *GH, /* diagonals from 3D variables are treated special */ if (mapping->is_diagonal_in_3D) { - retval = GetDiagonalFromFrom3D (GH, mapping, vindex, timelevel, hdatatype, - hdata); + retval = GetDiagonalFromFrom3D (GH, mapping, proc, vindex, timelevel, + hdatatype, hdata); return (retval); } @@ -470,6 +486,7 @@ fprintf (stderr, "***** copying %d bytes from %p tp %p\n", dim0_hsize, typed_vda static int GetDiagonalFromFrom3D (const cGH *GH, const hslab_mapping_t *mapping, + int proc, int vindex, int timelevel, int hdatatype, @@ -548,7 +565,7 @@ static int GetDiagonalFromFrom3D (const cGH *GH, { /* allocate communication buffers */ myproc = CCTK_MyProc (GH); - if (mapping->target_proc < 0 || mapping->target_proc == myproc) + if (proc < 0 || proc == myproc) { global_npoints = (CCTK_INT *) malloc (nprocs * sizeof (CCTK_INT)); recvcnts = (int *) malloc (2 * nprocs * sizeof (int)); @@ -560,7 +577,7 @@ static int GetDiagonalFromFrom3D (const cGH *GH, } /* gather the number of local points on each processor */ - if (mapping->target_proc < 0) + if (proc < 0) { CACTUS_MPI_ERROR (MPI_Allgather (&local_npoints, 1, PUGH_MPI_INT, global_npoints, 1, PUGH_MPI_INT, @@ -570,12 +587,11 @@ static int GetDiagonalFromFrom3D (const cGH *GH, { CACTUS_MPI_ERROR (MPI_Gather (&local_npoints, 1, PUGH_MPI_INT, global_npoints, 1, PUGH_MPI_INT, - mapping->target_proc, - pughGH->PUGH_COMM_WORLD)); + proc, pughGH->PUGH_COMM_WORLD)); } /* compute the receive count and displacement vectors */ - if (mapping->target_proc < 0 || mapping->target_proc == myproc) + if (proc < 0 || proc == myproc) { for (i = 0; i < nprocs; i++) { @@ -588,7 +604,7 @@ static int GetDiagonalFromFrom3D (const cGH *GH, mpidatatype = PUGH_MPIDataType (pughGH, hdatatype); /* gather the local hyperslab data from each processor */ - if (mapping->target_proc < 0) + if (proc < 0) { CACTUS_MPI_ERROR (MPI_Allgatherv (local_hdata, local_npoints, mpidatatype, hdata, recvcnts, displs, @@ -598,12 +614,12 @@ static int GetDiagonalFromFrom3D (const cGH *GH, { CACTUS_MPI_ERROR (MPI_Gatherv (local_hdata, local_npoints, mpidatatype, hdata, recvcnts, displs, - mpidatatype, mapping->target_proc, + mpidatatype, proc, pughGH->PUGH_COMM_WORLD)); } /* free communication buffers */ - if (mapping->target_proc < 0 || mapping->target_proc == myproc) + if (proc < 0 || proc == myproc) { free (global_npoints); free (recvcnts); |