]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpi/test/python/reduce_test.py
1 # Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>.
3 # Use, modification and distribution is subject to the Boost Software
4 # License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
5 # http://www.boost.org/LICENSE_1_0.txt)
7 # Test reduce() collective.
9 import boost
.parallel
.mpi
as mpi
10 from generators
import *
12 def reduce_test(comm
, generator
, kind
, op
, op_kind
, root
):
14 print ("Reducing to %s of %s at root %d..." % (op_kind
, kind
, root
)),
15 my_value
= generator(comm
.rank
)
16 result
= mpi
.reduce(comm
, my_value
, op
, root
)
18 expected_result
= generator(0);
19 for p
in range(1, comm
.size
):
20 expected_result
= op(expected_result
, generator(p
))
21 assert result
== expected_result
27 reduce_test(mpi
.world
, int_generator
, "integers", lambda x
,y
:x
+ y
, "sum", 0)
28 reduce_test(mpi
.world
, int_generator
, "integers", lambda x
,y
:x
* y
, "product", 1)
29 reduce_test(mpi
.world
, int_generator
, "integers", min, "minimum", 0)
30 reduce_test(mpi
.world
, string_generator
, "strings", lambda x
,y
:x
+ y
, "concatenation", 0)
31 reduce_test(mpi
.world
, string_list_generator
, "list of strings", lambda x
,y
:x
+ y
, "concatenation", 0)