broadcast_test.py 1002 B

1234567891011121314151617181920212223242526272829
  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 broadcast() collective.
  6. import boost.parallel.mpi as mpi
  7. def broadcast_test(comm, value, kind, root):
  8. if comm.rank == root:
  9. print ("Broadcasting %s from root %d..." % (kind, root)),
  10. got_value = mpi.broadcast(comm, value, root)
  11. assert got_value == value
  12. if comm.rank == root:
  13. print "OK."
  14. return
  15. broadcast_test(mpi.world, 17, 'integer', 0)
  16. broadcast_test(mpi.world, 17, 'integer', 1)
  17. broadcast_test(mpi.world, 'Hello, World!', 'string', 0)
  18. broadcast_test(mpi.world, 'Hello, World!', 'string', 1)
  19. broadcast_test(mpi.world, ['Hello', 'MPI', 'Python', 'World'],
  20. 'list of strings', 0)
  21. broadcast_test(mpi.world, ['Hello', 'MPI', 'Python', 'World'],
  22. 'list of strings', 1)