scatter_test.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. # Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>.
  2. # Use, modification and distribution is subject to the Boost Software
  3. # License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  4. # http://www.boost.org/LICENSE_1_0.txt)
  5. # Test scatter() collective.
  6. import boost.parallel.mpi as mpi
  7. from generators import *
  8. def scatter_test(comm, generator, kind, root):
  9. if comm.rank == root:
  10. print ("Scattering %s from root %d..." % (kind, root)),
  11. if comm.rank == root:
  12. values = list()
  13. for p in range(0, comm.size):
  14. values.append(generator(p))
  15. result = mpi.scatter(comm, values, root = root)
  16. else:
  17. result = mpi.scatter(comm, root = root);
  18. assert result == generator(comm.rank)
  19. if comm.rank == root: print "OK."
  20. return
  21. scatter_test(mpi.world, int_generator, "integers", 0)
  22. scatter_test(mpi.world, int_generator, "integers", 1)
  23. scatter_test(mpi.world, gps_generator, "GPS positions", 0)
  24. scatter_test(mpi.world, gps_generator, "GPS positions", 1)
  25. scatter_test(mpi.world, string_generator, "strings", 0)
  26. scatter_test(mpi.world, string_generator, "strings", 1)
  27. scatter_test(mpi.world, string_list_generator, "list of strings", 0)
  28. scatter_test(mpi.world, string_list_generator, "list of strings", 1)