from pyccel.stdlib.parallel.mpi import mpi_comm_world from pyccel.stdlib.parallel.mpi import mpi_status_size from pyccel.stdlib.parallel.mpi import mpi_allgather from pyccel.stdlib.parallel.mpi import MPI_INTEGER # we need to declare these variables somehow, # since we are calling mpi subroutines ierr = -1 size = -1 rank = -1 mpi_init(ierr) comm = mpi_comm_world mpi_comm_size(comm, size, ierr) mpi_comm_rank(comm, rank, ierr) nb_values = 8 block_length = nb_values / size # ... values = zeros(block_length, int) for i in range(0, block_length): values[i] = 1000 + rank * nb_values + i print('I, process ', rank, 'sent my values array : ', values) # ... # ... data = zeros(nb_values, int)
def __init__(self, npts, pads, periods, reorder): ntx = npts[0] nty = npts[1] # ... TODO : to be computed using 'len' self.ndims = 2 self.n_neighbour = 4 # ... # ... Constants north = 0 east = 1 south = 2 west = 3 # ... # ... self.neighbour = zeros(self.n_neighbour, int) self.coords = zeros(self.ndims, int) self.dims = zeros(self.ndims, int) self.starts = zeros(self.ndims, int) self.ends = zeros(self.ndims, int) self.comm1d = zeros(self.ndims, int) self.steps = [1, 1] self.pads = pads self.periods = periods self.reorder = reorder # ... # ... TODO: remove from here ierr = -1 size = -1 self.rank = -1 self.rank_in_topo = -1 self.comm_cart = -1 comm = mpi_comm_world mpi_comm_size(comm, size, ierr) mpi_comm_rank(comm, self.rank, ierr) # ... # ... # Know the number of processes along x and y mpi_dims_create(size, self.ndims, self.dims, ierr) # ... # ... # Create a 2d mpi cart mpi_cart_create(comm, self.ndims, self.dims, self.periods, self.reorder, self.comm_cart, ierr) # Know my coordinates in the topology mpi_comm_rank(self.comm_cart, self.rank_in_topo, ierr) mpi_cart_coords(self.comm_cart, self.rank_in_topo, self.ndims, self.coords, ierr) # X-axis limits sx = (self.coords[0] * ntx) / self.dims[0] ex = ((self.coords[0] + 1) * ntx) / self.dims[0] - 1 # Y-axis limits sy = (self.coords[1] * nty) / self.dims[1] ey = ((self.coords[1] + 1) * nty) / self.dims[1] - 1 # ... # ... self.starts[0] = sx self.ends[0] = ex self.starts[1] = sy self.ends[1] = ey # ... # ... self.sx = sx self.ex = ex + 1 self.sy = sy self.ey = ey + 1 # ... # ... grid without ghost cells self.r_x = range(self.sx, self.ex, self.steps[0]) self.r_y = range(self.sy, self.ey, self.steps[1]) self.indices = tensor(self.r_x, self.r_y) # ... # ... self.sx_ext = sx - self.pads[0] self.ex_ext = ex + self.pads[0] + 1 self.sy_ext = sy - self.pads[1] self.ey_ext = ey + self.pads[1] + 1 # ... # ... extended grid with ghost cells self.r_ext_x = range(self.sx_ext, self.ex_ext, self.steps[0]) self.r_ext_y = range(self.sy_ext, self.ey_ext, self.steps[1]) self.extended_indices = tensor(self.r_ext_x, self.r_ext_y) # ... # ... Neighbours # Search of my West and East neigbours mpi_cart_shift(self.comm_cart, 0, self.pads[0], self.neighbour[west], self.neighbour[east], ierr) # Search of my South and North neighbours mpi_cart_shift(self.comm_cart, 1, self.pads[1], self.neighbour[south], self.neighbour[north], ierr) # ... # ... Create 1d communicator within the cart flags = [True, False] mpi_cart_sub(self.comm_cart, flags, self.comm1d[0], ierr) flags = [False, True] mpi_cart_sub(self.comm_cart, flags, self.comm1d[1], ierr) # ... # ... Derived Types # Creation of the type_line derived datatype to exchange points # with northern to southern neighbours self.type_line = -1 mpi_type_vector(ey - sy + 1, 1, ex - sx + 1 + 2 * self.pads[0], MPI_DOUBLE, self.type_line, ierr) mpi_type_commit(self.type_line, ierr) # Creation of the type_column derived datatype to exchange points # with western to eastern neighbours self.type_column = -1 mpi_type_contiguous(ex - sx + 1, MPI_DOUBLE, self.type_column, ierr) mpi_type_commit(self.type_column, ierr)
rank = -1 # rank is 2d cart rank_in_topo = -1 # 2d cart communicator comm_2d = -1 # 1d communicator comm_1d = -1 mpi_init(ierr) comm = mpi_comm_world mpi_comm_size(comm, size, ierr) mpi_comm_rank(comm, rank, ierr) north = 0 east = 1 south = 2 west = 3 ndims = 2 steps = [1, 1] dims = [2, 2] periods = [False, True] reorder = False neighbor = zeros(4, int) coords = zeros(2, int)
from pyccel.stdlib.parallel.mpi import mpi_comm_split from pyccel.stdlib.parallel.mpi import mpi_comm_free from pyccel.stdlib.parallel.mpi import mpi_bcast from pyccel.stdlib.parallel.mpi import MPI_INTEGER # we need to declare these variables somehow, # since we are calling mpi subroutines ierr = -1 size = -1 rank_in_world = -1 mpi_init(ierr) comm = mpi_comm_world mpi_comm_size(comm, size, ierr) mpi_comm_rank(comm, rank_in_world, ierr) master = 0 m = 8 a = zeros(m, int) if rank_in_world == 1: a = 1 if rank_in_world == 2: a = 2 key = rank_in_world if rank_in_world == 1: key = -1 if rank_in_world == 2: