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]) if rank == dest: mpi_recv(x[1], count, MPI_REAL8, source, tag2, comm, status, ierr) print("> test 2: processor ", rank, " got ", x[1])
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)
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]) if rank == dest: mpi_recv(x[1], 1, MPI_DOUBLE, source, tag2, comm, status, ierr) print("> test 2: processor ", rank, " got ", x[1]) # ...
# 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)
nb_columns = 4 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_line datatype type_line = -1 mpi_type_vector (nb_columns, 1, nb_lines, MPI_INTEGER, type_line, ierr) # Validation of the type_line datatype mpi_type_commit (type_line, ierr) # Sending of the first column if ( rank == 0 ): mpi_send (a[1,0], nb_columns, MPI_INTEGER, 1, tag, comm , ierr) # Reception in the last column if ( rank == 1 ): mpi_recv (a[nb_lines-1,0], 1, type_line, 0, tag, comm, status, ierr) print('I process ', rank, ', has a = ', a) # Free the datatype mpi_type_free (type_line, ierr) mpi_finalize(ierr)