1# Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>. 2 3# Use, modification and distribution is subject to the Boost Software 4# License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 5# http://www.boost.org/LICENSE_1_0.txt) 6 7# Test skeleton/content 8 9from __future__ import print_function 10import mpi 11import skeleton_content 12 13def test_skeleton_and_content(comm, root, manual_broadcast = True): 14 assert manual_broadcast 15 16 # Setup data 17 list_size = comm.size + 7 18 original_list = skeleton_content.list_int() 19 for i in range(0,list_size): 20 original_list.push_back(i) 21 22 if comm.rank == root: 23 # Broadcast skeleton 24 print ("Broadcasting integer list skeleton 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.skeleton(original_list)) 29 print ("OK.") 30 31 # Broadcast content 32 print ("Broadcasting 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 38 print ("OK.") 39 40 # Broadcast reversed content 41 original_list.reverse() 42 print ("Broadcasting reversed integer list content from root %d..." % (root)), 43 if manual_broadcast: 44 for p in range(0,comm.size): 45 if p != comm.rank: 46 comm.send(p, 0, value = mpi.get_content(original_list)) 47 48 print ("OK.") 49 else: 50 # Allocate some useless data, to try to get the addresses of 51 # the underlying lists used later to be different across 52 # processors. 53 junk_list = skeleton_content.list_int() 54 for i in range(0,comm.rank * 3 + 1): 55 junk_list.push_back(i) 56 57 # Receive the skeleton of the list 58 if manual_broadcast: 59 transferred_list_skeleton = comm.recv(root, 0) 60 assert transferred_list_skeleton.object.size == list_size 61 62 # Receive the content and check it 63 transferred_list = transferred_list_skeleton.object 64 if manual_broadcast: 65 comm.recv(root, 0, mpi.get_content(transferred_list)) 66 assert transferred_list == original_list 67 68 # Receive the content (again) and check it 69 original_list.reverse() 70 if manual_broadcast: 71 comm.recv(root, 0, mpi.get_content(transferred_list)) 72 assert transferred_list == original_list 73 74 75test_skeleton_and_content(mpi.world, 0) 76test_skeleton_and_content(mpi.world, 1) 77