From ac353c229482f5ff8f6063794bf4812c43b87a0d Mon Sep 17 00:00:00 2001 From: Michael Krayer Date: Fri, 28 May 2021 01:18:23 +0200 Subject: [PATCH] removed some unnecessary leftovers, some bugfixes --- parallel.py | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/parallel.py b/parallel.py index 0229dba..3d5ddb8 100644 --- a/parallel.py +++ b/parallel.py @@ -138,8 +138,8 @@ class PPP: nxp_ext,nyp_ext,nzp_ext,nproc_ext = None,None,None,None nxp,nyp,nzp,nproc = None,None,None,None # Broadcast the data - self.proc_grid_ext = self.comm.bcast(proc_grid_ext,root=0) - self.proc_grid = self.comm.bcast(proc_grid,root=0) + self.proc_grid_ext = self.comm.bcast(proc_grid_ext,root=0) + self.proc_grid = self.comm.bcast(proc_grid,root=0) self.nxp_ext,self.nyp_ext,\ self.nzp_ext,self.nproc_ext = self.comm.bcast((nxp_ext,nyp_ext,nzp_ext,nproc_ext),root=0) self.nxp,self.nyp,\ @@ -147,25 +147,14 @@ class PPP: # Get position in processor grid self.ip,self.jp,self.kp = self.position_from_rank(self.rank,external=False) # Determine local grid indices and size - self.chunk_bounds = {} - self.chunk_size = {} for key in self.proc_grid: - self.chunk_bounds[key] = [None]*6 - self.chunk_bounds[key][0] = self.proc_grid[key][0][self.ip] - self.chunk_bounds[key][1] = self.proc_grid[key][1][self.ip] - self.chunk_bounds[key][2] = self.proc_grid[key][2][self.jp] - self.chunk_bounds[key][3] = self.proc_grid[key][3][self.jp] - self.chunk_bounds[key][4] = self.proc_grid[key][4][self.kp] - self.chunk_bounds[key][5] = self.proc_grid[key][5][self.kp] - self.chunk_size[key] = [None]*3 - self.chunk_size[key][0] = self.chunk_bounds[key][1]-self.chunk_bounds[key][0]+1 - self.chunk_size[key][1] = self.chunk_bounds[key][3]-self.chunk_bounds[key][2]+1 - self.chunk_size[key][2] = self.chunk_bounds[key][5]-self.chunk_bounds[key][4]+1 + nxl = self.proc_grid[key][1][self.ip]-self.proc_grid[key][0][self.ip]+1 + nyl = self.proc_grid[key][3][self.jp]-self.proc_grid[key][2][self.jp]+1 + nzl = self.proc_grid[key][5][self.kp]-self.proc_grid[key][4][self.kp]+1 # Verify that local grid size is not smaller than ghost cell size - assert (self.chunk_size[key][0]>=self.nghx and - self.chunk_size[key][1]>=self.nghy and - self.chunk_size[key][2]>=self.nghz), "Local grid size must be greater than number "\ - "of ghost cells in each direction!" + assert (nxl>=self.nghx and nyl>=self.nghy and nzl>=self.nghz),\ + "Local grid size must be greater than number "\ + "of ghost cells in each direction!" # Initialize neighbor array nghbr = np.empty((3,3,3),dtype='int') # wrap-around x @@ -432,10 +421,17 @@ class PPP: def shifting_state(self,key,axis=None): if axis is None: - return tuple(self.shifting_state(key,axis=ii) for axis in range(3)) + return tuple(self.shifting_state(key,axis=ii) for ii in range(3)) assert axis<3, "'axis' must be one of 0,1,2." return int(round((self.origin[key][axis]-self.bounds[2*axis])/(0.5*self.spacing[axis]))) + def chunk_size(self,key,axis=None): + '''Returns size of chunk without ghost cells.''' + if axis is None: + return tuple(self.chunk_size(key,axis=ii) for ii in range(3)) + assert axis<3, "'axis' must be one of 0,1,2." + return self.field[key].numpoints[axis]-2*self.num_ghost[axis] + def exchange_ghost_cells(self,key): '''Communicates all ghost cells of specified field''' # Trigger non-blocking communication: @@ -496,7 +492,7 @@ class PPP: # [send/recv] create a tag tag = ip_dst*100+jp_dst*10+kp_dst # [send/recv] get the indices of data to be sent/received - nxl,nyl,nzl = self.chunk_size[key] + nxl,nyl,nzl = self.chunk_size(key) if positionDst[0]==-1: ii_src = slice(self.nghx,2*self.nghx) ii_dst = slice(self.nghx+nxl,2*self.nghx+nxl)