1#!/usr/bin/env python 2# Copyright (C) 2006 Douglas Gregor <doug.gregor -at- gmail.com>. 3 4# Use, modification and distribution is subject to the Boost Software 5# License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 6# http://www.boost.org/LICENSE_1_0.txt) 7 8# Test broadcast() collective. 9 10from __future__ import print_function 11import mpi 12 13def broadcast_test(comm, value, kind, root): 14 if comm.rank == 0: 15 print ("Broadcasting %s from root %d..." % (kind, root)), 16 got_value = None 17 got_value = mpi.broadcast(comm, value, root) 18 if comm.rank == 0: 19 print ("OK.") 20 return 21 22broadcast_test(mpi.world, 17, 'integer', 0) 23broadcast_test(mpi.world, 'Hello, World!', 'string', 0) 24broadcast_test(mpi.world, ['Hello', 'MPI', 'Python', 'World'], 25 'list of strings', 0) 26if mpi.world.size > 1: 27 broadcast_test(mpi.world, 17, 'integer', 1) 28 broadcast_test(mpi.world, 'Hello, World!', 'string', 1) 29 broadcast_test(mpi.world, ['Hello', 'MPI', 'Python', 'World'], 30 'list of strings', 1) 31 32 33