예제 #1
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)

# Create a 2d mpi cart
mpi_cart_create(comm, ndims, dims, periods, reorder, comm_2d, ierr)

# Know my coordinates in the topology
mpi_comm_rank(comm_2d, rank_in_topo, ierr)
mpi_cart_coords(comm_2d, rank_in_topo, ndims, coords, ierr)

# Search of my West and East neigbors
mpi_cart_shift(comm_2d, 0, steps[0], neighbor[west], neighbor[east], ierr)

# Search of my South and North neighbors
mpi_cart_shift(comm_2d, 1, steps[1], neighbor[south], neighbor[north], ierr)

m = 4
v = zeros(m, double)
if coords[0] == 1:
    v = (rank + 1) * 1.0
예제 #2
0
파일: mpi.py 프로젝트: toddrme2178/pyccel
    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)