コード例 #1
0
    def __init__(self, args):
        if sys.version_info < (3, 0, 0):  # not supported in Python 2.7
            exit()
        assert charm.numPes() >= 4
        self.done = -1
        workers = Group(Worker)
        controllers = Array(Controller, charm.numPes())
        receivers = Array(CallbackReceiver,
                          charm.numPes(),
                          args=[self.thisProxy])
        workers.work(receivers[1].getResult)
        self.wait('self.done == 1')
        self.done = -1

        controllers[1].start(workers, receivers[2].getResult)
        self.wait('self.done == 2')
        self.done = -1

        controllers[2].start(workers, receivers.getResultBroadcast)
        self.wait('self.done == ' + str(charm.numPes()))
        self.done = -1

        f = Future()
        controllers[3].start(workers, f)
        assert f.get() == (charm.numPes() * (charm.numPes() - 1)) // 2

        exit()
コード例 #2
0
    def __init__(self, args):
        assert charm.numPes() >= 4
        g1 = Group(Test)
        g2 = Group(Test)
        a = Array(Test, charm.numPes() * 8)

        assert self.thisProxy == self.thisProxy
        assert self.thisProxy != g1
        assert self.thisProxy != a

        assert g1 == g1
        assert g1 == g1[2].getProxy(ret=True).get()
        assert g1[2] == g1[2].getProxy(elem=True, ret=True).get()
        assert g1[2].getProxy(ret=True).get() == g1[3].getProxy(ret=True).get()
        assert g1[2].getProxy(True, ret=True).get() != g1[3].getProxy(
            True, ret=True).get()

        assert g1 != g2
        assert g1[2].getProxy(ret=True).get() != g2[2].getProxy(ret=True).get()
        assert g1[2].getProxy(True, ret=True).get() != g2[2].getProxy(
            True, ret=True).get()

        assert g1 != a
        assert a == a
        assert a == a[12].getProxy(ret=True).get()
        assert a[12] == a[12].getProxy(elem=True, ret=True).get()
        assert a[8] != a[12].getProxy(elem=True, ret=True).get()

        exit()
コード例 #3
0
ファイル: test2.py プロジェクト: sdrave/charm4py
def main(args):
    g1 = Group(Test)
    g2 = Group(Test)
    g3 = Group(Test)
    g4 = Group(Test)

    P = charm.numPes()
    a1 = Array(Test, P * 8)
    a2 = Array(Test, P * 10)
    a3 = Array(Test, P * 4)
    a4 = Array(Test, P * 1)

    charm.awaitCreation(g1, g2, g3, g4, a1, a2, a3, a4)

    chares = []  # proxies to all individual chares created
    for collection in (g1, g2, g3, g4):
        for idx in range(P):
            chares.append(collection[idx])

    for collection, numelems in ((a1, P * 8), (a2, P * 10), (a3, P * 4), (a4,
                                                                          P)):
        for idx in range(numelems):
            chares.append(collection[idx])

    print('There are', len(chares), 'chares')

    # establish random channels between chares
    global gchannels
    gchannels = {}
    num_self_channels = 0
    for level in range(NUM_LEVELS):
        gchannels[level] = defaultdict(list)
        for _ in range(NUM_CHANNELS):
            a = random.choice(chares)
            b = random.choice(chares)
            if a == b:
                num_self_channels += 1
            gchannels[level][a].append(b)
            gchannels[level][b].append(a)
    charm.thisProxy.updateGlobals({
        'gchannels': gchannels
    }, awaitable=True).get()

    done_fut = Future(8 *
                      NUM_LEVELS)  # wait for 8 collections to finish 3 levels
    for collection in (g1, g2, g3, g4, a1, a2, a3, a4):
        collection.setup(awaitable=True).get()
    print(NUM_CHANNELS * NUM_LEVELS, 'channels set up,', num_self_channels,
          'self channels')
    for collection in (g1, g2, g3, g4, a1, a2, a3, a4):
        for lvl in range(NUM_LEVELS):
            collection.work(lvl, done_fut)

    msgs = sum(done_fut.get())
    assert msgs == sum(LEVELS_NUM_ITER[:NUM_LEVELS]) * NUM_CHANNELS * 2
    print('total msgs received by chares=', msgs)
    exit()
コード例 #4
0
ファイル: proxies_same_name.py プロジェクト: sdrave/charm4py
def main(args):
    assert charm.numPes() >= 4
    g1 = Group(Hello)
    g2 = Group(proxies_same_name_aux.Hello)
    tester1 = Chare(Test, onPE=2)
    tester2 = Chare(proxies_same_name_aux.Test, onPE=1)
    charm.awaitCreation(g2, g1, tester2, tester1)
    tester1.test(g2, 'check2', awaitable=True).get()
    tester2.test(g1, 'check1', awaitable=True).get()
    exit()
コード例 #5
0
ファイル: test2.py プロジェクト: sdrave/charm4py
def main(args):
    numChares = charm.numPes() * 10
    a = Array(Test, numChares)
    g = Group(Test)
    charm.awaitCreation(a, g)
    f1 = Future()
    f2 = Future()
    a.start(f1)
    g.start(f2)
    f1.get()
    f2.get()
    exit()
コード例 #6
0
 def __init__(self, args):
     # create Group of chares of type hello.Hello
     hello_chares = Group(hello.Hello)
     # create Group of chares of type goodbye.Goodbye
     bye_chares = Group(goodbye.Goodbye)
     # add bye_chares proxy to globals of module hello on every process
     future1 = charm.thisProxy.updateGlobals({'bye_chares': bye_chares},
                                             module_name='hello', awaitable=True)
     # add mainchare proxy to globals of module goodbye on every process
     future2 = charm.thisProxy.updateGlobals({'mainProxy': self.thisProxy},
                                             module_name='goodbye', awaitable=True)
     charm.wait((future1, future2))
     # broadcast a message to the hello chares
     hello_chares.SayHi()
コード例 #7
0
def main(args):
    global numChares, testGroup
    numChares = min(charm.numPes() * 8, 32)
    testGroup = Group(Test2)
    charm.thisProxy.updateGlobals({'numChares': numChares, 'testGroup': testGroup},
                                  '__main__', awaitable=True).get()
    Array(Test, numChares)
コード例 #8
0
ファイル: nqueen.py プロジェクト: sdrave/charm4py
def main(args):
    global NUM_ROWS, GRAINSIZE
    NUM_ROWS = 5  # size of board is NUM_ROWS x NUM_ROWS
    if len(args) > 1:
        NUM_ROWS = int(args[1])
    if len(args) > 2:
        GRAINSIZE = min(int(args[2]), NUM_ROWS)
    else:
        GRAINSIZE = max(1, NUM_ROWS - 2)

    print('\nUsage: nqueen [numqueens] [grainsize]')
    print('Number of queens is', NUM_ROWS, ', grainsize is', GRAINSIZE)

    # set NUM_ROWS and GRAINSIZE as global variables on every PE
    global_data = {}
    global_data['NUM_ROWS'] = NUM_ROWS
    global_data['GRAINSIZE'] = GRAINSIZE
    global_data['solution_count'] = 0  # to count number of solutions found on each PE
    charm.thisProxy.updateGlobals(global_data, awaitable=True).get()

    startTime = time()
    # initialize empty solution, solution holds the column number where a queen is placed, for each row
    solution = array.array('b', [-1] * NUM_ROWS)
    queen(0, solution)
    # wait until there is no work being done on any PE (quiescence detection)
    charm.waitQD()
    elapsed = time() - startTime
    numSolutions = sum(Group(Util).getSolutionCount(ret=True).get())
    print('There are', numSolutions, 'solutions to', NUM_ROWS, 'queens. Time taken:', round(elapsed, 3), 'secs')
    exit()
コード例 #9
0
def main(args):
    g1 = Group(Test)
    g2 = Group(Test)
    done = charm.Future()

    main_globals = {}
    main_globals['group1_proxy'] = g1
    main_globals['group2_proxy'] = g2
    main_globals['done_future'] = done
    charm.thisProxy.updateGlobals(main_globals,
                                  module_name='__main__',
                                  awaitable=True).get()

    group1_proxy.start()
    done.get()
    exit()
コード例 #10
0
def main(args):
    f1 = Future()
    f2 = Future()
    Group(Test, args=[f1, f2])
    assert f1.get() == charm.numPes()
    assert f2.get() == charm.numPes()
    exit()
コード例 #11
0
ファイル: scheduler.py プロジェクト: sdrave/charm4py
 def __init__(self):
     # create a Worker on every process, pass them a reference (proxy) to myself
     self.workers = Group(Worker, args=[self.thisProxy])
     # scheduler will send tasks to processes from 1 to N-1 (keep 0 free)
     self.free_workers = set(range(1, charm.numPes()))
     self.next_job_id = 0
     self.jobs = {}
コード例 #12
0
def main(args):

    my = Mytest()
    tree = my.tree
    driver = my.cal()

    ti = time()
    my_array = Array(MyChare,args=[driver.src_weights.sum()], dims=4,map=Group(WorkerMap))

    my_array[1].summation_setter(driver)
    my_array[1].flag_setter("3")
    my_array[1].work()

    driver.step21()
    driver.step22()



    from CustomGreen import CustomConstantOneExpansionWrangler
    c = CustomConstantOneExpansionWrangler(tree)
    my_array[0].time_setter(ti)
    my_array[0].summation_setter(driver)

    my_array[2].summation_setter(driver)
    my_array[2].flag_setter("467")
    my_array[3].summation_setter(driver)
    my_array[3].flag_setter("5")

    my_array[0].work()
    my_array[2].work()
    my_array[3].work()
コード例 #13
0
ファイル: test_main.py プロジェクト: sdrave/charm4py
def main(args):
    grpProxy = Group(Test)
    for i in range(charm.numPes()):
        data = grpProxy[i].getData(ret=True).get()
        assert data == i**2, "Blocking call in main failed."
        print("Test " + str(i) + " sent data: " + str(data))
    exit()
コード例 #14
0
ファイル: test.py プロジェクト: sdrave/charm4py
def main(args):
    assert charm.numPes() % 2 == 0

    NUM_ITER = 5
    npes = charm.numPes()
    g = Group(Test)
    a = Array(Test, npes * 8)

    for proxy, num_chares in ((g, npes), (a, npes * 8)):
        for i in range(2):
            if i == 0:
                methods = {'allbad': 'allbad', 'good': 'good', 'bad': 'bad'}
            else:
                methods = {
                    'allbad': 'allbad_th',
                    'good': 'good_th',
                    'bad': 'bad_th'
                }

            # p2p
            if proxy == g:
                bad_idx = 1
            else:
                bad_idx = (num_chares // 2) + 1
            for _ in range(NUM_ITER):
                try:
                    getattr(proxy[bad_idx], methods['bad'])(ret=True).get()
                    assert False
                except NameError:
                    retval = getattr(proxy[bad_idx],
                                     methods['good'])(ret=True).get()
                    assert retval == bad_idx

            # bcast awaitable=True
            for _ in range(NUM_ITER):
                try:
                    getattr(proxy, methods['allbad'])(awaitable=True).get()
                    assert False
                except NameError:
                    try:
                        getattr(proxy, methods['bad'])(awaitable=True).get()
                        assert False
                    except NameError:
                        retval = getattr(
                            proxy, methods['good'])(awaitable=True).get()
                        assert retval is None

            # bcast ret=True (returns list of results)
            for _ in range(NUM_ITER):
                retvals = getattr(proxy, methods['bad'])(ret=True).get()
                num_errors = 0
                for retval in retvals:
                    if isinstance(retval, NameError):
                        num_errors += 1
                    else:
                        assert retval == 'good'
                assert num_errors == (num_chares // 2)
    exit()
コード例 #15
0
def main(args):
    my = Mytest()
    tree = my.tree
    driver = my.cal()
    ti = time()
    direct_result_future = charm.createFuture()
    local_result_future = charm.createFuture()
    local_exp_workers = Array(MyChare, 2, map=Group(WorkerMap))
    local_exp_workers[0].summation_setter(driver)
    local_exp_workers[0].flag_setter('3')
    local_exp_workers[0].direct_result(direct_result_future)

    driver.step21()
    driver.step22()

    local_exp_workers[1].summation_setter(driver)
    local_exp_workers[1].flag_setter('5')
    local_exp_workers[1].direct_result(direct_result_future)

    direct_evl_workers = Array(MyChare, 2, map=Group(DirectWorkerMap))
    direct_evl_workers[0].summation_setter(driver)
    direct_evl_workers[0].flag_setter('4')
    direct_evl_workers[0].sum_local_exp(local_result_future)
    direct_evl_workers[1].summation_setter(driver)
    direct_evl_workers[1].flag_setter('6')
    direct_evl_workers[1].sum_local_exp(local_result_future)

    local_exps = local_result_future.get()
    last_step_start = time()
    driver.wrangler.refine_locals(
        driver.traversal.level_start_target_or_target_parent_box_nrs,
        driver.traversal.target_or_target_parent_boxes, local_exps)
    local_result = driver.wrangler.eval_locals(
        driver.traversal.level_start_target_box_nrs,
        driver.traversal.target_boxes, local_exps)

    direct_result = direct_result_future.get()

    result = driver.wrangler.reorder_potentials(direct_result + local_result)
    result = driver.wrangler.finalize_potentials(result)

    end = time()
    print(end - ti)
    assert (result == driver.src_weights.sum()).all()
    exit()
コード例 #16
0
ファイル: inorder.py プロジェクト: sdrave/charm4py
 def __init__(self, args):
     assert charm.numPes() >= 2
     g = Group(Test)
     done_fut = Future()
     g[1].work(self.thisProxy, done_fut)
     ch = Channel(self, remote=g[1])
     for i in range(NUM_STEPS):
         ch.send(i)
     done_fut.get()
     exit()
コード例 #17
0
def main(args):
    f1 = Future()
    f2 = Future()
    Group(Test, args=[f1])
    Array(Test, charm.numPes() * 4, args=[f2])
    np.testing.assert_allclose(f1.get(),
                               np.arange(10, dtype='float64') * charm.numPes())
    np.testing.assert_allclose(
        f2.get(),
        np.arange(10, dtype='float64') * charm.numPes() * 4)
    exit()
コード例 #18
0
def main(args):
    # create a single controller on PE 0
    controller = Chare(Controller, onPE=0)
    # We only need one monitor per host. For this example, we could just launch
    # the program with one process per host and create a Group of monitors.
    # But more complex applications might need multiple processes per host
    # and still need to restrict certain groups of chares to certain PEs. Here
    # we illustrate how to do that:
    rank0pes = [charm.getHostFirstPe(host) for host in range(charm.numHosts())]
    # create monitors only on the first process of each host
    monitors = Group(Monitor, onPEs=rank0pes)
    controller.start(monitors)
コード例 #19
0
def main(args):
    t0 = time.time()
    durations2 = []
    num_cpus = charm.numPes()
    # same seed for fair comparison
    np.random.seed(seed=1234)
    streaming_actors = Group(StreamingPrefixCount)
    for _ in range(num_trials):
        streaming_actors.reset(awaitable=True).get()
        start_time = time.time()

        for i in range(num_cpus * 10):
            document = [np.random.bytes(20) for _ in range(10000)]
            #document = [np.random.bytes(5) for _ in range(1000)]   # smaller task size
            streaming_actors[i % num_cpus].add_document(document)

        # wait for quiescence
        charm.waitQD()
        # get the aggregated results
        results = Future()
        streaming_actors.get_popular(results)
        popular_prefixes = results.get()

        duration2 = time.time() - start_time
        durations2.append(duration2)
        print(
            'Stateful computation workload took {} seconds.'.format(duration2))
    print('Total time=', time.time() - t0)
    exit()
コード例 #20
0
    def __init__(self, args):
        self.expectedReductions = 7
        self.recvdReductions = 0

        nDims = 1
        ARRAY_SIZE = [10] * nDims  # 1-D array with 10 elements
        nElements = 1
        for x in ARRAY_SIZE:
            nElements *= x
        print('Running reduction example on ' + str(charm.numPes()) +
              ' processors')
        groupProxy = Group(TestGroup)
        # create an array to test group-to-array reductions
        arrayProxy = Array(TestArray, ARRAY_SIZE)
        charm.thisProxy.updateGlobals(
            {
                'mainProxy': self.thisProxy,
                'arrayProxy': arrayProxy
            },
            '__main__',
            awaitable=True).get()
        groupProxy.doReduction()
コード例 #21
0
def main(args):
    global numChares, testGroup
    # every chare sends to every other so don't want a ton of chares
    numChares = min(charm.numPes() * 8, 32)
    testGroup = Group(Test2)
    charm.thisProxy.updateGlobals(
        {
            'numChares': numChares,
            'testGroup': testGroup
        },
        '__main__',
        awaitable=True).get()
    Array(Test, numChares)
コード例 #22
0
ファイル: future_bcast.py プロジェクト: sdrave/charm4py
def main(args):
    a = Array(Test, charm.numPes())
    sleepTimes = [random.uniform(0.5, 1.5) for i in range(charm.numPes())]
    # for some reason, work() runs on PE 0 before sending the broadcast msgs out
    # to the other PEs, so I set wait time to 0 on PE 0
    sleepTimes[0] = 0.0
    t0 = time.time()
    a.work(sleepTimes, awaitable=True).get()  # wait for broadcast to complete
    wait_time = time.time() - t0
    assert (wait_time >= max(sleepTimes))
    print(wait_time, max(sleepTimes))

    g = Group(Test)
    sleepTimes = [random.uniform(0.5, 1.5) for i in range(charm.numPes())]
    sleepTimes[0] = 0.0
    t0 = time.time()
    g.work(sleepTimes, awaitable=True).get()  # wait for broadcast to complete
    wait_time = time.time() - t0
    assert (wait_time >= max(sleepTimes))
    print(wait_time, max(sleepTimes))

    exit()
コード例 #23
0
ファイル: test1.py プロジェクト: sdrave/charm4py
def main(args):
    array_map = Group(MyMap)
    for nDims in range(1, 7):
        if nDims <= 3:
            dim_size = 4
        else:
            dim_size = 2
        if nDims < 6:
            Array(MyChare, [dim_size] * nDims, args=[False], map=array_map)
        else:
            dyn_array = Array(MyChare, ndims=nDims, map=array_map)
            for idx in itertools.product(range(dim_size), repeat=nDims):
                dyn_array.ckInsert(idx, args=[True])
            dyn_array.ckDoneInserting()
コード例 #24
0
def main(args):

    my = Mytest()
    tree = my.tree
    driver = my.cal()

    very_start = time()

    f = charm.createFuture()
    f_other = charm.createFuture()
    ro.driver = driver
    step3_array = Array(step3_chare, args=[6, f], dims=6, map=Group(WorkerMap))
    my_array = Array(MyChare, args=[f_other, tree.nsources], dims=2)

    for i in range(0, 6):
        step3_array[i].index_setter(i)
    step3_array.calculate()
    driver.step21()
    driver.step22()

    my_array[0].summation_setter(driver)
    my_array[0].flag_setter("4")

    my_array[1].summation_setter(driver)
    my_array[1].flag_setter("6")

    my_array.work()

    local_result = driver.step5()
    if driver.traversal.from_sep_close_bigger_starts is not None:
        step_6_extra = driver.step6_extra()
        local_result += step_6_extra
    local_result += f.get()

    local_exps = f_other.get()

    local_exps = driver.wrangler.refine_locals(
        driver.traversal.level_start_target_or_target_parent_box_nrs,
        driver.traversal.target_or_target_parent_boxes, local_exps)
    local_result_from_exp = driver.wrangler.eval_locals(
        driver.traversal.level_start_target_box_nrs,
        driver.traversal.target_boxes, local_exps)

    end = time()
    result = driver.wrangler.reorder_potentials(local_result_from_exp +
                                                local_result)
    result = driver.wrangler.finalize_potentials(result)
    print("at the end:" + str(end - very_start))
    assert (result == driver.src_weights.sum()).all()
    exit()
コード例 #25
0
ファイル: test_gather.py プロジェクト: sdrave/charm4py
    def __init__(self, args):
        self.recvdReductions = 0
        self.expectedReductions = 5

        nDims = 1
        ARRAY_SIZE = [10] * nDims
        self.nElements = 1
        for x in ARRAY_SIZE:
            self.nElements *= x
        print('Running gather example on', charm.numPes(), 'processors for',
              self.nElements, 'elements, array dims=', ARRAY_SIZE)
        arrProxy = Array(Test, ARRAY_SIZE)
        grpProxy = Group(TestGroup)
        charm.thisProxy.updateGlobals({
            'mainProxy': self.thisProxy
        },
                                      '__main__',
                                      awaitable=True).get()
        arrProxy.doGather()
        grpProxy.doGather()
        red_future = charm.Future()
        arrProxy.doGather(red_future)
        self.done_gather_single(red_future.get())
コード例 #26
0
    def start(self):
        # print('Controller running on PE', charm.myPe())
        for i in range(charm.numPes()):
            assert i == charm.thisProxy[i].myPe(ret=True).get()

        pe = charm.myPe() - 1
        if pe == -1:
            pe = 0
        charm.thisProxy[pe].exec('global MY_GLOBAL; MY_GLOBAL = 7262',
                                 __name__,
                                 awaitable=True).get()
        assert charm.thisProxy[pe].eval('MY_GLOBAL', __name__,
                                        ret=True).get() == 7262

        Group(Test)
コード例 #27
0
def main(args):
    g1 = Group(Test)
    g2 = Group(Test)

    numArrayChares = charm.numPes() * 8
    a1 = Array(Test, numArrayChares)
    a2 = Array(Test, numArrayChares)

    charm.awaitCreation(g1, g2, a1, a2)

    wait_alldone = [charm.Future() for _ in range(4)]
    i = 0
    for collection in (g1, g2):
        collection.run(charm.numPes(), wait_alldone[i])
        i += 1

    for collection in (a1, a2):
        collection.run(numArrayChares, wait_alldone[i])
        i += 1

    for done in wait_alldone:
        done.get()
    print('DONE')
    exit()
コード例 #28
0
ファイル: retmodes.py プロジェクト: sdrave/charm4py
def main(args):
    f1 = Future()
    f2 = Future()
    done1 = Future()
    done2 = Future()
    a = Array(Test, charm.numPes() * 10, args=[f1, done1])
    g = Group(Test, args=[f2, done2])

    collections = []
    collections.append((a, f1.get(), charm.numPes() * 10))
    collections.append((g, f2.get(), charm.numPes()))
    for collection, vals, num_elems in collections:
        indexes = list(range(num_elems))
        random_idxs = random.sample(indexes, int(max(len(indexes) * 0.8, 1)))
        for random_idx in random_idxs:
            retval = collection[random_idx].getVal(False, awaitable=False, ret=False)
            assert retval is None

            retval = collection[random_idx].getVal(False, ret=True).get()
            assert retval == vals[random_idx]

            retval = collection[random_idx].getVal_th(False, awaitable=False, ret=False)
            assert retval is None

            retval = collection[random_idx].getVal_th(False, ret=True).get()
            assert retval == vals[random_idx]

        retval = collection.getVal(True, ret=False)
        assert retval is None

        retval = collection.getVal(True, awaitable=True).get()
        assert retval is None

        retval = collection.getVal(True, ret=True).get()
        assert retval == [vals[i] for i in range(num_elems)]

        retval = collection.getVal_th(True, awaitable=False)
        assert retval is None

        retval = collection.getVal_th(True, awaitable=True).get()
        assert retval is None

        retval = collection.getVal_th(True, ret=True).get()
        assert retval == [vals[i] for i in range(num_elems)]

    done1.get()
    done2.get()
    exit()
コード例 #29
0
def main(args):
    # Note that chare creation calls are also asynchronous

    # create one instance of MyChare on every processor
    my_group = Group(MyChare)

    # create 3 instances of MyChare, distributed among cores by the runtime
    my_array = Array(MyChare, 3)

    # create 2 x 2 instances of MyChare, indexed using 2D index and distributed
    # among cores by the runtime
    my_2d_array = Array(MyChare, (2, 2))

    # wait for the chare collections to be created
    charm.awaitCreation(my_group, my_array, my_2d_array)
    exit()
コード例 #30
0
ファイル: allreduce.py プロジェクト: sdrave/charm4py
def main(args):
    assert charm.numPes() % 2 == 0
    g = Group(Test)
    gsec = g[::2]  # make a section with even numbered elements

    f = Future(2)
    g.work(f, charm.numPes())
    gsec.work(f, charm.numPes() // 2, gsec)
    f.get()
    g.verify(awaitable=True).get()
    exit()