]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 all_reduce() collective. | |
8 | ||
20effc67 TL |
9 | from __future__ import print_function |
10 | import mpi | |
7c673cae FG |
11 | from generators import * |
12 | ||
13 | def all_reduce_test(comm, generator, kind, op, op_kind): | |
14 | if comm.rank == 0: | |
15 | print ("Reducing to %s of %s..." % (op_kind, kind)), | |
16 | my_value = generator(comm.rank) | |
17 | result = mpi.all_reduce(comm, my_value, op) | |
18 | expected_result = generator(0); | |
19 | for p in range(1, comm.size): | |
20 | expected_result = op(expected_result, generator(p)) | |
21 | ||
22 | assert result == expected_result | |
23 | if comm.rank == 0: | |
20effc67 | 24 | print ("OK.") |
7c673cae FG |
25 | return |
26 | ||
27 | all_reduce_test(mpi.world, int_generator, "integers", lambda x,y:x + y, "sum") | |
28 | all_reduce_test(mpi.world, int_generator, "integers", lambda x,y:x * y, "product") | |
29 | all_reduce_test(mpi.world, string_generator, "strings", lambda x,y:x + y, "concatenation") | |
30 | all_reduce_test(mpi.world, string_list_generator, "list of strings", lambda x,y:x + y, "concatenation") |