def main(args): f1 = Future() f2 = Future() Group(Test, args=[f1, f2]) assert f1.get() == charm.numPes() assert f2.get() == charm.numPes() exit()
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()
def done(self, result): self.count += result self.countReductions += 1 if self.countReductions == 2: assert self.count == (charm.numPes() + charm.numPes() * CHARES_PER_PE) print('Program done') exit()
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()
def done_float(self, reduction_result): expected_result = [x * charm.numPes() for x in [10.1, 13.4]] indices_sum = (charm.numPes() * (charm.numPes() - 1)) / 2 expected_result += [float(indices_sum)] assert_allclose(reduction_result, expected_result, 1e-03) print('[Main] All sum_float contributions done. Test passed') self.recvdReductions += 1 if self.recvdReductions >= self.expectedReductions: exit()
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()
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()
def recvLocations(self, locations): loc = defaultdict(list) for chare_idx, pe in enumerate(locations): loc[pe].append(chare_idx) myPe = charm.myPe() myPos = loc[myPe].index(self.thisIndex[0]) # i-th chare in a PE sends to i-th chare in PE-1 and PE+1 and to itself nb1 = self.thisProxy[loc[(myPe - 1) % charm.numPes()][myPos]] nb2 = self.thisProxy[loc[(myPe + 1) % charm.numPes()][myPos]] self.nbs = [nb1, nb2, self.thisProxy[self.thisIndex]] self.contribute(None, None, mainProxy.start)
def __init__(self, args): assert charm.numPes() >= 2 g = Group(Test) a = Array(Test, charm.numPes() * 4) self.thisProxy.startPhase(1, 2, 33, 44, awaitable=True).get() g.startPhase(1, 2, 33, 44, awaitable=True).get() a.startPhase(1, 2, 33, 44, awaitable=True).get() for collection in (g, a, self.thisProxy): collection.recv(1, 2, awaitable=True).get() collection.recv(1, 2, 33, awaitable=True).get() collection.recv(1, 2, 33, 44, awaitable=True).get() collection.recv(y=2, x=1, awaitable=True).get() collection.recv(b=44, a=33, y=2, x=1, awaitable=True).get() if collection == g: single_chare = 1 elif collection == a: single_chare = 4 else: continue collection[single_chare].recv(1, 2, awaitable=True).get() collection[single_chare].recv(1, 2, 33, awaitable=True).get() collection[single_chare].recv(1, 2, 33, 44, awaitable=True).get() collection[single_chare].recv(y=2, x=1, awaitable=True).get() collection[single_chare].recv(b=44, a=33, y=2, x=1, awaitable=True).get() self.thisProxy.startPhase(10, 20, 3000, 4000, awaitable=True).get() g.startPhase(10, 20, 3000, 4000, awaitable=True).get() a.startPhase(10, 20, 3000, 4000, awaitable=True).get() for collection in (g, a, self.thisProxy): collection.recv(10, 20, 3000, 4000, awaitable=True).get() collection.recv(10, 20, 3000, b=4000, awaitable=True).get() collection.recv(b=4000, a=3000, y=20, x=10, awaitable=True).get() if collection == g: single_chare = 1 elif collection == a: single_chare = 4 else: continue collection[single_chare].recv(10, 20, 3000, b=4000, awaitable=True).get() collection[single_chare].recv(b=4000, a=3000, y=20, x=10, awaitable=True).get() exit()
def main(args): assert charm.numPes() > 1 global section_pes section_pes = random.sample(range(charm.numPes()), charm.numPes() // 2) charm.thisProxy.updateGlobals({'section_pes': section_pes}, awaitable=True).get() g = Group(Test, onPEs=section_pes, args=[4862]) assert g[section_pes[0]].test2(ret=True).get() == 34589 g.test(awaitable=True).get() assert g.getIdx(ret=True).get() == sorted(section_pes) assert g[section_pes[0]].getIdx(ret=True).get() == section_pes[0] g.testallreduce(awaitable=True).get() exit()
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()
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)
def __init__(self, args): self.RENDER = True try: args.remove('--NO-RENDER') self.RENDER = False except ValueError: pass print('\nUsage: wave2d.py [num_iterations] [max_framerate])') global NUM_ITERATIONS, MAX_FRAMERATE if len(args) > 1: NUM_ITERATIONS = int(args[1]) if len(args) > 2: MAX_FRAMERATE = int(args[2]) print('Running wave2d on', charm.numPes(), 'processors for', NUM_ITERATIONS, 'iterations') print('Max framerate is', MAX_FRAMERATE, 'frames per second') self.count = 0 # tracks from how many workers I have received a subimage for this iteration programStartTime = frameStartTime = time.time() # Create new 2D array of worker chares array = Array(Wave, (CHARE_ARRAY_WIDTH, CHARE_ARRAY_HEIGHT)) # tell all the worker chares to start the simulation array.work(self.thisProxy) if self.RENDER: tk = tkinter.Tk() self.frame = Image.new('RGB', (IMAGE_WIDTH, IMAGE_HEIGHT)) img = ImageTk.PhotoImage(self.frame) label_image = tkinter.Label(tk, image=img) label_image.pack() self.frameReady = Future() for i in range(NUM_ITERATIONS): self.frameReady.get() # wait for the next frame if MAX_FRAMERATE > 0: elapsed = time.time() - frameStartTime if elapsed < 1/MAX_FRAMERATE: # enforce framerate charm.sleep(1/MAX_FRAMERATE - elapsed) if self.RENDER: fps = round(1/(time.time() - frameStartTime)) # draw frames per second value on image d = ImageDraw.Draw(self.frame) d.text((10,10), str(fps) + ' fps', fill=(0,0,0,255)) img = ImageTk.PhotoImage(self.frame) label_image.configure(image=img) label_image.image = img tk.update_idletasks() tk.update() # loop simulation every 1000 iterations reset = (i % 1000 == 0) frameStartTime = time.time() array.resume(reset) # tell workers to resume self.frameReady = Future() print('Program Done!, Total time=', time.time() - programStartTime) exit()
def main(args): pes = list(range(charm.numPes())) found_pes = set([0]) explore_tree(0, pes, found_pes) assert sorted(list(found_pes)) == pes exit()
def __init__(self, args): charm.thisProxy.updateGlobals({ 'mainProxy': self.thisProxy }, '__main__', awaitable=True).get() self.testProxy = Array(Test, charm.numPes() * CHARES_PER_PE)
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()
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()
def main(args): NUM_TASKS = (charm.numPes() - 1) * 100 # test charm.pool.map() tasks = list(range(NUM_TASKS)) for chunksize in (1, 8): for func in (square, square_coro): t0 = time() for _ in range(NUM_TRIALS): result = charm.pool.map(func, tasks, chunksize=chunksize) assert result == [func(x) for x in tasks] print('Elapsed=', time() - t0) # test charm.pool.submit() funcs = [square, square_coro, add_val, add_val_coro] tasks = [] for i in range(NUM_TASKS): tasks.append((funcs[i % len(funcs)], i)) for chunksize in (1, 8): t0 = time() for _ in range(NUM_TRIALS): result = charm.pool.submit(tasks, chunksize=chunksize) assert result == [f(x) for f, x in tasks] print('Elapsed=', time() - t0) exit()
def done_int(self, reduction_result): assert reduction_result == 42 * charm.numPes( ), 'Group-to-singleton sum_int reduction failed' print('[Main] All sum_int contributions done. Test passed') self.recvdReductions += 1 if self.recvdReductions >= self.expectedReductions: exit()
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 = {}
def __init__(self): if isinstance(self.thisIndex, tuple): myIndex = self.thisIndex[0] else: myIndex = self.thisIndex if charm.numPes() <= 20 or myIndex == 0: print('Test', self.thisIndex, 'created')
def done_gather_array(self, result): gather_arr_indices = [tuple([i]) for i in range(self.nElements)] gather_grp_indices = [[i, 42] for i in range(charm.numPes())] assert result == gather_arr_indices or result == gather_grp_indices, 'Gather arrays failed.' print('[Main] Gather collective for arrays done. Test passed') self.recvdReductions += 1 if self.recvdReductions >= self.expectedReductions: exit()
def start(self): """ Invoke the starter code for test. """ if charm.myPe() == 0: print(self.thisIndex, 'on PE', charm.myPe(), 'before migration') self.toPe = (charm.myPe() + 1) % charm.numPes() self.thisProxy[self.thisIndex].migrate(self.toPe)
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)
def main(args): numChares = charm.numPes() * CHARES_PER_PE cells = Array(Cell, numChares, args=[numChares]) charm.awaitCreation(cells) f = Future() cells.work(f) f.get() exit()
def done_gather_single(self, result): gather_arr_indices = list(range(self.nElements)) gather_grp_indices = list(range(charm.numPes())) assert result == gather_arr_indices or result == gather_grp_indices, 'Gather single elements failed.' print('[Main] Gather collective for single elements done. Test passed') self.recvdReductions += 1 if self.recvdReductions >= self.expectedReductions: exit()
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()
def sayHi(self, hello_num): print('Hi[' + str(hello_num) + '] from element', self.thisIndex) if self.thisIndex == charm.numPes() - 1: # we reached the last element print('All done') exit() else: # pass the hello message to the next element self.thisProxy[self.thisIndex + 1].sayHi(hello_num + 1)
def __init__(self, args): assert charm.numPes() > 1 numChares = charm.numPes() * CHARES_PER_PE self.workers = Array(Worker, numChares, args=[numChares]) print('WORK_TIME=', WORK_TIME) qdGroupReceivers = Group(QDReceiver, args=[self.thisProxy]) qdArrayReceivers = Array(QDReceiver, charm.numPes(), args=[self.thisProxy]) charm.awaitCreation(self.workers, qdGroupReceivers, qdArrayReceivers) self.testQD(callback=self.thisProxy.recvQD) self.testQD(callback=qdGroupReceivers.recvQD) self.testQD(callback=qdArrayReceivers.recvQD) self.testQD(callback=qdGroupReceivers[1].recvQD) self.testQD(callback=qdArrayReceivers[1].recvQD) self.testQD(callback=Future()) self.testQD(callback=None) exit()
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()