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