コード例 #1
0
def MC_int(c, s, dist):
    x = np.empty([s], dtype=np.double, dist=dist)
    y = np.empty([s], dtype=np.double, dist=dist)
    sum = 0.0
    np.timer_reset()
    np.evalflush()
    start = time.time()
    for i in range(c):
        np.ufunc_random(x, x)
        np.ufunc_random(y, y)
        np.square(x, x)
        np.square(y, y)
        np.add(x, y, x)
        z = np.less_equal(x, 1)
        sum += np.add.reduce(z) * 4.0 / s
    sum = sum / c
    np.evalflush()
    stop = time.time()
    print 'Pi: ', sum, ' with ', s, ' samples in sec: ', stop - start,
    if dist:
        print "(Dist) notes: %s" % sys.argv[4]
    else:
        print "(Non-Dist) notes: %s" % sys.argv[4]
コード例 #2
0
ファイル: MonteCarlo.py プロジェクト: greenday0925/distnumpy
def MC_int(c, s, dist):
    x = np.empty([s], dtype=np.double, dist=dist)
    y = np.empty([s], dtype=np.double, dist=dist)
    sum=0.0
    np.timer_reset()
    np.evalflush()
    start=time.time()
    for i in range(c):
        np.ufunc_random(x,x)
        np.ufunc_random(y,y)
        np.square(x,x)
        np.square(y,y)
        np.add(x,y,x)
        z = np.less_equal(x, 1)
        sum += np.add.reduce(z)*4.0/s
    sum = sum / c
    np.evalflush()
    stop=time.time()
    print 'Pi: ', sum, ' with ', s,' samples in sec: ', stop-start,
    if dist:
        print "(Dist) notes: %s"%sys.argv[4]
    else:
        print "(Non-Dist) notes: %s"%sys.argv[4]
コード例 #3
0
ファイル: hpcLU.py プロジェクト: greenday0925/distnumpy
def gen_matrix(SIZE, dist):
    A = np.zeros((SIZE, SIZE), dtype=float, dist=dist)
    np.ufunc_random(A, A)
    for i in xrange(SIZE):
        A[i, i] *= 2**30
    return A
コード例 #4
0
ファイル: alignment.py プロジェクト: greenday0925/distnumpy
        work += right
        work += down
        work *= 0.2


parser = util.Parsing()
DIST = parser.dist
nonaligned = bool(eval(parser.argv[0]))
N = int(parser.argv[1])
iters = int(parser.argv[2])
BS = 1

full = np.empty((N + BS * 2, N + BS * 2), dtype=np.double, dist=DIST)
align = np.empty((N, N), dtype=np.double, dist=DIST)
work = np.zeros((N, N), dtype=np.double, dist=DIST)
np.ufunc_random(full, full)
np.ufunc_random(align, align)

center = full[1 * BS:-1 * BS, 1 * BS:-1 * BS]
up = full[1 * BS:-1 * BS, :-2 * BS]
left = full[:-2 * BS, 1 * BS:-1 * BS]
right = full[2 * BS:, 1 * BS:-1 * BS]
down = full[1 * BS:-1 * BS, 2 * BS:]

np.timer_reset()
if nonaligned:
    stencil(iters, work, center, up, left, right, down)
else:
    stencil(iters, work, align, align, align, align, align)
timing = np.timer_getdict()
コード例 #5
0
ファイル: jacobi.py プロジェクト: greenday0925/distnumpy
        np.subtract(B, tmp1, tmp1)
        np.divide(tmp1, tmp2, tmp1)
        hnew = h + tmp1
        np.subtract(hnew,h,tmp2)
        np.divide(tmp2,h,tmp1)
        np.absolute(tmp1,tmp1)
        dmax = np.maximum.reduce(tmp1)
        h = hnew

    timing = np.timer_getdict()
    print timing
    print 'Iter: ', n, ' size:', np.shape(A)
    parser.pprint(timing)

    return h

size = int(parser.argv[0])
iter = int(parser.argv[1])

#A = array([[4, -1, -1, 0], [-1, 4, 0, -1], [-1, 0, 4, -1], [0, -1, -1, 4]], float, dist=d)
#B = array([1,2,0,1], float, dist=d)

A = np.zeros([size,size], dtype=float, dist=parser.dist)
np.ufunc_random(A,A)

B = np.zeros([size], dtype=float, dist=parser.dist)
np.ufunc_random(B,B)

C = jacobi(A, B, forcedIter=iter)

コード例 #6
0
ファイル: LU.py プロジェクト: greenday0925/distnumpy
        if jp != j:  #Do full pivot!!!
            temp[:] = A[jp, :]
            A[jp, :] = A[j, :]
            A[j, :] = temp[:]

        if j < M - 1:
            recp = 1.0 / A[j][j]
            A[j:, j] *= recp

        if (j < minMN - 1):
            t1 = A[j + 1:, j + 1:] - A[j + 1:, j] * A[j, j + 1:]
            A[j + 1:, j + 1:] = t1

    return A, pivot


A = np.ufunc_random(np.empty((N, N), dtype=float, dist=DIST))
np.timer_reset()
np.evalflush()
t1 = time.time()
LU_factor(A)
np.evalflush()
t1 = time.time() - t1

print 'Iter: ', I, ' size: ', N, ' time: ', t1,
if A.dist():
    print "(Dist) notes: %s" % sys.argv[4]
else:
    print "(Non-Dist) notes: %s" % sys.argv[4]
コード例 #7
0
ファイル: nbody.py プロジェクト: seyatutome/distnumpy
import numpy as np
import sys
import time

d = int(sys.argv[1])  # Distributed
n = int(sys.argv[2])  # Number of bodies
k = int(sys.argv[3])  # Number of iterations

G = 1  # Gravitational constant
dT = 0.01  # Time increment

M = np.empty((n, 1), dist=d)
np.ufunc_random(M, M)
MT = np.empty((1, n), dist=d)
np.ufunc_random(MT, MT)
Px = np.empty((n, 1), dist=d)
np.ufunc_random(Px, Px)
Py = np.empty((n, 1), dist=d)
np.ufunc_random(Py, Py)
Pz = np.empty((n, 1), dist=d)
np.ufunc_random(Pz, Pz)
PxT = np.empty((1, n), dist=d)
np.ufunc_random(PxT, PxT)
PyT = np.empty((1, n), dist=d)
np.ufunc_random(PyT, PyT)
PzT = np.empty((1, n), dist=d)
np.ufunc_random(PzT, PzT)
Vx = np.empty((n, 1), dist=d)
np.ufunc_random(Vx, Vx)
Vy = np.empty((n, 1), dist=d)
np.ufunc_random(Vy, Vy)
コード例 #8
0
ファイル: summa.py プロジェクト: greenday0925/distnumpy
import numpy as np
import util
import pyHPC

parser = util.Parsing()
DIST = parser.dist
M = int(parser.argv[0])
N = int(parser.argv[1])
K = int(parser.argv[2])
C = int(parser.argv[3])

A = np.empty([M, K], dtype=float, dist=DIST)
np.ufunc_random(A, A)

B = np.empty([K, M], dtype=float, dist=DIST)
np.ufunc_random(B, B)

if DIST:
    matmul = pyHPC.summa
else:
    matmul = np.dot

np.timer_reset()
for i in range(C):
    tmp = matmul(A, B)
timing = np.timer_getdict()

if np.RANK == 0:
    print "SUMMA M:%d, N:%d, K:%d, C:%d" % (M, N, K, C)
    parser.pprint(timing)
    parser.write_dict(timing)
コード例 #9
0
ファイル: kNN.py プロジェクト: greenday0925/distnumpy
    t = base - target
    #print t.shape, tmp1.shape
    np.subtract(base, target, tmp1)
    tmp1 **= 2
    np.add.reduce(tmp1, out=tmp2)
    np.sqrt(tmp2, tmp2)
    r = np.max(tmp2, axis=0)
    return r


DIST = int(sys.argv[1])
ndims = int(sys.argv[2])
db_length = int(sys.argv[3])
step = int(sys.argv[4])

targets = np.ufunc_random(np.empty((ndims, db_length), dtype=float, dist=DIST))
base = targets  #np.ufunc_random(np.empty((ndims,db_length), dtype=float, dist=DIST))

tmp1 = np.empty((ndims, step, step), dtype=float, dist=DIST)
tmp2 = np.empty((step, step), dtype=float, dist=DIST)

np.timer_reset()
np.evalflush()
t1 = time.time()
for i in xrange(0, db_length, step):
    for j in xrange(0, db_length, step):
        compute_targets(base[:, i:i + step], targets[:, j:j + step], tmp1,
                        tmp2)
np.evalflush()
t2 = time.time()
コード例 #10
0
ファイル: kNN.py プロジェクト: greenday0925/distnumpy
    target = target[:,:,np.newaxis]
    t = base - target
    #print t.shape, tmp1.shape
    np.subtract(base, target, tmp1)
    tmp1 **= 2
    np.add.reduce(tmp1, out=tmp2)
    np.sqrt(tmp2, tmp2)
    r  = np.max(tmp2, axis=0)
    return r

DIST = int(sys.argv[1])
ndims = int(sys.argv[2])
db_length = int(sys.argv[3])
step = int(sys.argv[4])

targets = np.ufunc_random(np.empty((ndims,db_length), dtype=float, dist=DIST))
base = targets #np.ufunc_random(np.empty((ndims,db_length), dtype=float, dist=DIST))

tmp1 = np.empty((ndims,step,step), dtype=float, dist=DIST)
tmp2 = np.empty((step,step), dtype=float, dist=DIST)

np.timer_reset()
np.evalflush()
t1 = time.time()
for i in xrange(0, db_length, step):
    for j in xrange(0, db_length, step):
        compute_targets(base[:,i:i+step], targets[:,j:j+step], tmp1, tmp2)
np.evalflush()
t2 = time.time()

print "ndims: %d, dbsize: %d, step: %d - time: %f sec."\
コード例 #11
0
ファイル: nbody.py プロジェクト: greenday0925/distnumpy
import numpy as np
import sys
import time

d = int(sys.argv[1])  #Distributed
n = int(sys.argv[2])  #Number of bodies
k = int(sys.argv[3])  #Number of iterations

G = 1  #Gravitational constant
dT = 0.01  #Time increment

M = np.empty((n, 1), dist=d)
np.ufunc_random(M, M)
MT = np.empty((1, n), dist=d)
np.ufunc_random(MT, MT)
Px = np.empty((n, 1), dist=d)
np.ufunc_random(Px, Px)
Py = np.empty((n, 1), dist=d)
np.ufunc_random(Py, Py)
Pz = np.empty((n, 1), dist=d)
np.ufunc_random(Pz, Pz)
PxT = np.empty((1, n), dist=d)
np.ufunc_random(PxT, PxT)
PyT = np.empty((1, n), dist=d)
np.ufunc_random(PyT, PyT)
PzT = np.empty((1, n), dist=d)
np.ufunc_random(PzT, PzT)
Vx = np.empty((n, 1), dist=d)
np.ufunc_random(Vx, Vx)
Vy = np.empty((n, 1), dist=d)
np.ufunc_random(Vy, Vy)
コード例 #12
0
ファイル: BlackSholes.py プロジェクト: greenday0925/distnumpy
# Black Sholes Function
def BlackScholes(CallPutFlag,S,X,T,r,v):
    d1 = (np.log(S/X)+(r+v*v/2.)*T)/(v*np.sqrt(T))
    d2 = d1-v*np.sqrt(T)
    if CallPutFlag=='c':
        return S*CND(d1)-X*np.exp(-r*T)*CND(d2)
    else:
        return X*np.exp(-r*T)*CND(-d2)-S*CND(-d1)

DIST=int(sys.argv[1])

N=int(sys.argv[2])

S = np.empty((N), dtype=float, dist=DIST)
np.ufunc_random(S,S)
S = S*4.0-2.0 + 60.0 #Price is 58-62

X=65.0
#T=0.25 Moved to loop
r=0.08
v=0.3

year=int(sys.argv[3])
day=1.0/year
T=day

np.timer_reset()
np.evalflush()
stime = time.time()
for t in xrange(year):
コード例 #13
0
ファイル: alignment.py プロジェクト: greenday0925/distnumpy
        work += left
        work += right
        work += down
        work *= 0.2

parser = util.Parsing()
DIST=parser.dist
nonaligned = bool(eval(parser.argv[0]))
N = int(parser.argv[1])
iters=int(parser.argv[2])
BS=1

full = np.empty((N+BS*2,N+BS*2), dtype=np.double, dist=DIST)
align = np.empty((N,N), dtype=np.double, dist=DIST)
work   = np.zeros((N,N), dtype=np.double, dist=DIST)
np.ufunc_random(full,full)
np.ufunc_random(align,align)

center = full[1*BS:-1*BS, 1*BS:-1*BS]
up     = full[1*BS:-1*BS,     :-2*BS]
left   = full[:-2*BS    , 1*BS:-1*BS]
right  = full[2*BS:     , 1*BS:-1*BS]
down   = full[1*BS:-1*BS, 2*BS:     ]

np.timer_reset()
if nonaligned:
    stencil(iters, work, center, up, left, right, down)
else:
    stencil(iters, work, align, align, align, align, align)
timing = np.timer_getdict()
コード例 #14
0
ファイル: LU.py プロジェクト: greenday0925/distnumpy
        if jp != j: #Do full pivot!!!
            temp[:]=A[jp,:]
            A[jp,:]=A[j,:]
            A[j,:]=temp[:]

        if j < M-1:
            recp =  1.0 / A[j][j]
            A[j:,j] *= recp

        if (j < minMN-1):
            t1 = A[j+1:,j+1:] - A[j+1:,j] * A[j,j+1:]
            A[j+1:,j+1:] = t1

    return A, pivot

A = np.ufunc_random(np.empty((N,N), dtype=float, dist=DIST))
np.timer_reset()
np.evalflush()
t1 = time.time()
LU_factor(A)
np.evalflush()
t1 = time.time() - t1

print 'Iter: ', I, ' size: ', N,' time: ', t1,
if A.dist():
    print "(Dist) notes: %s"%sys.argv[4]
else:
    print "(Non-Dist) notes: %s"%sys.argv[4]

コード例 #15
0
ファイル: hpcLU.py プロジェクト: greenday0925/distnumpy
def gen_matrix(SIZE,dist):
    A = np.zeros((SIZE,SIZE), dtype=float, dist=dist);
    np.ufunc_random(A,A)
    for i in xrange(SIZE):
        A[i,i] *= 2**30
    return A