예제 #1
0
    def test_validate_shape_called(self):
        shape_int = 1
        with mock.patch('mpids.MPInumpy.array_creation._validate_shape'
                        ) as mock_obj_int:
            mpi_np.ones(shape_int)
        mock_obj_int.assert_called_with(shape_int)

        shape_tuple = (1, 2)
        with mock.patch('mpids.MPInumpy.array_creation._validate_shape'
                        ) as mock_obj_tuple:
            mpi_np.ones(shape_tuple)
        mock_obj_tuple.assert_called_with(shape_tuple)
예제 #2
0
 def test_return_behavior_from_all_ranks_with_tuple_shape(self):
     for root in range(self.size):
         shape = None
         self.assertTrue(shape is None)
         if self.rank == root:
             shape = self.tuple_shape
         mpi_np_ones = mpi_np.ones(shape,
                                   comm=self.comm,
                                   root=root,
                                   dist=self.dist)
         self.assertTrue(isinstance(mpi_np_ones, mpi_np.MPIArray))
         self.assertTrue(isinstance(mpi_np_ones, self.dist_class))
         self.assertEqual(mpi_np_ones.comm, self.comm)
         self.assertEqual(mpi_np_ones.dist, self.dist)
         self.assertTrue(np.alltrue((mpi_np_ones) == (1)))
예제 #3
0
 def test_validate_shape_errors_propegated(self):
     with mock.patch('mpids.MPInumpy.array_creation._validate_shape',
                     side_effect=Exception('Mock Execption')) as mock_obj:
         with self.assertRaises(Exception):
             mpi_np.ones(1)
예제 #4
0
from mpi4py import MPI
import numpy as np

import mpids.MPInumpy as mpi_np

if __name__ == "__main__":

    #Capture default communicator, MPI process rank, and number of MPI processes
    comm = MPI.COMM_WORLD
    rank = comm.Get_rank()
    size = comm.Get_size()

    note = "Note: creation routines are using their default MPI related kwargs."
    note += "\nDefault kwargs:"
    note += " routine(..., comm=MPI.COMM_WORLD, root=0, dist='b')\n"
    print(note) if rank == 0 else None

    #Ones, shape based distributed array initialized with ones
    print('From ones(array_shape) Routine:') if rank == 0 else None
    array_shape = (size, size)
    mpi_ones_array = mpi_np.ones(array_shape)
    print('Local Array Result Rank {}:\n{}'.format(rank, mpi_ones_array))
    print() if rank == 0 else None