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
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
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]
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]
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)
#Create the scenery. BOUND = np.zeros((nx,ny,nz), dtype=float, dist=DIST) BOUNDi = np.zeros((nx,ny,nz), dtype=float, dist=DIST) BOUNDi += 1#ones if not NO_OBST: for i in xrange(nx): for j in xrange(ny): for k in xrange(nz): if ((i-4)**2+(j-5)**2+(k-6)**2) < 6: BOUND[i,j,k] += 1.0 BOUNDi[i,j,k] += 0.0 BOUND[:,0,:] += 1.0 BOUNDi[:,0,:] *= 0.0 np.timer_reset() np.evalflush() t1 = time.time() while ts<ITER: ##Propagate / Streaming step T[:] = F #nearest-neighbours F[1,:,:,0] = T[1,:,:,-1] F[1,:,:,1:] = T[1,:,:,:-1] F[2,:,:,:-1] = T[2,:,:,1:] F[2,:,:,-1] = T[2,:,:,0] F[3,:,0,:] = T[3,:,-1,:] F[3,:,1:,:] = T[3,:,:-1,:] F[4,:,:-1,:] = T[4,:,1:,:] F[4,:,-1,:] = T[4,:,0,:] F[5,0,:,:] = T[5,-1,:,:]