def _execute_reduction_test_int_min(self, is_allreduce):
        my_rank = mpi.rank
        rank_to_reduce_on = 0

        my_value = my_rank - 2 # this is an int

        if is_allreduce:
            min_val = mpi.allreduce(mpi.world, my_value, mpi.MPI_op.MIN)
        else:
            min_val = mpi.reduce(mpi.world, my_value, rank_to_reduce_on, mpi.MPI_op.MIN)

        if is_allreduce or my_rank == rank_to_reduce_on:
            self.assertEqual(-2, min_val)
    def _execute_reduction_test_int_max(self, is_allreduce):
        my_rank = mpi.rank
        rank_to_reduce_on = 0

        my_value = my_rank + 2 # this is an int

        if is_allreduce:
            max_val = mpi.allreduce(mpi.world, my_value, mpi.MPI_op.MAX)
        else:
            max_val = mpi.reduce(mpi.world, my_value, rank_to_reduce_on, mpi.MPI_op.MAX)

        if is_allreduce or my_rank == rank_to_reduce_on:
            self.assertEqual(mpi.size+1, max_val)
    def _execute_reduction_test_int_sum(self, is_allreduce):
        my_rank = mpi.rank
        rank_to_reduce_on = 0

        my_value = my_rank+1 # this is an int

        if is_allreduce:
            sum_val = mpi.allreduce(mpi.world, my_value, mpi.MPI_op.SUM)
        else:
            sum_val = mpi.reduce(mpi.world, my_value, rank_to_reduce_on, mpi.MPI_op.SUM)

        if is_allreduce or my_rank == rank_to_reduce_on:
            comm_size = mpi.size
            exp_val = int((comm_size)*(comm_size+1)/2)
            self.assertEqual(exp_val, sum_val)
 def Reduce(self, my_value, rank_to_reduce_on, mpi_op):
     self._CheckInputFor_Reduce(my_value, rank_to_reduce_on, mpi_op)
     return mpi.reduce(mpi.world, my_value, rank_to_reduce_on,
                       mpi_op_types_dict[mpi_op])