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 9 from __future__ import print_function 10 import mpi 11 from generators import * 12 13 def 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 30 scatter_test(mpi.world, int_generator, "integers", 0) 31 scatter_test(mpi.world, int_generator, "integers", 1) 32 scatter_test(mpi.world, gps_generator, "GPS positions", 0) 33 scatter_test(mpi.world, gps_generator, "GPS positions", 1) 34 scatter_test(mpi.world, string_generator, "strings", 0) 35 scatter_test(mpi.world, string_generator, "strings", 1) 36 scatter_test(mpi.world, string_list_generator, "list of strings", 0) 37 scatter_test(mpi.world, string_list_generator, "list of strings", 1) 38