Menu

PnumpyExample

Alexander Pletzer

pnumpy examples

All examples require you to import

import pnumpy

Distributed array

Use this class if you want the flexibility to expose any parts of your array to other processes.

# create dist array and fill with zeros
da = pnumpy.daZeros( (2,3), numpy.float32 )
# processor rank and number of processes
rk = da.rk
nprocs = da.sz

# expose the high end of the first index (-1 refers to last index in python)
north = ( slice(-1, None, None), slice(0, None, None) )
da.expose( slce=north, winID='n' )

# set the data to the rank value
da[:] = rk

# free the data
da.free()

You can expose as many parts as you want. The number of slices should match the number if indices in the array. slice(0, None, None) refers to 0:-1 with a stride of one.

Ghosted distributed array

Use a ghosted distributed array if you want to expose the boundary of the array, otherwise also known as the halo. The thickness of the halo can be prescribed.

da = pnumpy.ghZeros( (2,3), numpy.float32, ghostWidth=1 )

This will expose one ghost along the north, south, east, and west sides of the array. The winID for these parts are (1,0), (-1,0), (0,1), and (0,-1) respectively.

Accessing remote data

The following method can be used to access remote data

# use the key form the expose method to access the halo on a different process
remoteData = da.get(remoteRank, winID='n')

or

# ghosted array takes a tuple as winID
remoteData = da.get(remoteRank, winID=(1,0))

Note that for ghosted distributed arrays, the key to the window is a tuple with elements -1, 0, or 1. The value -1 refers to the low end of the variable, +1 to the high end, and 0 indicates variation along this index.


Related

Wiki: Home