skeleton_content_test.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 skeleton/content
  6. import boost.parallel.mpi as mpi
  7. import skeleton_content
  8. def test_skeleton_and_content(comm, root, manual_broadcast = True):
  9. assert manual_broadcast
  10. # Setup data
  11. list_size = comm.size + 7
  12. original_list = skeleton_content.list_int()
  13. for i in range(0,list_size):
  14. original_list.push_back(i)
  15. if comm.rank == root:
  16. # Broadcast skeleton
  17. print ("Broadcasting integer list skeleton from root %d..." % (root)),
  18. if manual_broadcast:
  19. for p in range(0,comm.size):
  20. if p != comm.rank:
  21. comm.send(p, 0, value = mpi.skeleton(original_list))
  22. print "OK."
  23. # Broadcast content
  24. print ("Broadcasting integer list content from root %d..." % (root)),
  25. if manual_broadcast:
  26. for p in range(0,comm.size):
  27. if p != comm.rank:
  28. comm.send(p, 0, value = mpi.get_content(original_list))
  29. print "OK."
  30. # Broadcast reversed content
  31. original_list.reverse()
  32. print ("Broadcasting reversed integer list content from root %d..." % (root)),
  33. if manual_broadcast:
  34. for p in range(0,comm.size):
  35. if p != comm.rank:
  36. comm.send(p, 0, value = mpi.get_content(original_list))
  37. print "OK."
  38. else:
  39. # Allocate some useless data, to try to get the addresses of
  40. # the underlying lists used later to be different across
  41. # processors.
  42. junk_list = skeleton_content.list_int()
  43. for i in range(0,comm.rank * 3 + 1):
  44. junk_list.push_back(i)
  45. # Receive the skeleton of the list
  46. if manual_broadcast:
  47. transferred_list_skeleton = comm.recv(root, 0)
  48. assert transferred_list_skeleton.object.size == list_size
  49. # Receive the content and check it
  50. transferred_list = transferred_list_skeleton.object
  51. if manual_broadcast:
  52. comm.recv(root, 0, mpi.get_content(transferred_list))
  53. assert transferred_list == original_list
  54. # Receive the content (again) and check it
  55. original_list.reverse()
  56. if manual_broadcast:
  57. comm.recv(root, 0, mpi.get_content(transferred_list))
  58. assert transferred_list == original_list
  59. test_skeleton_and_content(mpi.world, 0)
  60. test_skeleton_and_content(mpi.world, 1)