7
def jacobi(A, B, tol=0.005, forcedIter=0):
8
'''itteratively solving for matrix A with solution vector B
9
tol = tolerance for dh/h
10
init_val = array of initial values to use in the solver
12
h = np.zeros(np.shape(B), float)
15
tmp0 = np.empty(np.shape(A), float)
16
tmp1 = np.empty(np.shape(B), float)
21
while (forcedIter and forcedIter > n) or \
22
(forcedIter == 0 and dmax > tol):
25
np.add.reduce(tmp0,1,out=tmp1)
27
np.subtract(B, tmp1, tmp1)
28
np.divide(tmp1, tmp2, tmp1)
30
np.subtract(hnew,h,tmp2)
31
np.divide(tmp2,h,tmp1)
32
np.absolute(tmp1,tmp1)
33
dmax = np.maximum.reduce(tmp1)
41
print 'Iter: ', n, ' size: ', np.shape(B),' time: ', t1,
42
print "(Dist) notes: %s"%sys.argv[4]
44
# print "(Dist) notes: %s"%sys.argv[4]
46
# print "(Non-Dist) notes: %s"%sys.argv[4]
53
size = int(sys.argv[2])
54
iter = int(sys.argv[3])
56
#A = array([[4, -1, -1, 0], [-1, 4, 0, -1], [-1, 0, 4, -1], [0, -1, -1, 4]], float, dist=d)
57
#B = array([1,2,0,1], float, dist=d)
59
#A = np.zeros([size,size], dtype=float)
61
A = np.random.random_sample([size,size])
63
#B = np.zeros([size], dtype=float)
65
B = np.random.random_sample([size])
67
C = jacobi(A, B, 0.10, forcedIter=iter)
69
if __name__ == '__main__':
71
#cProfile.run("main()", "profile.%s.prof" % str(me()))