How to use the pyccel.stdlib.parallel.mpi.mpi_comm_rank function in pyccel

To help you get started, we’ve selected a few pyccel examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyccel / pyccel / tests / old / scripts / mpi / core / gather.py View on Github external
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_gather
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)

master    = 1
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)
github pyccel / pyccel / tests / old / scripts / mpi / core / cart2d_1.py View on Github external
size = -1

# rank in comm worl
rank = -1

# rank is 2d cart
rank_in_topo = -1

# 2d cart communicator
comm_2d = -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)
github pyccel / pyccel / tests / old / scripts / mpi / core / sendrecv_replace.py View on Github external
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_sendrecv_replace
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)

if rank == 0:
    partner = 1

if rank == 1:
    partner = 0

msg = rank + 1000
tag = 1234
status = zeros(mpi_status_size, int)

mpi_sendrecv_replace(msg, 1, MPI_INTEGER, partner, tag,
                     partner, tag,
                     comm, status, ierr)

print('I, process ', rank, ', I received', msg, ' from process ', partner)
github pyccel / pyccel / tests / old / scripts / mpi / core / scatter.py View on Github external
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_scatter
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)

master    = 1
nb_values = 8

block_length = nb_values / size

data = zeros(block_length, int)

if rank == master:
    values = zeros(nb_values, int)
    for i in range(0, nb_values):
        values[i] = 1000 + i

    print('I, process ', rank ,' send my values array', values)

mpi_scatter (values, block_length, MPI_INTEGER,
github pyccel / pyccel / tests / old / scripts / mpi / core / alltoall.py View on Github external
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_alltoall
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(nb_values, int)
for i in range(0, nb_values):
    values[i] = 1000 + rank*nb_values + i

print('I, process ', rank, 'sent my values array : ', values)
# ...

# ...
data = zeros(nb_values, int)
github pyccel / pyccel / tests / old / scripts / mpi / core / split.py View on Github external
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:
    key = -1
github pyccel / pyccel / tests / old / scripts / mpi / core / cart2d_1.py View on Github external
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)

print("I, ", rank_in_topo, " process, has neighbor :", neighbor)

# Destruction of the communicators
mpi_comm_free (comm_2d, ierr)

mpi_finalize(ierr)
github pyccel / pyccel / tests / old / scripts / mpi / core / cart2d_2.py View on Github external
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

# Every row of the grid must be a 1D cartesian topology
remain_dims = [True, False]
github pyccel / pyccel / mpi_utils.py View on Github external
self.steps   = [1, 1]
        self.periods = [False, True]
        self.reorder = False
        # ...

        # ... TODO: remove from here
        ierr = -1
        size = -1
        rank = -1
        rank_in_topo = -1
        self.comm_cart = -1

        comm = mpi_comm_world
        mpi_comm_size(comm, size, ierr)
        mpi_comm_rank(comm, 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, rank_in_topo, ierr)
        mpi_cart_coords (self.comm_cart, rank_in_topo, self.ndims, self.coords, ierr)

        # X-axis limits
github pyccel / pyccel / pyccel / stdlib / parallel / mpi.py View on Github external
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