From 0e48c9b382709ac9833a9f7e6736b958f79eb0de Mon Sep 17 00:00:00 2001 From: Michael Krayer Date: Wed, 2 Jun 2021 09:35:16 +0200 Subject: [PATCH] added striding to parallel routines in order to gather a complete field at rank 0 --- field.py | 37 ---------------- parallel.py | 119 ++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 93 insertions(+), 63 deletions(-) diff --git a/field.py b/field.py index 1e204f4..54705c8 100644 --- a/field.py +++ b/field.py @@ -236,7 +236,6 @@ class Field3d: self.data = self.data.astype(dtype,copy=False) return - def derivative(self,axis,only_keep_interior=False,shift_origin='before'): '''Computes derivative wrt to direction 'axis' with 2nd order finite differences centered between the origin grid points''' @@ -342,42 +341,6 @@ class Field3d: radius.append(int(truncate*sigma_img[ii]+0.5)) return tuple(radius) - # def shift_origin(self,rel_shift): - # raise NotImplementedError("Routine has not been verified yet.") - # #TBD: verify this routine - # assert isinstance(rel_shift,(tuple,list,numpy.ndarray)) and len(rel_shift)==3,\ - # "'shift' must be tuple/list with length 3." - # assert all([rel_shift[ii]>-1.0 and rel_shift[ii]<1.0 for ii in range(3)]),\ - # "'shift' must be in (-1.0,1.0)." - # #data = numpy.full(self.dim,numpy.nan) - # data = self.data.copy() - # origin = list(self.origin) - # for axis in range(3): - # if abs(rel_shift[axis])=stride*num_ghost), "At least stride*num_ghost "\ + "ghost cells are required in the original field. Have {}, need {}.".format( + tuple(self.num_ghost),tuple(stride*num_ghost)) + ib = self.proc_grid[key][0][self.ip]-1 + ie = self.proc_grid[key][1][self.ip]-1 + jb = self.proc_grid[key][2][self.jp]-1 + je = self.proc_grid[key][3][self.jp]-1 + kb = self.proc_grid[key][4][self.kp]-1 + ke = self.proc_grid[key][5][self.kp]-1 + ijkb = np.array((ib,jb,kb)) + ijke = np.array((ie,je,ke)) + # Determine the first point to consider in this chunk for the case of output + # without ghost cells + idx_origin = (np.ceil(ijkb/stride)*stride).astype(int)-ijkb+self.num_ghost + # Now the last point to consider under the same circumstances + idx_endpoint = (np.floor(ijke/stride)*stride).astype(int)-ijkb+self.num_ghost + # If we want the subfield to have ghost cells, shift the origin and endpoint + idx_origin -= (~no_lower_ghost).astype(int)*stride*num_ghost + idx_endpoint += (~no_upper_ghost).astype(int)*stride*num_ghost + # Compute the number of points + num_points = ((idx_endpoint-idx_origin)/stride+1).astype(int) + # Some last assertions which should never fail + # print(self.rank,idx_origin,idx_endpoint,num_points,self.field[key].dim(),self.field[key].dim()) + assert all(idx_origin>=0) + assert all(idx_endpoint