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 basic communication. 8 9from __future__ import print_function 10import mpi 11 12def ring_test(comm, value, kind, root): 13 next_peer = (comm.rank + 1) % comm.size; 14 prior_peer = (comm.rank + comm.size - 1) % comm.size; 15 16 if comm.rank == root: 17 print ("Passing %s around a ring from root %d..." % (kind, root)), 18 comm.send(next_peer, 0, value) 19 (other_value, stat) = comm.recv(return_status = True) 20 assert value == other_value 21 assert stat.source == prior_peer 22 assert stat.tag == 0 23 else: 24 msg = comm.probe() 25 other_value = comm.recv(msg.source, msg.tag) 26 assert value == other_value 27 comm.send(next_peer, 0, other_value) 28 29 comm.barrier() 30 if comm.rank == root: 31 print ("OK") 32 pass 33 34if mpi.world.size < 2: 35 print ("ERROR: ring_test.py must be executed with more than one process") 36 mpi.world.abort(-1); 37 38ring_test(mpi.world, 17, 'integers', 0) 39ring_test(mpi.world, 17, 'integers', 1) 40ring_test(mpi.world, 'Hello, World!', 'string', 0) 41ring_test(mpi.world, 'Hello, World!', 'string', 1) 42ring_test(mpi.world, ['Hello', 'MPI', 'Python', 'World'], 'list of strings', 0) 43ring_test(mpi.world, ['Hello', 'MPI', 'Python', 'World'], 'list of strings', 1) 44