pystella/decomp.py
def gather_array(self, queue, in_array, out_array, root):
        """
        Gathers the subdomains of an array from each rank into a single array
        of the entire grid, removing halo padding from ``in_array``.

        :arg queue: The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.

        :arg in_array: The subarrays to be gathered.
            May be either a :class:`pyopencl.array.Array` or a
            :class:`numpy.ndarray`.

        :arg out_array: The output array for the gathered grid.
            May be either a :class:`pyopencl.array.Array` or a
            :class:`numpy.ndarray` on rank ``root``, and *None* otherwise.

        :arg root: The rank to which ``in_array`` is gathered.
        """

        h = self.halo_shape
        dtype = None if self.rank != root else out_array.dtype
        dtype = self.bcast(dtype, root=root)
        if in_array.dtype != dtype:
            raise ValueError("in_array and out_array have different dtypes")

        cl_in = self.bcast(isinstance(in_array, cla.Array), root)
        cl_out = self.bcast(isinstance(out_array, cla.Array), root)

        if self.nranks == 1:
            self.remove_halos(queue, in_array, out_array)
        else:
            temp_in = in_array.get() if cl_in else in_array
            if cl_out and self.rank == root:
                temp_out = np.zeros(shape=out_array.shape, dtype=dtype)
            elif self.rank == root:
                temp_out = out_array
            else:
                temp_out = None

            rank_shape = tuple(i - 2 * hi for i, hi in zip(in_array.shape, h))
            full_shape = None if self.rank != root else out_array.shape
            full_shape = self.bcast(full_shape, root)

            from mpi4py import MPI
            MPI_dtype = MPI._typedict[np.dtype(dtype).char]

            interior = tuple(slice(hi, -hi) if hi > 0 else slice(None) for hi in h)

            nx = self.allreduce(rank_shape[0], op=MPI.MAX)
            for i in range(nx):
                displs, counts = self.get_displs_and_counts(full_shape, i)
                # repeat the last row when some ranks have smaller rank_shape[0]
                x_slice = min(i + h[0], rank_shape[0] + h[0] - 1)
                tmp = temp_in[(x_slice,) + interior[1:]].copy()
                if self.rank == root:
                    recv_buf = [temp_out, counts, displs, MPI_dtype]
                else:
                    recv_buf = None
                self.comm.Gatherv(tmp, recv_buf, root=root)

            if cl_out and self.rank == root:
                out_array.set(temp_out)

        Gathers the subdomains of an array from each rank into a single array
        of the entire grid, removing halo padding from ``in_array``.

        :arg queue: The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.

        :arg in_array: The subarrays to be gathered.
            May be either a :class:`pyopencl.array.Array` or a
            :class:`numpy.ndarray`.

        :arg out_array: The output array for the gathered grid.
            May be either a :class:`pyopencl.array.Array` or a
            :class:`numpy.ndarray` on rank ``root``, and *None* otherwise.

        :arg root: The rank to which ``in_array`` is gathered.
        
Gathers the subdomains of an array from each rank into a single array
of the entire grid, removing halo padding from ``in_array``.
Gathers the subdomains of an array from each rank into a single array of the entire grid removing halo padding from ` ` in_array ` ` .
def gather_array(self, queue, in_array, out_array, root):
        h = self.halo_shape
        dtype = None if self.rank != root else out_array.dtype
        dtype = self.bcast(dtype, root=root)
        if in_array.dtype != dtype:
            raise ValueError("in_array and out_array have different dtypes")
        cl_in = self.bcast(isinstance(in_array, cla.Array), root)
        cl_out = self.bcast(isinstance(out_array, cla.Array), root)
        if self.nranks == 1:
            self.remove_halos(queue, in_array, out_array)
        else:
            temp_in = in_array.get() if cl_in else in_array
            if cl_out and self.rank == root:
                temp_out = np.zeros(shape=out_array.shape, dtype=dtype)
            elif self.rank == root:
                temp_out = out_array
            else:
                temp_out = None
            rank_shape = tuple(i - 2 * hi for i, hi in zip(in_array.shape, h))
            full_shape = None if self.rank != root else out_array.shape
            full_shape = self.bcast(full_shape, root)
            from mpi4py import MPI
            MPI_dtype = MPI._typedict[np.dtype(dtype).char]
            interior = tuple(slice(hi, -hi) if hi > 0 else slice(None) for hi in h)
            nx = self.allreduce(rank_shape[0], op=MPI.MAX)
            for i in range(nx):
                displs, counts = self.get_displs_and_counts(full_shape, i)
                x_slice = min(i + h[0], rank_shape[0] + h[0] - 1)
                tmp = temp_in[(x_slice,) + interior[1:]].copy()
                if self.rank == root:
                    recv_buf = [temp_out, counts, displs, MPI_dtype]
                else:
                    recv_buf = None
                self.comm.Gatherv(tmp, recv_buf, root=root)
            if cl_out and self.rank == root:
                out_array.set(temp_out)
def gather_array ( self , queue , in_array , out_array , root ) : h = self . halo_shape dtype = None if self . rank != root else out_array . dtype dtype = self . bcast ( dtype , root = root ) if in_array . dtype != dtype : raise ValueError ( "in_array and out_array have different dtypes" ) cl_in = self . bcast ( isinstance ( in_array , cla . Array ) , root ) cl_out = self . bcast ( isinstance ( out_array , cla . Array ) , root ) if self . nranks == 1 : self . remove_halos ( queue , in_array , out_array ) else : temp_in = in_array . get ( ) if cl_in else in_array if cl_out and self . rank == root : temp_out = np . zeros ( shape = out_array . shape , dtype = dtype ) elif self . rank == root : temp_out = out_array else : temp_out = None rank_shape = tuple ( i - 2 * hi for i , hi in zip ( in_array . shape , h ) ) full_shape = None if self . rank != root else out_array . shape full_shape = self . bcast ( full_shape , root ) from mpi4py import MPI MPI_dtype = MPI . _typedict [ np . dtype ( dtype ) . char ] interior = tuple ( slice ( hi , - hi ) if hi > 0 else slice ( None ) for hi in h ) nx = self . allreduce ( rank_shape [ 0 ] , op = MPI . MAX ) for i in range ( nx ) : displs , counts = self . get_displs_and_counts ( full_shape , i ) x_slice = min ( i + h [ 0 ] , rank_shape [ 0 ] + h [ 0 ] - 1 ) tmp = temp_in [ ( x_slice , ) + interior [ 1 : ] ] . copy ( ) if self . rank == root : recv_buf = [ temp_out , counts , displs , MPI_dtype ] else : recv_buf = None self . comm . Gatherv ( tmp , recv_buf , root = root ) if cl_out and self . rank == root : out_array . set ( temp_out )
Gathers the subdomains of an array from each rank into a single array
of the entire grid, removing halo padding from ``in_array``.
Gathers the subdomains of an array from each rank into a single array of the entire grid removing halo padding from ` ` in_array ` ` .
"""
        Gathers the subdomains of an array from each rank into a single array
        of the entire grid, removing halo padding from ``in_array``.

        :arg queue: The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.

        :arg in_array: The subarrays to be gathered.
            May be either a :class:`pyopencl.array.Array` or a
            :class:`numpy.ndarray`.

        :arg out_array: The output array for the gathered grid.
            May be either a :class:`pyopencl.array.Array` or a
            :class:`numpy.ndarray` on rank ``root``, and *None* otherwise.

        :arg root: The rank to which ``in_array`` is gathered.
        """ # repeat the last row when some ranks have smaller rank_shape[0]

self
queue
The :class:`pyopencl.CommandQueue` to enqueue kernels and copies.
The : class : ` pyopencl . CommandQueue ` to enqueue kernels and copies .
in_array
The subarrays to be gathered.
May be either a :class:`pyopencl.array.Array` or a
:class:`numpy.ndarray`.
The subarrays to be gathered . May be either a : class : ` pyopencl . array . Array ` or a : class : ` numpy . ndarray ` .
out_array
The output array for the gathered grid.
May be either a :class:`pyopencl.array.Array` or a
:class:`numpy.ndarray` on rank ``root``, and *None* otherwise.
The output array for the gathered grid . May be either a : class : ` pyopencl . array . Array ` or a : class : ` numpy . ndarray ` on rank ` ` root ` ` and * None * otherwise .
root
The rank to which ``in_array`` is gathered.
The rank to which ` ` in_array ` ` is gathered .