def _init(): neutrons = mcni.neutron_buffer(ntotneutrons) for i in range(ntotneutrons): neutrons[i] = mcni.neutron( r = (0,0,i), ) continue from mcni.utils import mpi global mpirank mpirank = mpi.rank mpisize = mpi.world.size if mpisize != 3: raise RuntimeError, __doc__ import os channel = 1000 if mpirank == 0: if os.path.exists(neutron_storage_path): os.remove(neutron_storage_path) from mcni.neutron_storage.Storage import Storage storage = Storage(neutron_storage_path, 'w') storage.write(neutrons) del storage for i in range(1, mpisize): mpi.send(0, i, channel) continue else: mpi.receive(0, channel)
def main(self): base.main(self) neutrons = {} #get neutrons from other nodes from mcni.neutron_storage import neutrons_from_npyarr as a2n, neutrons_as_npyarr as n2a, ndblsperneutron from mcni.utils.mpi import rank as mpirank, send, receive, world tag = 999 if mpirank != 0: arr = n2a( self.inventory.recorder.neutrons ) print "Node %s: sending array of shape %s" % (mpirank, arr.shape,) send(arr , 0, tag ) else: for peer in range(1, world.size): arr = receive( peer, tag ) arr.shape = -1, ndblsperneutron neutrons[ peer ] = a2n( arr ) print "Node %s: received array of shape %s" % (mpirank, arr.shape) continue neutrons[ 0] = self.inventory.recorder.neutrons #compare if mpirank == 0: for peer in range(1, world.size): assert neutrons[0][0].state.velocity[2] != neutrons[peer][0].state.velocity[2] continue return
def main(self): super(App, self).main() from mcni.utils.mpi import world, size, rank, send, receive print "in app.main(): mpi world %s, size %s" % (world, size) print "mode=%s, rank=%s" % (self.inventory.mode, rank) send(rank, 1 - rank, tag=100) received = receive(1 - rank, tag=100) print "my rank: %s, received from %s: %s(%s)" % ( rank, 1 - rank, received, type(received)) self.testFacility.assertEqual(1 - rank, received) self.testFacility.assertEqual(type(received), int) return
def main(self): super(App, self).main() from mcni.utils.mpi import world, size, rank, send, receive print "in app.main(): mpi world %s, size %s" % (world, size) print "mode=%s, rank=%s" % ( self.inventory.mode, rank) send(rank, 1-rank, tag=100) received = receive(1-rank, tag=100) print "my rank: %s, received from %s: %s(%s)" % ( rank, 1-rank, received, type(received)) self.testFacility.assertEqual(1-rank, received) self.testFacility.assertEqual(type(received), int) return