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 gather() collective. 8 9from __future__ import print_function 10import mpi 11from generators import * 12 13def gather_test(comm, generator, kind, root): 14 if comm.rank == root: 15 print ("Gathering %s to root %d..." % (kind, root)), 16 my_value = generator(comm.rank) 17 result = mpi.gather(comm, my_value, root) 18 if comm.rank == root: 19 for p in range(0, comm.size): 20 assert result[p] == generator(p) 21 print ("OK.") 22 else: 23 assert result == None 24 return 25 26gather_test(mpi.world, int_generator, "integers", 0) 27gather_test(mpi.world, int_generator, "integers", 1) 28gather_test(mpi.world, gps_generator, "GPS positions", 0) 29gather_test(mpi.world, gps_generator, "GPS positions", 1) 30gather_test(mpi.world, string_generator, "strings", 0) 31gather_test(mpi.world, string_generator, "strings", 1) 32gather_test(mpi.world, string_list_generator, "list of strings", 0) 33gather_test(mpi.world, string_list_generator, "list of strings", 1) 34