]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mpi/test/python/reduce_test.py
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / mpi / test / python / reduce_test.py
1 # Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>.
2
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)
6
7 # Test reduce() collective.
8
9 import boost.parallel.mpi as mpi
10 from generators import *
11
12 def reduce_test(comm, generator, kind, op, op_kind, root):
13 if comm.rank == 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)
17 if comm.rank == 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
22 print "OK."
23 else:
24 assert result == None
25 return
26
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)