def main(): futures = [] for i in legion.IndexLaunch(10): futures.append(hi(i)) for i, future in enumerate(futures): print("got %s" % future.get()) assert int(future.get()) == i # Same in 2 dimensions. futures = [] for point in legion.IndexLaunch([3, 3]): futures.append(hi(point)) for i, point in enumerate(legion.Domain.create([3, 3])): assert futures[i].get() == point R = legion.Region.create([4, 4], {'x': legion.float64}) P = legion.Partition.create_equal(R, [2, 2]) legion.fill(R, 'x', 0) for i in legion.IndexLaunch([2, 2]): hello(R, i) for i in legion.IndexLaunch([2, 2]): hello(P[i], i) # Again, with a more explicit syntax. # ID is the name of the (implicit) loop variable. futures = legion.index_launch([3, 3], hi, ID) for point in legion.Domain.create([3, 3]): assert futures[point].get() == point legion.index_launch([2, 2], hello, R, ID) legion.index_launch([2, 2], hello, P[ID], ID)
def main(): futures = [] for i in legion.IndexLaunch(10): futures.append(hi(i)) for i, future in enumerate(futures): print("got %s" % future.get()) assert int(future.get()) == i # Same in 2 dimensions. futures = [] for point in legion.IndexLaunch([3, 3]): futures.append(hi(point)) for i, point in enumerate(legion.Domain.create([3, 3])): assert futures[i].get() == point
def main(): # No explicit type specified, value is pickled f = Future([1, 2, 3]) print("value of f.get() is %s" % f.get()) assert f.get() == [1, 2, 3] # Explicit type specified, value not pickled g = Future(123, legion.int64) print("value of g.get() is %s" % g.get()) assert g.get() == 123 # Using a buffer object to pass raw bytes h = Future.from_buffer('asdf'.encode('utf-8')) h_value = codecs.decode(h.get_buffer(), 'utf-8') print("value of h.get_raw() is %s" % h_value) assert h_value == 'asdf' i = Future(return_void(), value_type=legion.void) print("value of i.get() is %s" % i.get()) show(f) show(g) show_buffer(h) show_nested(f) for i in legion.IndexLaunch([3]): show_index(i, f)
def main_task(): # Create a 2D index space of size 4x4. I = legion.Ispace.create([4, 4]) # Create a field space with a single field x of type float64. For # interop with C++, we have to choose an explicit field ID here # (in this case, 1). We could leave this out if the code were pure # Python. F = legion.Fspace.create({'x': (legion.float64, 1)}) # Create a region from I and F and launch two tasks. R = legion.Region.create(I, F) init_result = init(R) child_result = inc(R, 1) # Check task results: print("init task returned", init_result.get()) assert init_result.get() == 123 print("child task returned", child_result.get()) assert child_result.get() == 42 values = 'abc' for i in legion.IndexLaunch([3]): print('queue %s' % i) hello(i, values[i]) print("main_task done")
def main(): futures = [] for i in legion.IndexLaunch([10]): futures.append(hi(i)) for i, future in enumerate(futures): print("got %s" % future.get()) assert future.get() == i
def main(): R = legion.Region.create([4, 4], {'x': legion.float64}) P = legion.Partition.create_equal(R, [2, 2]) legion.fill(R, 'x', 0) trace1 = legion.Trace() for t in range(5): with trace1: for i in legion.IndexLaunch([2, 2]): look(R, i) for i in legion.IndexLaunch([2, 2]): incr(P[i], i) trace2 = legion.Trace() for t in range(5): with trace2: legion.index_launch([2, 2], look, R, ID) legion.index_launch([2, 2], incr, P[ID], ID)
def main(): R = legion.Region([4], {'x': legion.float64}) P = legion.Partition.equal(R, [4]) legion.fill(R, 'x', 0) hello2(P[0], 0) for i in legion.IndexLaunch([4]): hello2(P[i], i) legion.index_launch([4], hello2, P[ID], ID) # FIXME: This is needed in nopaint to avoid a race with region deletion legion.execution_fence()
def main_task(): assert _ds is not None events = _ds.smd().events() repeat = 'REPEAT' in os.environ and os.environ['REPEAT'] == '1' if repeat: assert _ds.config.limit events = itertools.cycle(events) if _ds.config.limit is not None: events = itertools.islice(events, _ds.config.limit) if _ds.config.predicate is not None: events = itertools.ifilter(_ds.config.predicate, events) eager = 'EAGER' in os.environ and os.environ['EAGER'] == '1' if eager: start = legion.c.legion_get_current_time_in_micros() events = list(events) stop = legion.c.legion_get_current_time_in_micros() print('Enumerating: Elapsed time: %e seconds' % ((stop - start) / 1e6)) print('Enumerating: Number of events: %s' % len(events)) print('Enumerating: Events per second: %e' % (len(events) / ((stop - start) / 1e6))) randomize = 'RANDOMIZE' in os.environ and os.environ['RANDOMIZE'] == '1' print('Randomize?', randomize) if randomize: assert eager random.seed(123456789) # Don't actually want this to be random random.shuffle(events) # Number of events per task chunksize = int( os.environ['CHUNKSIZE']) if 'CHUNKSIZE' in os.environ else 8 # Number of tasks per processor per launch overcommit = int( os.environ['OVERCOMMIT']) if 'OVERCOMMIT' in os.environ else 1 # Number of Python processors global_procs = legion.Tunable.select(legion.Tunable.GLOBAL_PYS).get() local_procs = legion.Tunable.select(legion.Tunable.LOCAL_PYS).get() # Number of tasks per launch launchsize = (max(global_procs - local_procs, local_procs)) * overcommit print('Chunk size %s' % chunksize) print('Launch size %s' % launchsize) start = legion.c.legion_get_current_time_in_micros() # Group events by calib cycle so that different cycles don't mix events = itertools.groupby( events, lambda e: e.get(psana.EventOffset).lastBeginCalibCycleDgram()) if _ds.small_data is not None: # create HDF5 output file hdf5 = legion_HDF5.LegionHDF5(_ds.small_data.filepath) nevents = 0 nlaunch = 0 ncalib = 0 file_buffer = [] file_buffer_length = 0 for calib, calib_events in events: calib = legion.Future(calib) for launch_events in chunk(chunk(calib_events, chunksize), launchsize): if nlaunch % 20 == 0: print('Processing event %s' % nevents) sys.stdout.flush() dictsBuffer = [] for idx in legion.IndexLaunch([len(launch_events)]): dicts = analyze_chunk(map(Location, launch_events[idx]), calib) dictsBuffer.append(dicts) nevents += len(launch_events[idx]) nlaunch += 1 if _ds.small_data is not None: for dicts in dictsBuffer: d = dicts.get() file_buffer = file_buffer + d file_buffer_length = file_buffer_length + len(d) if file_buffer_length >= _ds.small_data.gather_interval: hdf5.append_to_file(file_buffer) file_buffer = [] file_buffer_length = 0 ncalib += 1 legion.execution_fence(block=True) stop = legion.c.legion_get_current_time_in_micros() if _ds.config.teardown is not None: # FIXME: Should be a must-epoch launch for idx in legion.IndexLaunch([global_procs]): teardown() print('Elapsed time: %e seconds' % ((stop - start) / 1e6)) print('Number of calib cycles: %s' % ncalib) print('Number of launches: %s' % nlaunch) print('Number of events: %s' % nevents) print('Events per second: %e' % (nevents / ((stop - start) / 1e6))) # Hack: Estimate bandwidth used # total_events = 75522 * repeat # total_size = 875 * repeat # GB # fraction_events = float(nevents)/total_events # bw = fraction_events * total_size / ((stop - start)/1e6) # print('Estimated bandwidth used: %e GB/s' % bw) print('End of run') sys.stdout.flush()
def main(): futures = [] for i in legion.IndexLaunch([10]): futures.append(hi(i)) for future in futures: print("got %s" % future.get())