コード例 #1
0
ファイル: test.py プロジェクト: fred1653/lotsofcoresbook1code
def check_copy(gatype):
    if 0 == me:
        print '> Checking copy ...',
    g_a = create_global_array(gatype)
    g_b = create_global_array(gatype)
    a = create_local_a(gatype)
    if 0 == me:
        ga.put(g_a, a)
    ga.copy(g_a, g_b)
    if not np.all(a == ga.get(g_b)):
        ga.error('copy failed')
    if 0 == me:
        print 'OK'
    ga.destroy(g_a)
    ga.destroy(g_b)
コード例 #2
0
ファイル: copy.py プロジェクト: GlobalArrays/ga4py
import mpi4py.MPI  # initialize Message Passing Interface
from ga4py import ga  # initialize Global Arrays

me = ga.nodeid()


def print_distribution(g_a):
    for i in range(ga.nnodes()):
        lo, hi = ga.distribution(g_a, i)
        print "%s lo=%s hi=%s" % (i, lo, hi)


# create some arrays
g_a = ga.create(ga.C_DBL, (10, 20, 30), chunk=(-1, 20, -1))
g_b = ga.create(ga.C_DBL, (10, 20, 30), chunk=(10, -1, -1))

if not me:
    print_distribution(g_a)
    print_distribution(g_b)

ga.fill(g_a, 6)
ga.copy(g_a, g_b)

if not me:
    buffer = ga.access(g_b)
    print buffer.shape
    print buffer
コード例 #3
0
    a[:,a.shape[0] - 1] = 50 #right column
    ga.put(g_a, a)
ga.sync()

# which piece of array do I own?
# note that rhi and chi follow python range conventions i.e. [lo,hi)
(rlo,clo),(rhi,chi) = ga.distribution(g_a)

iteration = 0
start = ga.wtime()
while True:
    iteration += 1
    if iteration % HOW_MANY_STEPS_BEFORE_CONVERGENCE_TEST == 0:
        # check for convergence will occur, so make a copy of the GA
        ga.sync()
        ga.copy(g_a, g_b)
    # the iteration
    if rlo == 0 and rhi == dim:
        # I own the top and bottom rows
        ga.sync()
        my_array = ga.access(g_a)
        my_array[1:-1,1:-1] = (
                my_array[0:-2, 1:-1] +
                my_array[2:, 1:-1] +
                my_array[1:-1,0:-2] +
                my_array[1:-1, 2:]) / 4
        ga.release(g_a)
    elif rlo == 0:
        # I own the top rows, so get top row of next domain
        next_domain_row = ga.get(g_a, (rhi,0), (rhi+1,dim))
        ga.sync()