Ejemplo n.º 1
0
    def test_string(self):
        myid, ncpu = pp.rank(), pp.size()
        data = 'ABCDEFGHIJKLMNOP'  # Length = 16
        NP = len(data) / ncpu
        X = ' ' * NP

        pp.scatter(data, 0, buffer=X)  # With buffer
        Y = pp.scatter(data, 0)  # With buffer automatically created

        self.assertEqual(X, Y)
        self.assertEqual(Y, data[myid * NP:(myid + 1) * NP])
        self.assertEqual(X, data[myid * NP:(myid + 1) * NP])
Ejemplo n.º 2
0
    def test_string(self):
        myid, ncpu = pp.rank(), pp.size()
        data = 'ABCDEFGHIJKLMNOP'  # Length = 16
        NP = len(data) / ncpu
        X = ' ' * NP

        pp.scatter(data, 0, buffer=X)  # With buffer
        Y = pp.scatter(data, 0)  # With buffer automatically created

        self.assertEqual(X, Y)
        self.assertEqual(Y, data[myid * NP:(myid + 1) * NP])
        self.assertEqual(X, data[myid * NP:(myid + 1) * NP])
Ejemplo n.º 3
0
    def test_without_root(self):
        myid, ncpu = pp.rank(), pp.size()
        N = 16
        NP = N / ncpu
        data = np.array(range(N)).astype('i')
        X = np.zeros(NP).astype('i')

        pp.scatter(data, buffer=X)  # With buffer
        Y = pp.scatter(data)  # With buffer automatically created

        self.assertTrue(np.allclose(X, Y))
        self.assertTrue(np.allclose(X, data[myid * NP:(myid + 1) * NP]))
        self.assertTrue(np.allclose(Y, data[myid * NP:(myid + 1) * NP]))
Ejemplo n.º 4
0
    def test_without_root(self):
        myid, ncpu = pp.rank(), pp.size()
        N = 16
        NP = N / ncpu
        data = np.array(range(N)).astype('i')
        X = np.zeros(NP).astype('i')

        pp.scatter(data, buffer=X)  # With buffer
        Y = pp.scatter(data)  # With buffer automatically created

        self.assertTrue(np.allclose(X, Y))
        self.assertTrue(np.allclose(X, data[myid * NP:(myid + 1) * NP]))
        self.assertTrue(np.allclose(Y, data[myid * NP:(myid + 1) * NP]))
Ejemplo n.º 5
0
    def test_diff_master(self):
        myid, ncpu = pp.rank(), pp.size()
        N = 16
        NP = N / ncpu

        check = np.array(range(N)).astype('i')
        X = np.zeros(NP).astype('i')

        data = np.empty(N, 'i')

        if myid == 0:  # only generated on master
            data = np.array(range(N)).astype('i')

        pp.scatter(data, 0, buffer=X)  # With buffer
        Y = pp.scatter(data, 0)  # With buffer automatically created

        self.assertTrue(np.allclose(X, Y))
        self.assertTrue(np.allclose(X, check[myid * NP:(myid + 1) * NP]))
        self.assertTrue(np.allclose(Y, check[myid * NP:(myid + 1) * NP]))
Ejemplo n.º 6
0
    def test_diff_master(self):
        myid, ncpu = pp.rank(), pp.size()
        N = 16
        NP = N / ncpu

        check = np.array(range(N)).astype('i')
        X = np.zeros(NP).astype('i')

        data = np.empty(N, 'i')

        if myid == 0:  # only generated on master
            data = np.array(range(N)).astype('i')

        pp.scatter(data, 0, buffer=X)  # With buffer
        Y = pp.scatter(data, 0)  # With buffer automatically created

        self.assertTrue(np.allclose(X, Y))
        self.assertTrue(np.allclose(X, check[myid * NP:(myid + 1) * NP]))
        self.assertTrue(np.allclose(Y, check[myid * NP:(myid + 1) * NP]))
Ejemplo n.º 7
0
  





  # Test scatter  - with/without buffers (arrays, strings)
  #
  N = 17 #Number of elements
      
  testString = 'test' + str(myid)
  s_size = 1   
  X = ' '*s_size
  pypar.raw_scatter(testString, s_size, X, 0)
  
  Y = pypar.scatter(testString, s_size, 0)
      
  if myid == 0:
    assert X == 't'
    assert Y == 't'
    print "Scatter communication of strings OK"

  testArray = Numeric.array(range(N))
  s_size = 1   
  X = Numeric.zeros(s_size)
  pypar.raw_scatter(testArray, s_size, X, 0)
  
  Y = pypar.scatter(testArray, s_size, 0)
  

  if myid == 0:
Ejemplo n.º 8
0
def raw_scatter(x, buffer, source, vanilla=0):
    pypar.scatter(x, source, buffer=buffer, vanilla=vanilla)
Ejemplo n.º 9
0
    print "Broadcast communication of general structures OK"
  



  # Test scatter  - with/without buffers (arrays, strings)
  #
  N = 16 #Number of elements

  NP = N/numproc
  
  testString = 'ABCDEFGHIJKLMNOP'  #Length = 16
  X = ' '*NP
  pypar.raw_scatter(testString, X, 2)
  
  Y = pypar.scatter(testString, 2)

  #print 'P%d: s=%s, r=%s, %s' %(myid, testString, X, Y)

  assert X==Y, 'X=%s, Y=%s' %(X,Y)
  assert Y == testString[myid*NP:(myid+1)*NP]
  assert X == testString[myid*NP:(myid+1)*NP]

  if myid == 0:    
    print "Scatter communication of strings OK"
    

  #Scatter Arrays
  testArray = Numeric.array(range(N))
  X = Numeric.zeros(NP)
  pypar.raw_scatter(testArray, X, 0)
Ejemplo n.º 10
0
  #Y = pypar.scatter(testString, 2)


  #assert X==Y, 'X=%s, Y=%s' %(X,Y)
  #assert Y == testString[myid*NP:(myid+1)*NP]
  #assert X == testString[myid*NP:(myid+1)*NP]

  #if myid == 0:    
  #  print "Scatter communication of strings OK"
    

  #Scatter Arrays
  testArray = numpy.array(range(N)).astype('i')
  X = numpy.zeros(NP).astype('i')
  raw_scatter(testArray, X, 0)
  Y = pypar.scatter(testArray, 0)

  assert numpy.allclose(X, Y)  
  assert numpy.allclose(X, testArray[myid*NP:(myid+1)*NP])
  assert numpy.allclose(Y, testArray[myid*NP:(myid+1)*NP])   

  if myid == 0:
    print "Scatter communication of numeric integer array OK"


  testArray = numpy.array(range(N)).astype('f')
  X = numpy.zeros(NP).astype('f')
  raw_scatter(testArray, X, 0)
    
  Y = pypar.scatter(testArray, 0)
Ejemplo n.º 11
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()
Ejemplo n.º 12
0
"""
Simple scatter example.

Dale Roberts <*****@*****.**>
"""

import numpy as np
import pypar as pp

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

N = 16
NP = N/ncpu

if myid == 0:
    data = np.arange(N, dtype='i')
else:
    data = np.empty(N, dtype='i')

X = np.zeros(NP, dtype='i')

pp.scatter(data, 0, buffer=X) # With buffer
Y = pp.scatter(data, 0) # With buffer automatically created

print "id: %i X: %s" % (myid, X)
print "id: %i Y: %s" % (myid, Y)

pp.finalize()
Ejemplo n.º 13
0
    if OK is False:
        raise Exception

    if myid == 0:
        print "Broadcast communication of general structures OK"

    # Test scatter  - with/without buffers (arrays, strings)
    #
    N = 16  # Number of elements

    NP = N / numproc

    testString = 'ABCDEFGHIJKLMNOP'  # Length = 16
    X = ' ' * NP

    pypar.scatter(testString, 0, buffer=X)  # With buffer
    Y = pypar.scatter(testString, 0)  # With buffer automatically created

    assert X == Y, 'X=%s, Y=%s' % (X, Y)
    assert Y == testString[myid * NP:(myid + 1) * NP]
    assert X == testString[myid * NP:(myid + 1) * NP]

    if myid == 0:
        print "Scatter communication of strings OK"

    # Scatter Arrays
    testArray = numpy.array(range(N)).astype('i')
    X = numpy.zeros(NP).astype('i')

    pypar.scatter(testArray, 0, buffer=X)  # With buffer
    Y = pypar.scatter(testArray, 0)  # With buffer automatically created
Ejemplo n.º 14
0
  if myid == 0:
    print "Broadcast communication of general structures OK"
  



  # Test scatter  - with/without buffers (arrays, strings)
  #
  N = 16 # Number of elements

  NP = N/numproc
  
  testString = 'ABCDEFGHIJKLMNOP'  #Length = 16
  X = ' '*NP

  pypar.scatter(testString, 0, buffer=X) # With buffer
  Y = pypar.scatter(testString, 0) # With buffer automatically created

  assert X==Y, 'X=%s, Y=%s' %(X,Y)
  assert Y == testString[myid*NP:(myid+1)*NP]
  assert X == testString[myid*NP:(myid+1)*NP]

  if myid == 0:    
    print "Scatter communication of strings OK"
    

  #Scatter Arrays
  testArray = numpy.array(range(N)).astype('i')
  X = numpy.zeros(NP).astype('i')

  pypar.scatter(testArray, 0, buffer=X) # With buffer