Exemple #1
0
# since we are calling mpi subroutines
ierr = np.int32(-1)
size = np.int32(-1)
rank = np.int32(-1)

mpi_init(ierr)

comm = mpi_comm_world
mpi_comm_size(comm, size, ierr)
mpi_comm_rank(comm, rank, ierr)

nx = 4
x = np.zeros(nx)

if rank == 0:
    x[:] = 1.0

source = np.int32(0)
dest = np.int32(1)

# ...
tag1 = np.int32(1234)
if rank == source:
    x[1] = 2.0
    count = np.int32(1)
    mpi_send(x[1], count, MPI_REAL8, dest, tag1, comm, ierr)
    print("> processor ", rank, " sent x(1) = ", x)
# ...

mpi_finalize(ierr)
Exemple #2
0
ny = np.int32(3 * 2)
x = np.zeros(nx)
y = np.zeros((3, 2))

if rank == 0:
    x[:] = 1.0
    y[:, :] = 1.0

source = np.int32(0)
dest = np.int32(1)
status = np.zeros(mpi_status_size, 'int32')

# ...
tag1 = np.int32(1234)
if rank == source:
    mpi_send(x, nx, MPI_REAL8, dest, tag1, comm, ierr)
    print("> test 1: processor ", rank, " sent ", x)

if rank == dest:
    mpi_recv(x, nx, MPI_REAL8, source, tag1, comm, status, ierr)
    print("> test 1: processor ", rank, " got  ", x)
# ...

# ...
tag2 = np.int32(5678)
count = np.int32(1)
if rank == source:
    x[:] = 0.0
    x[1] = 2.0
    mpi_send(x[1], count, MPI_REAL8, dest, tag2, comm, ierr)
    print("> test 2: processor ", rank, " sent ", x[1])
Exemple #3
0
a      = np.zeros((nb_lines, nb_columns), 'int')
status = np.zeros(mpi_status_size, dtype='int32')

# Initialization of the matrix on each process
a[:,:] = 1000 + rank

# Definition of the type_column datatype
type_column = np.int32(-1)
mpi_type_contiguous (nb_lines, MPI_INTEGER8, type_column, ierr)

# Validation of the type_column datatype
mpi_type_commit (type_column, ierr)

# Sending of the first column
if ( rank == 0 ):
    count = np.int32(1)
    dest  = np.int32(1)
    mpi_send (a[0,0], count, type_column, dest, tag, comm, ierr)

# Reception in the last column
if ( rank == 1 ):
    source = np.int32(0)
    mpi_recv (a[0,nb_columns-1], nb_lines, MPI_INTEGER8, source, tag, comm, status, ierr)

print('I process ', rank, ', has a = ', a)

# Free the datatype
mpi_type_free (type_column, ierr)

mpi_finalize(ierr)
Exemple #4
0
# Initialization of the matrix on each process
a[:, :] = 1000 + rank

# Definition of the type_line datatype
blocklength = np.int32(1)
type_line = np.int32(-1)
mpi_type_vector(nb_columns, blocklength, nb_lines, MPI_INTEGER8, type_line,
                ierr)

# Validation of the type_line datatype
mpi_type_commit(type_line, ierr)

# Sending of the first column
if (rank == 0):
    dest = np.int32(1)
    mpi_send(a[1, 0], nb_columns, MPI_INTEGER8, dest, tag, comm, ierr)

# Reception in the last column
if (rank == 1):
    count = np.int32(1)
    source = np.int32(0)
    mpi_recv(a[nb_lines - 1, 0], count, type_line, source, tag, comm, status,
             ierr)

print('I process ', rank, ', has a = ', a)

# Free the datatype
mpi_type_free(type_line, ierr)

mpi_finalize(ierr)
Exemple #5
0
tag = 100

a = zeros((nb_lines, nb_columns), 'int')
status = zeros(mpi_status_size, 'int')

# Initialization of the matrix on each process
a[:, :] = 1000 + rank

# Definition of the type_column datatype
type_column = -1
mpi_type_contiguous(nb_lines, MPI_INTEGER, type_column, ierr)

# Validation of the type_column datatype
mpi_type_commit(type_column, ierr)

# Sending of the first column
if (rank == 0):
    mpi_send(a[0, 0], 1, type_column, 1, tag, comm, ierr)

# Reception in the last column
if (rank == 1):
    mpi_recv(a[0, nb_columns - 1], nb_lines, MPI_INTEGER, 0, tag, comm, status,
             ierr)

print('I process ', rank, ', has a = ', a)

# Free the datatype
mpi_type_free(type_column, ierr)

mpi_finalize(ierr)
ny = 3 * 2
x = zeros(nx)
y = zeros((3, 2))

if rank == 0:
    x[:] = 1.0
    y[:, :] = 1.0

source = 0
dest = 1
status = zeros(mpi_status_size, 'int')

# ...
tag1 = 1234
if rank == source:
    mpi_send(x, nx, MPI_DOUBLE, dest, tag1, comm, ierr)
    print("> test 1: processor ", rank, " sent ", x)

if rank == dest:
    mpi_recv(x, nx, MPI_DOUBLE, source, tag1, comm, status, ierr)
    print("> test 1: processor ", rank, " got  ", x)
# ...

# ...
tag2 = 5678
if rank == source:
    x[:] = 0.0
    x[1] = 2.0
    mpi_send(x[1], 1, MPI_DOUBLE, dest, tag2, comm, ierr)
    print("> test 2: processor ", rank, " sent ", x[1])
# 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)

nx = 4
x = zeros(nx)

if rank == 0:
    x[:] = 1.0

source = 0
dest   = 1

# ...
tag1 = 1234
if rank == source:
    x[1] = 2.0
    mpi_send(x[1], 1, MPI_DOUBLE, dest, tag1, comm, ierr)
    print("> processor ", rank, " sent x(1) = ", x)
# ...

mpi_finalize(ierr)