def test_op_logical(done, op, vector_size, use_numpy=False): if vector_size > 1: if use_numpy: data = np.random.rand(vector_size) p = 0.1 data = np.random.choice(a=[False, True], size=(vector_size), p=[p, 1 - p]) else: data = list(map(bool, range(0, vector_size))) else: data = bool(random.randint(0, 1)) finished_future = Future(2) chares = Array(TestVec, vector_size, args=[op, data]) chares.do_test(None, finished_future) section = chares[0:vector_size] section.do_test(section, finished_future) val1, val2 = finished_future.get() try: if vector_size > 1: assert list(val1) == list(val2) else: assert val1 == val2 print('[Main] Reduction with Reducer.%s passes.' % get_op_name(op)) done(True) except AssertionError: print('[Main] Reduction with Reducer.%s is not correct.' % get_op_name(op)) done(False)
def test_op(done, op, vector_size, use_numpy=False): if vector_size > 1: if use_numpy: data = np.random.rand(vector_size) else: data = list(range(0, vector_size)) else: data = random.uniform(0, 5) finished_future = Future(2) chares = Array(TestVec, vector_size, args=[op, data]) chares.do_test(None, finished_future, awaitable=True).get() section = chares[0:vector_size] section.do_test(section, finished_future) val1, val2 = finished_future.get() try: if vector_size > 1: if use_numpy: assert np.isclose(val1, val2, atol=1e-5).all() else: assert list(val1) == list(val2) else: assert val1 == val2 print('[Main] Reduction with Reducer.%s passes.' % get_op_name(op)) done(True) except AssertionError: print('[Main] Reduction with Reducer.%s is not correct.' % get_op_name(op)) done(False)
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()
def main(args): print('\nUsage: particle.py [num_chares_x num_chares_y] [max_particles_per_cell_start]') if len(args) >= 3: array_dims = (int(args[1]), int(args[2])) else: array_dims = (8, 4) # default: 2D chare array of 8 x 4 cells if len(args) == 4: max_particles_per_cell_start = int(args[3]) else: max_particles_per_cell_start = 10000 print('\nCell array size:', array_dims[0], 'x', array_dims[1], 'cells') # create 2D Cell chare array and start simulation sim_done = Future() cells = Array(Cell, array_dims, args=[array_dims, max_particles_per_cell_start, sim_done], useAtSync=True) num_particles_per_cell = cells.getNumParticles(ret=True).get() print('Total particles created:', sum(num_particles_per_cell)) print('Initial conditions:\n\tmin particles per cell:', min(num_particles_per_cell), '\n\tmax particles per cell:', max(num_particles_per_cell)) print('\nStarting simulation') t0 = time.time() cells.run() # this is a broadcast # wait for the simulation to finish sim_done.get() print('Particle simulation done, elapsed time=', round(time.time() - t0, 3), 'secs') 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): numChares = charm.numPes() * CHARES_PER_PE cells = Array(Cell, numChares, args=[numChares]) charm.awaitCreation(cells) f = Future() cells.work(f) f.get() 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 main(args): home_pes = Future() array = Array(Test, charm.numPes() * 4, args=[home_pes], useAtSync=True) charm.thisProxy.updateGlobals( { 'all_created': True, 'arrayElemHomeMap': home_pes.get() }, '__main__', awaitable=True).get() array.start()
def __init__(self, args): charm.thisProxy.updateGlobals( { 'mainProxy': self.thisProxy, 'NUM_CHARES': charm.numPes() * CHARES_PER_PE }, '__main__', awaitable=True).get() self.arrayProxy = Array(Test, NUM_CHARES) self.arrayProxy.run() self.startTime = time.time()
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()
def main(args): numChares = min(charm.numPes() * CHARES_PER_PE, 64) testProxy = Array(Test, numChares) f = Future(num_vals=numChares) testProxy.getData(f) data = f.get() print('[Main] Received data: ' + str(data)) assert sorted(data) == list(range(numChares)), 'Multi-futures failed!' print('[Main] All done.') exit()
def main(args): testProxy = Array(Test, charm.numPes() * CHARES_PER_PE) sum_f = Future() min_f = Future() max_f = Future() testProxy.getStats((sum_f, min_f, max_f)) print('[Main] Sum: ' + str(sum_f.get()) + ', Min: ' + str(min_f.get()) + ', Max: ' + str(max_f.get())) print('[Main] All done.') exit()
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 for ' + str(nElements) + ' elements, array dims=' + str(ARRAY_SIZE)) arrProxy = Array(Test, ARRAY_SIZE) groupProxy = Group(TestGroup) charm.thisProxy.updateGlobals({'mainProxy': self.thisProxy, 'arrProxy': arrProxy, 'groupProxy': groupProxy}, '__main__', awaitable=True).get() arrProxy.doReduction()
def __init__(self, args): self.recvdReductions = 0 self.expectedReductions = 4 nDims = 1 ARRAY_SIZE = [10] * nDims lastIdx = tuple([x-1 for x in ARRAY_SIZE]) self.nElements = 1 for x in ARRAY_SIZE: self.nElements *= x print('Running reduction example on ' + str(charm.numPes()) + ' processors for ' + str(self.nElements) + ' elements, array dims=' + str(ARRAY_SIZE)) arrProxy = Array(Test, ARRAY_SIZE) charm.thisProxy.updateGlobals({'mainProxy': self.thisProxy, 'arrProxy': arrProxy, 'lastIdx': lastIdx}, '__main__', awaitable=True).get() arrProxy.doReduction()
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()
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()
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 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 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 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()
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()
class Main(Chare): 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 testQD(self, callback): self.qdReached = False check_fut = Future() t0 = time() self.workers.start() if callback is not None: charm.startQD(callback) if isinstance(callback, threads.Future): callback.get() print('QD reached') else: self.wait('self.qdReached') else: charm.waitQD() assert time() - t0 > WORK_TIME self.workers.check(check_fut) check_fut.get() def recvQD(self): print('QD reached') self.qdReached = True
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 __init__(self, args): ro.X = 47 num_chares = min(charm.numPes() * CHARES_PER_PE, MAX_CHARES) assert num_chares % 2 == 0 workers = Array(Worker, num_chares, args=[self.thisProxy]) self.num_responses1 = self.num_responses2 = 0 self.result = 0 for i in range(NUM_ITER): workers.sendVal() self.wait("self.num_responses1 == " + str(num_chares // 2) + " and 33 == TEST_GLOBAL") self.wait("self.num_responses2 == " + str(num_chares // 2) + " and 47 == ro.X") assert (self.result == num_chares * 237) assert (self.num_responses1 == num_chares // 2) assert (self.num_responses2 == num_chares // 2) self.num_responses1 = self.num_responses2 = 0 self.result = 0 charm.printStats() exit()
class Main(Chare): def __init__(self, args): charm.thisProxy.updateGlobals( { 'mainProxy': self.thisProxy, 'NUM_CHARES': charm.numPes() * CHARES_PER_PE }, '__main__', awaitable=True).get() self.arrayProxy = Array(Test, NUM_CHARES) self.arrayProxy.run() self.startTime = time.time() def collectSum(self, result): assert_almost_equal(result.sum(), NUM_CHARES * VAL_CHECK, 0.05) self.arrayProxy.run() def done(self): print('Program done in', time.time() - self.startTime) charm.printStats() exit()
def main(args): threaded = False if len(args) > 1 and args[1] == '-t': threaded = True pings = Array(Ping, 2) charm.awaitCreation(pings) for _ in range(2): done_future = Future() pings[0].start(done_future, threaded) totalTime = done_future.get() print("ping pong time per iter (us)=", totalTime / NITER * 1000000) exit()
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()
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): 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()
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)