コード例 #1
0
ファイル: jacobi.py プロジェクト: greenday0925/distnumpy
def jacobi(A, B, tol=0.005, forcedIter=0):
    '''itteratively solving for matrix A with solution vector B
       tol = tolerance for dh/h
       init_val = array of initial values to use in the solver
    '''
    h = np.zeros(np.shape(B), float, dist=A.dist())
    dmax = 1.0
    n = 0
    tmp0 = np.empty(np.shape(A), float, dist=A.dist())
    tmp1 = np.empty(np.shape(B), float, dist=A.dist())
    AD = np.diagonal(A)
    np.timer_reset()
    while (forcedIter and forcedIter > n) or \
          (forcedIter == 0 and dmax > tol):
        n += 1
        np.multiply(A,h,tmp0)
        np.add.reduce(tmp0,1,out=tmp1)
        tmp2 = AD
        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
コード例 #2
0
ファイル: jacobi.py プロジェクト: greenday0925/distnumpy
def jacobi(A, B, tol=0.005, forcedIter=0):
    '''itteratively solving for matrix A with solution vector B
       tol = tolerance for dh/h
       init_val = array of initial values to use in the solver
    '''
    h = np.zeros(np.shape(B), float, dist=A.dist())
    dmax = 1.0
    n = 0
    tmp0 = np.empty(np.shape(A), float, dist=A.dist())
    tmp1 = np.empty(np.shape(B), float, dist=A.dist())
    AD = np.diagonal(A)
    np.timer_reset()
    while (forcedIter and forcedIter > n) or \
          (forcedIter == 0 and dmax > tol):
        n += 1
        np.multiply(A, h, tmp0)
        np.add.reduce(tmp0, 1, out=tmp1)
        tmp2 = AD
        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
コード例 #3
0
ファイル: fft3d.py プロジェクト: greenday0925/distnumpy
import time
import numpy as np
import pyHPC
import util

np.datalayout([(3, 1, 1)])

parser = util.Parsing()
DIST = parser.dist
SIZE = int(parser.argv[0])
A = np.empty((SIZE, SIZE, SIZE), dtype=np.complex, dist=DIST)

if DIST:
    f = pyHPC.fft3d
else:
    f = np.fft.fftn

np.timer_reset()
f(A)
timing = np.timer_getdict()

if np.RANK == 0:
    print 'fft3d - size:,', np.shape(A)

parser.pprint(timing)
parser.write_dict(timing)
コード例 #4
0
ファイル: fft2d.py プロジェクト: seyatutome/distnumpy
import time
import numpy as np
import pyHPC
import util

np.datalayout([(2, 1, 1)])

parser = util.Parsing()
DIST = parser.dist
SIZE1 = int(parser.argv[0])
SIZE2 = int(parser.argv[1])
A = np.empty((SIZE1, SIZE2), dtype=np.complex, dist=DIST)

if DIST:
    f = pyHPC.fft2d
else:
    f = np.fft.fft2

np.timer_reset()
f(A)
timing = np.timer_getdict()

if np.RANK == 0:
    print "fft2d - size:,", np.shape(A)

parser.pprint(timing)
parser.write_dict(timing)