Example #1
0
#   assert Numeric.allclose(Y, testArray[myid*MP:(myid+1)*MP,:])   

#   if myid == 0:
#     print "Scatter communication of 2D numeric complex array OK"



  # Test gather  - with/without buffers (arrays, strings)
  #
  N = 17 #Number of elements
      
  testString = 'AB'
  X = '_'*(len(testString)*numproc)    #Blanks caused errors when numproc >= 6 
  pypar.raw_gather(testString, X, 0)

  Y =  pypar.gather(testString, 0) 
  
  if myid == 0:
    assert X == 'AB' * numproc
    assert Y == 'AB' * numproc
    print "Gather communication of strings OK"
  

  testArray = Numeric.array(range(N))
  X = Numeric.zeros(N*numproc)
  pypar.raw_gather(testArray, X, 0)

  Y = pypar.gather(testArray, 0)
  
  if myid == 0:
    for i in range(numproc):       
Example #2
0


  # Test gather  - with/without buffers (arrays, strings)
  #
  N = 17 #Number of elements
      
  testString = 'AB'
  s_size = 2 # to help test
  X = ' '*(s_size*numproc)
  pypar.raw_gather(testString, s_size, X, 0, 0)

  if myid == 0:
    assert X == 'AB' * numproc

  Y =  pypar.gather(testString, s_size, 0) 
  #print myid, Y
  
  if myid == 0:
    assert X == 'AB' * numproc
    assert Y == 'AB' * numproc
    print "Gather communication of strings OK"
  

  testArray = Numeric.array(range(N))
  s_size = N   
  X = Numeric.zeros(s_size*numproc)
  pypar.raw_gather(testArray, s_size, X, 0, 0)

  Y = pypar.gather(testArray, s_size, 0)
  
Example #3
0
def raw_gather(x, buffer, source, vanilla=0):
    pypar.gather(x, source, buffer=buffer, vanilla=0)  
Example #4
0
#   assert numpy.allclose(Y, testArray[myid*MP:(myid+1)*MP,:])   

#   if myid == 0:
#     print "Scatter communication of 2D numeric complex array OK"



  # Test gather  - with/without buffers (arrays, strings)
  #
  N = 17 #Number of elements
      
  testString = 'AB'
  X = '_'*(len(testString)*numproc)    #Blanks caused errors when numproc >= 6 
  raw_gather(testString, X, 0)

  Y =  pypar.gather(testString, 0) 
  
  if myid == 0:
    assert X == 'AB' * numproc
    assert Y == 'AB' * numproc
    print "Gather communication of strings OK"
  

  testArray = numpy.array(range(N)).astype('i')
  X = numpy.zeros(N*numproc).astype('i')
  raw_gather(testArray, X, 0)

  Y = pypar.gather(testArray, 0)
  
  if myid == 0:
    for i in range(numproc):       
Example #5
0
Dale Roberts <*****@*****.**>
"""

import numpy as np
import pypar as pp

N = 100000
ncpu = pp.size()
myid = pp.rank()

def mc_pi(points):
    inside = 0
    for x, y in points:
        if x**2 + y**2 <= 1:
            inside += 1
    return 4*float(inside)/len(points)

points = np.random.random((N, 2)) #FIXME: this is done on each cpu

mypoints = pp.scatter(points, 0)
mypi = np.array([mc_pi(mypoints)]) #FIXME: casting float as np.array for gather

pi = sum(pp.gather(mypi, 0)) / ncpu

if myid == 0:
    abserror = abs(pi - np.pi)
    print("pi: %.16f abs error: %.16f" % (pi, abserror))

pp.finalize()
Example #6
0
#   raw_scatter(testArray, X, 0)
#   Y = pypar.scatter(testArray, 0)
#   assert numpy.allclose(X, Y)
#   assert numpy.allclose(X, testArray[myid*MP:(myid+1)*MP,:])
#   assert numpy.allclose(Y, testArray[myid*MP:(myid+1)*MP,:])
#   if myid == 0:
#     print "Scatter communication of 2D numeric complex array OK"
# Test gather  - with/without buffers (arrays, strings)
#
    N = 17  # Number of elements

    testString = 'AB'
    # Blanks caused errors when numproc >= 6
    X = '_' * (len(testString) * numproc)

    pypar.gather(testString, 0, buffer=X)  # Using buffer
    Y = pypar.gather(testString, 0)  # Create buffer automatically

    if myid == 0:
        assert X == 'AB' * numproc
        assert Y == 'AB' * numproc
        print "Gather communication of strings OK"

    testArray = numpy.array(range(N)).astype('i')
    X = numpy.zeros(N * numproc).astype('i')

    pypar.gather(testArray, 0, buffer=X)  # Using buffer
    Y = pypar.gather(testArray, 0)  # Create buffer automatically

    if myid == 0:
        for i in range(numproc):
Example #7
0
#   assert numpy.allclose(X, testArray[myid*MP:(myid+1)*MP,:])
#   assert numpy.allclose(Y, testArray[myid*MP:(myid+1)*MP,:])   

#   if myid == 0:
#     print "Scatter communication of 2D numeric complex array OK"



  # Test gather  - with/without buffers (arrays, strings)
  #
  N = 17 # Number of elements
      
  testString = 'AB'
  X = '_'*(len(testString)*numproc) # Blanks caused errors when numproc >= 6 

  pypar.gather(testString, 0, buffer=X) # Using buffer  
  Y = pypar.gather(testString, 0) # Create buffer automatically
  
  if myid == 0:
    assert X == 'AB' * numproc
    assert Y == 'AB' * numproc
    print "Gather communication of strings OK"
  

  testArray = numpy.array(range(N)).astype('i')
  X = numpy.zeros(N*numproc).astype('i')

  pypar.gather(testArray, 0, buffer=X) # Using buffer  
  Y = pypar.gather(testArray, 0) # Create buffer automatically

  if myid == 0: