/usr/lib/python2.7/dist-packages/PySPH-1.0a4.dev0-py2.7-linux-x86_64.egg/pyzoltan/core/tests/zcomm.py is in python-pysph 0~20160514.git91867dc-4build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | """Tests for the Zoltan unstructured communication package"""
import mpi4py.MPI as mpi
import numpy as np
from numpy import random
# import the unstructured communication package
from pyzoltan.core import zoltan_comm
from pyzoltan.core import zoltan
# MPI comm, rank and size
comm = mpi.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()
# Initialize the Zoltan library
zoltan_version = zoltan.Zoltan_Initialize()
# each processor creates some random data
numObjectsTotal = 1<<10
x = random.random(numObjectsTotal)
gids = np.array( np.arange(size * numObjectsTotal) )[rank*numObjectsTotal:(rank+1)*numObjectsTotal]
gids = gids.astype(np.uint32)
# arbitrarily assign some objects to be sent to some other processor
nsend = np.int32( random.random_integers(low=1, high=5) )
object_ids = random.random_integers( low=0, high=numObjectsTotal, size=nsend )
proclist = random.random_integers(low=0, high=size-1, size=nsend).astype(np.int32)
my_indices = np.where(proclist == rank)[0]
proclist[my_indices] = (rank + 1)%size
# create the ZComm object
tag = np.int32(0)
zcomm = zoltan_comm.ZComm(comm, tag=tag, nsend=nsend, proclist=proclist)
# the data to send and receive
senddata = x[ object_ids ]
recvdata = np.ones( zcomm.nreturn )
# use zoltan to exchange doubles
print("Proc %d, Sending %s to %s"%(rank, senddata, proclist))
zcomm.Comm_Do(senddata, recvdata)
print("Proc %d, Received %s"%(rank, recvdata))
# use zoltan to exchange unsigned ints
senddata = gids[ object_ids ]
recvdata = np.ones(zcomm.nreturn, dtype=np.uint32)
zcomm.set_nbytes(recvdata.itemsize, recvdata.dtype)
print("Proc %d, Sending %s to %s"%(rank, senddata, proclist))
zcomm.Comm_Do(senddata, recvdata)
print("Proc %d, Received %s"%(rank, recvdata))
# Test the Comm Reverse function
# modify the received data
recvdata[:] = rank
updated_info = np.zeros(zcomm.nsend, dtype=senddata.dtype)
print('Proc %d, sending updated data %s'%(rank, recvdata))
zcomm.Comm_Do_Reverse(recvdata, updated_info)
print('Proc %d, received updated data %s'%(rank, updated_info))
|