Example #1
0
    lastPE = charm.numPes() - 1
    if lastPE != 0:
        print("\nWhole topo tree rooted at", lastPE)
        printWholeTree(lastPE, lastPE)
        assert (len(allPes_check) == charm.numPes()
                and set(allPes_check) == set(range(charm.numPes())))
        allPes_check = []

    print("\nEven numbered PE tree, rooted at PE 0")
    evenPEs = [pe for pe in range(charm.numPes()) if pe % 2 == 0]
    printEvenNbTree(evenPEs, 0)
    assert (len(evenPes_check) == len(evenPEs)
            and set(evenPes_check) == set(evenPEs))
    evenPes_check = []

    newRoot = evenPEs[-1]
    if newRoot != 0:
        evenPEs.insert(
            0, evenPEs.pop())  # move root from back to beginning of list
        print("\nEven numbered PE tree, rooted at PE", newRoot)
        printEvenNbTree(evenPEs, newRoot)
        assert (len(evenPes_check) == len(evenPEs)
                and set(evenPes_check) == set(evenPEs))
        evenPes_check = []

    exit()


charm.start(main)
Example #2
0
    def reduceGroupToGroup(self, reduction_result):
        assert self.thisIndex == 0
        assert list(reduction_result) == [
            charm.numPes() * x for x in [5, 7, -3, 0]
        ], 'Group-to-group reduction failed.'
        mainProxy.done_group_to_group()

    def reduceGroupToGroupBcast(self, reduction_result):
        assert_almost_equal(reduction_result, -4.2 * charm.numPes(), 1e-03)
        self.contribute(None, None, mainProxy.done_group_to_group_bcast)


class TestArray(Chare):
    def __init__(self):
        print('TestArray ' + str(self.thisIndex) + ' created on PE ' +
              str(charm.myPe()))

    def reduceGroupToArray(self, reduction_result):
        assert self.thisIndex[0] == 0
        assert_allclose(reduction_result,
                        [charm.numPes() * x for x in [4.2, 13.1]], 1e-03)
        mainProxy.done_group_to_array()

    def reduceGroupToArrayBcast(self, reduction_result):
        assert reduction_result == -4 * charm.numPes(
        ), 'Group-to-array bcast reduction failed.'
        self.contribute(None, None, mainProxy.done_group_to_array_bcast)


charm.start(Main)
Example #3
0
    print('[Main] Sum: ' + str(sum_f.get()) + ', Min: ' + str(min_f.get()) +
          ', Max: ' + str(max_f.get()))
    print('[Main] All done.')
    exit()


class Test(Chare):
    def getStats(self, futures):
        if self.thisIndex[0] == 0:
            self.sum_future, self.min_future, self.max_future = futures

        self.contribute(self.thisIndex[0], Reducer.sum,
                        self.thisProxy[0].collectStats)
        self.contribute(self.thisIndex[0], Reducer.min,
                        self.thisProxy[0].collectStats)
        self.contribute(self.thisIndex[0], Reducer.max,
                        self.thisProxy[0].collectStats)

    def collectStats(self, stat_result):
        assert self.thisIndex[0] == 0, 'Reduction target incorrect!'
        if stat_result == 0:
            self.min_future.send(stat_result)
        elif stat_result == (charm.numPes() * CHARES_PER_PE) - 1:
            self.max_future.send(stat_result)
        else:
            self.sum_future.send(stat_result)


charm.start(entry=main)
Example #4
0
    ss = rng.bit_generator._seed_seq
    init_seeds = ss.spawn(num_init_cond)
    if charm:
        sol = np.array(charm.pool.map(partial(min_action, params=params),
                                      init_seeds),
                       dtype=object)
        np.savez(specs['data_folder'] + specs['name'] + '_results.npz',
                 path=np.array(sol[:, 0]),
                 params=np.array(sol[:, 1]),
                 action=np.array(sol[:, 2]),
                 time=np.array(sol[0, 3]),
                 **specs)
    else:
        sol = min_action(init_seeds[0], params)
        np.savez(specs['data_folder'] + specs['name'] + '_results.npz',
                 path=sol[0],
                 params=sol[1],
                 action=sol[2],
                 time=sol[3],
                 **specs)

    exit()


if __name__ == '__main__':
    if charm:
        from charm4py import charm
        charm.start(run)
    else:
        run(None)
Example #5
0

class Hello(Chare):
    def check1(self):
        assert charm.myPe() == 3
        return 68425


class Test(Chare):
    def __init__(self):
        assert charm.myPe() == 2

    @coro
    def test(self, proxy, method_name):
        assert getattr(proxy[1], method_name)(ret=True).get() == 32255


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()


charm.start(main, modules=['proxies_same_name_aux'])
Example #6
0
    #
    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))
    #print(result)
    assert (result == 9000000).all()
    charm.printStats()
    exit()


    #assert (result == 9000000).all()



    #future = my_array.work(li, ret=True)
    #individual = MyChare

    #individual




if __name__ == "__main__":
    Options.PROFILING = True
    #
    ti = time()
    charm.start(main)  # call main([]) in interactive mode
    #main("a")
    #print(time() - ti)
Example #7
0
from charm4py import charm, Chare, Group
import hello
import goodbye


class Main(Chare):

    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()

    def done(self):
        exit()


# Start a main chare of type Main. We specify to the charm runtime which
# modules contain Chare definitions. Note that the __main__ module is always
# searched for chare definitions, so we don't have to specify it
charm.start(Main, modules=['hello', 'goodbye'])