Example #1
0
def check_scatter(gatype):
    nptype = ga.dtype(gatype)
    if 0 == me:
        print '> Checking scatter (might be slow)...',
    g_a = create_global_array(gatype)
    a = create_local_a(gatype)
    if 0 == me:
        ga.put(g_a, a)
    ga.sync()
    ijv = np.zeros((m,2), dtype=np.int64)
    v = np.zeros(m, dtype=nptype)
    random.seed(ga.nodeid()*51 + 1) # different seed for each proc
    for j in range(10):
        check = None
        if MIRROR:
            check = random.randint(0,lprocs-1) == iproc
        else:
            check = random.randint(0,nproc-1) == me
        if check:
            for loop in range(m):
                ijv[loop,:] = (random.randint(0,n-1),random.randint(0,n-1))
                v[loop] = ijv[loop,0]+ijv[loop,1]
            ga.scatter(g_a, v, ijv)
            for loop in range(m):
                value = ga.get(g_a, ijv[loop], ijv[loop]+1).flatten()
                if not v[loop] == value:
                    ga.error('scatter failed')
    if 0 == me:
        print 'OK'
    ga.destroy(g_a)
Example #2
0
def create_local_a(gatype):
    nptype = ga.dtype(gatype)
    if gatype == ga.C_SCPL:
        if MIRROR:
            a = np.fromfunction(lambda i,j: i+inode, (n,n), dtype=np.float32)
            b = np.fromfunction(lambda i,j: j*n,     (n,n), dtype=np.float32)
            return np.vectorize(complex)(a,b)
        else:
            a = np.fromfunction(lambda i,j: i,   (n,n), dtype=np.float32)
            b = np.fromfunction(lambda i,j: j*n, (n,n), dtype=np.float32)
            return np.vectorize(complex)(a,b)
    elif gatype == ga.C_DCPL:
        if MIRROR:
            a = np.fromfunction(lambda i,j: i+inode, (n,n), dtype=np.float64)
            b = np.fromfunction(lambda i,j: j*n,     (n,n), dtype=np.float64)
            return np.vectorize(complex)(a,b)
        else:
            a = np.fromfunction(lambda i,j: i,   (n,n), dtype=np.float64)
            b = np.fromfunction(lambda i,j: j*n, (n,n), dtype=np.float64)
            return np.vectorize(complex)(a,b)
    elif gatype in [ga.C_DBL,ga.C_FLOAT]:
        if MIRROR:
            return np.fromfunction(lambda i,j: inode+i+j*n, (n,n), dtype=nptype)
        else:
            return np.fromfunction(lambda i,j: i+j*n,       (n,n), dtype=nptype)
    elif gatype in [ga.C_INT,ga.C_LONG]:
        if MIRROR:
            return np.fromfunction(lambda i,j: inode+i+j*1000, (n,n), dtype=nptype)
        else:
            return np.fromfunction(lambda i,j: i+j*1000, (n,n), dtype=nptype)
Example #3
0
def create_local_b(gatype):
    nptype = ga.dtype(gatype)
    b = np.zeros((n,n), dtype=nptype)
    if gatype in [ga.C_SCPL, ga.C_DCPL]:
        b[:] = complex(-1,1)
    else:
        b[:] = -1
    return b
Example #4
0
def check_accumulate_disjoint(gatype):
    """Each node accumulates into disjoint sections of the array."""
    if 0 == me:
        print '> Checking disjoint accumulate ...',
    g_a = create_global_array(gatype)
    a = create_local_a(gatype)
    b = np.fromfunction(lambda i,j: i+j+2, (n,n), dtype=ga.dtype(gatype))
    if 0 == me:
        ga.put(g_a, a)
    ga.sync()
    inc = (n-1)/20 + 1
    ij = 0
    for i in range(0,n,inc):
        for j in range(0,n,inc):
            x = 10.0
            lo = [i,j]
            hi = [min(i+inc,n), min(j+inc,n)]
            piece = b[ga.zip(lo,hi)]
            check = False
            if MIRROR:
                check = ij % lprocs == iproc
            else:
                check = ij % nproc == me
            if check:
                ga.acc(g_a, piece, lo, hi, x)
            ga.sync()
            ij += 1
            # each process applies all updates to its local copy
            a[ga.zip(lo,hi)] += x * piece
    ga.sync()
    # all nodes check all of a
    if not np.all(ga.get(g_a) == a):
        ga.error('acc failed')
    if 0 == me:
        print 'OK'
    ga.destroy(g_a)
Example #5
0
chunk = (-1,-1)
ld = NSIZE

g_a = ga.create(ga.C_INT, dims, "test_a", chunk)
if me == 0 and g_a:
    print "\nSuccessfully created Global Array"

# Initialize data in GA. Find data owned by neighboring processor

nghbr = (me+1)%nprocs
lo,hi = ga.distribution(g_a, nghbr)

# Create data in local buffer, assign unique value for each data element
patch_shape = hi-lo
a_buf = np.fromfunction(lambda i,j: j*NSIZE + i,
        patch_shape, dtype=ga.dtype(ga.C_INT))
a_buf += lo[1,np.newaxis]
a_buf += lo[np.newaxis,0]*dims[0]

# Copy local data to GA
ga.put(g_a, a_buf, lo, hi)
ga.sync()
if me == 0:
    print "\nCopied values into Global Array from local buffer\n"

# Check data in GA to see if it is correct. Find data owned by this
# processor and then copy it to local buffer
lo,hi = ga.distribution(g_a, me)
b_buf = ga.get(g_a, lo, hi)
if me == 0:
    print "\nCopied values from Global Array to local buffer\n"