gather_test.py 1.2 KB

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