scan_test.py 1.1 KB

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 scan() collective.
  6. import boost.parallel.mpi as mpi
  7. from generators import *
  8. def scan_test(comm, generator, kind, op, op_kind):
  9. if comm.rank == 0:
  10. print ("Prefix reduction to %s of %s..." % (op_kind, kind)),
  11. my_value = generator(comm.rank)
  12. result = mpi.scan(comm, my_value, op)
  13. expected_result = generator(0);
  14. for p in range(1, comm.rank+1):
  15. expected_result = op(expected_result, generator(p))
  16. assert result == expected_result
  17. if comm.rank == 0:
  18. print "OK."
  19. return
  20. scan_test(mpi.world, int_generator, "integers", lambda x,y:x + y, "sum")
  21. scan_test(mpi.world, int_generator, "integers", lambda x,y:x * y, "product")
  22. scan_test(mpi.world, string_generator, "strings", lambda x,y:x + y, "concatenation")
  23. scan_test(mpi.world, string_list_generator, "list of strings", lambda x,y:x + y, "concatenation")