def check_dot(gatype): if 0 == me: print '> Checking dot ...', np.random.seed(12345) # everyone has same seed g_a = create_global_array(gatype) g_b = create_global_array(gatype) a = create_local_a(gatype) b = np.random.random_sample((n,n)) if MIRROR: if 0 == iproc: ga.put(g_b, b) ga.put(g_a, a) else: if 0 == me: ga.put(g_b, b) ga.put(g_a, a) ga.sync() sum1 = np.sum(a*b) sum2 = ga.dot(g_a, g_b) if mismatch(sum1, sum2): ga.error('dot wrong %s != %s' % (sum1, sum2)) if 0 == me: print 'OK' ga.destroy(g_a) ga.destroy(g_b)
def convergence_test_L2(g_a, g_b): # compute L2 norm of change # subtract g_b from g_a, results stored in g_b ga.add(g_a, g_b, g_b, beta=-1) # compute elementwise dot product (i.e. treats N-d arrays as vectors) value = ga.dot(g_b, g_b) if DEBUG: print_sync(value) return value < EPSILON
def verify(g_a, g_b, g_c): g_chk = ga.duplicate(g_a, "array check") if not g_chk: ga.error("duplicate failed") ga.sync() ga.gemm(False, False, TOTALELEMS, TOTALELEMS, TOTALELEMS, 1.0, g_a, g_b, 0.0, g_chk); ga.sync() ga.add(g_c, g_chk, g_chk, 1.0, -1.0) rchk = ga.dot(g_chk, g_chk) if not me: print "Normed difference in matrices: %12.4f" % rchk if not (-TOLERANCE < rchk < TOLERANCE): ga.error("Matrix multiply verify failed") else: print "Matrix Multiply OK" ga.destroy(g_chk)