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()
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): global blockDimX, blockDimY, num_chare_x, num_chare_y if len(args) != 3 and len(args) != 5: print('\nUsage:\t', args[0], 'array_size block_size') print('\t', args[0], 'array_size_X array_size_Y block_size_X block_size_Y') exit() if len(args) == 3: arrayDimX = arrayDimY = int(args[1]) blockDimX = blockDimY = int(args[2]) elif len(args) == 5: arrayDimX, arrayDimY = [int(arg) for arg in args[1:3]] blockDimX, blockDimY = [int(arg) for arg in args[3:5]] assert (arrayDimX >= blockDimX) and (arrayDimX % blockDimX == 0) assert (arrayDimY >= blockDimY) and (arrayDimY % blockDimY == 0) num_chare_x = arrayDimX // blockDimX num_chare_y = arrayDimY // blockDimY # set the following global variables on every PE, wait for the call to complete charm.thisProxy.updateGlobals( { 'blockDimX': blockDimX, 'blockDimY': blockDimY, 'num_chare_x': num_chare_x, 'num_chare_y': num_chare_y }, awaitable=True).get() print('\nRunning Jacobi on', charm.numPes(), 'processors with', num_chare_x, 'x', num_chare_y, 'chares') print('Array Dimensions:', arrayDimX, 'x', arrayDimY) print('Block Dimensions:', blockDimX, 'x', blockDimY) print('Max iterations:', MAX_ITER) print('Threshold:', THRESHOLD) if numbaFound: # wait until Numba functions are compiled on every PE, so we can get consistent benchmark results Group(Util).compile(awaitable=True).get() print('Numba compilation complete') else: print( '!!WARNING!! Numba not found. Will run without Numba but it will be very slow' ) sim_done = Future() # create 2D chare array of Jacobi objects (each chare will hold one block) array = Array(Jacobi, (num_chare_x, num_chare_y), args=[sim_done]) charm.awaitCreation(array) print('Starting computation') initTime = time.time() array.run() # this is a broadcast total_iterations = sim_done.get() # wait until the computation completes totalTime = time.time() - initTime if total_iterations >= MAX_ITER: print('Finished due to max iterations', total_iterations, 'total time', round(totalTime, 3), 'seconds') else: print('Finished due to convergence, iterations', total_iterations, 'total time', round(totalTime, 3), 'seconds') exit()