def done_float(self, reduction_result): expected_result = [x*CkNumPes() for x in [10.1, 13.4]] indices_sum = (CkNumPes() * (CkNumPes() - 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): CkExit()
def __init__(self, args): ro.mainProxy = self.thisProxy ro.NUM_CHARES = CkNumPes() * CHARES_PER_PE ro.arrayProxy = Array(Test, ro.NUM_CHARES) ro.arrayProxy.run() self.startTime = time.time()
def __init__(self, args): if len(args) <= 1: args = [None, 2, 3] # default: 2 dimensions of size 3 elif len(args) != 3: charm.abort( "Usage : python array_hello.py [<num_dimensions> <array_size>]" ) ro.nDims = int(args[1]) ro.ARRAY_SIZE = [int(args[2])] * ro.nDims ro.firstIdx = [0] * ro.nDims ro.lastIdx = tuple([x - 1 for x in ro.ARRAY_SIZE]) self.nElements = 1 for x in ro.ARRAY_SIZE: self.nElements *= x print("Running Hello on " + str(CkNumPes()) + " processors for " + str(self.nElements) + " elements") ro.mainProxy = self.thisProxy self.arrProxy = Array(Hello, ndims=ro.nDims) print("Created array proxy") indices = list( itertools.product(range(ro.ARRAY_SIZE[0]), repeat=ro.nDims)) assert len(indices) == self.nElements for i in indices: self.arrProxy.ckInsert(i) self.arrProxy.ckDoneInserting() self.arrProxy[ro.firstIdx].SayHi(17)
def __init__(self, args): ro.numChares = CkNumPes() * CHARES_PER_PE ro.arrayIndexes = [(i, ) for i in range(ro.numChares)] ro.testProxy = Array(Test, ro.numChares) ro.mainProxy = self.thisProxy ro.testProxy.doIteration() self.iterations = 0 self.startTime = time.time()
def done_gather_single(self, result): gather_arr_indices = list(range(self.nElements)) gather_grp_indices = list(range(CkNumPes())) 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): CkExit()
def testWhen(self, id, msg): assert (CkMyPe() == 0) and (self.current == id) and (msg == "hi") print(str(id) + " " + str(self.msgsRcvd)) self.msgsRcvd += 1 if self.msgsRcvd >= GRP_TO_SEND: self.msgsRcvd = 0 self.current += 1 if self.current == CkNumPes(): charm.exit()
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(CkNumPes())] 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): CkExit()
def SayHi(self, hellos): hellos.addHello("Hi[" + str(hellos.hiNo) + "] from element " + str(self.thisIndex)) hellos.hiNo += 1 if self.thisIndex + 1 < CkNumPes(): # Pass the hello list on: self.thisProxy[self.thisIndex + 1].SayHi(hellos) else: ro.mainProxy.done(hellos)
def __init__(self, args): if (len(args) != 3) and (len(args) != 7): print(args[0] + " [array_size] [block_size]") print( "OR " + args[0] + " [array_size_X] [array_size_Y] [array_size_Z] [block_size_X] [block_size_Y] [block_size_Z]" ) charm.abort("Incorrect program arguments") if len(args) == 3: ro.arrayDimX = ro.arrayDimY = ro.arrayDimZ = int(args[1]) ro.blockDimX = ro.blockDimY = ro.blockDimZ = int(args[2]) elif len(args) == 7: ro.arrayDimX, ro.arrayDimY, ro.arrayDimZ = [ int(arg) for arg in args[1:4] ] ro.blockDimX, ro.blockDimY, ro.blockDimZ = [ int(arg) for arg in args[4:7] ] if (ro.arrayDimX < ro.blockDimX) or (ro.arrayDimX % ro.blockDimX != 0): charm.abort("array_size_X % block_size_X != 0!") if (ro.arrayDimY < ro.blockDimY) or (ro.arrayDimY % ro.blockDimY != 0): charm.abort("array_size_Y % block_size_Y != 0!") if (ro.arrayDimZ < ro.blockDimZ) or (ro.arrayDimZ % ro.blockDimZ != 0): charm.abort("array_size_Z % block_size_Z != 0!") ro.num_chare_x = ro.arrayDimX // ro.blockDimX ro.num_chare_y = ro.arrayDimY // ro.blockDimY ro.num_chare_z = ro.arrayDimZ // ro.blockDimZ print("\nSTENCIL COMPUTATION WITH BARRIERS\n") print("Running Stencil on " + str(CkNumPes()) + " processors with " + str((ro.num_chare_x, ro.num_chare_y, ro.num_chare_z)) + " chares") print("Array Dimensions: " + str((ro.arrayDimX, ro.arrayDimY, ro.arrayDimZ))) print("Block Dimensions: " + str((ro.blockDimX, ro.blockDimY, ro.blockDimZ))) # Create new array of worker chares ro.mainProxy = self.thisProxy self.array = Array(Stencil, (ro.num_chare_x, ro.num_chare_y, ro.num_chare_z)) # Start the computation self.array.begin_iteration()
def __init__(self, args): self.expectedReductions = 7 self.recvdReductions = 0 ro.nDims = 1 ro.ARRAY_SIZE = [10] * ro.nDims # 1-D array with 10 elements ro.firstIdx = [0] * ro.nDims ro.lastIdx = tuple([x-1 for x in ro.ARRAY_SIZE]) nElements = 1 for x in ro.ARRAY_SIZE: nElements *= x print("Running reduction example on " + str(CkNumPes()) + " processors for " + str(nElements) + " elements, array dims=" + str(ro.ARRAY_SIZE)) ro.mainProxy = self.thisProxy ro.arrProxy = Array(Test, ro.ARRAY_SIZE) ro.groupProxy = Group(TestGroup) ro.arrProxy.doReduction()
def __init__(self, args): if len(args) <= 1: self.total_iterations = default_total_iterations else: self.total_iterations = int(args[1]) self.iteration = self.count = 0 self.programStartTime = self.periodStartTime = time.time() ro.mainProxy = self.thisProxy # store the main proxy print("Running wave2d on " + str(CkNumPes()) + " processors") # Create new array of worker chares ro.arrayProxy = Array(Wave, (chareArrayWidth, chareArrayHeight)) # Start the computation ro.arrayProxy.begin_iteration(False)
def main(args): if len(args) <= 1: args = [None, 3, 2] # default: 3 dimensions of size 2 each elif len(args) != 3: charm.abort( "Usage : python array_hello.py [<num_dimensions> <array_size>]") ro.nDims = int(args[1]) ro.ARRAY_SIZE = [int(args[2])] * ro.nDims ro.firstIdx = [0] * ro.nDims ro.lastIdx = tuple([x - 1 for x in ro.ARRAY_SIZE]) nElements = 1 for x in ro.ARRAY_SIZE: nElements *= x print("Running Hello on " + str(CkNumPes()) + " processors for " + str(nElements) + " elements, array dims=" + str(ro.ARRAY_SIZE)) arrProxy = Array(Hello, ro.ARRAY_SIZE) arrProxy[ro.firstIdx].SayHi(17)
def __init__(self, args): self.recvdReductions = 0 self.expectedReductions = 5 ro.nDims = 1 ro.ARRAY_SIZE = [10] * ro.nDims ro.firstIdx = [0] * ro.nDims ro.lastIdx = tuple([x-1 for x in ro.ARRAY_SIZE]) self.nElements = 1 for x in ro.ARRAY_SIZE: self.nElements *= x print("Running gather example on " + str(CkNumPes()) + " processors for " + str(self.nElements) + " elements, array dims=" + str(ro.ARRAY_SIZE)) ro.mainProxy = self.thisProxy ro.arrProxy = Array(Test, ro.ARRAY_SIZE) ro.grpProxy = Group(TestGroup) ro.arrProxy.doGather() ro.grpProxy.doGather() red_future = charm.createFuture() ro.arrProxy.doGather(red_future) self.done_gather_single(red_future.get())
def reduceGroupToGroup(self, reduction_result): assert self.thisIndex == 0 assert list(reduction_result) == [CkNumPes()*x for x in [5, 7, -3, 0]], "Group-to-group reduction failed." ro.mainProxy.done_group_to_group()
def __init__(self, args): print("Running Hello on " + str(CkNumPes()) + " processors") grpProxy = Group(Hello) grpProxy[0].SayHi(HelloList(17)) ro.mainProxy = self.thisProxy
def __init__(self, args): if CkNumPes() < 3: charm.abort("Run program with at least 3 PEs") Group(Test).run()
def done_int(self, reduction_result): assert reduction_result == 42*CkNumPes(), "Group-to-singleton sum_int reduction failed" print("[Main] All sum_int contributions done. Test passed") self.recvdReductions += 1 if (self.recvdReductions >= self.expectedReductions): CkExit()
def reduceGroupToArrayBcast(self, reduction_result): assert reduction_result == -4*CkNumPes(), "Group-to-array bcast reduction failed." self.contribute(None, None, ro.mainProxy.done_group_to_array_bcast)
def reduceGroupToArray(self, reduction_result): assert self.thisIndex[0] == 0 assert_allclose(reduction_result, [CkNumPes()*x for x in [4.2, 13.1]], 1e-03) ro.mainProxy.done_group_to_array()
def reduceGroupToGroupBcast(self, reduction_result): assert_almost_equal(reduction_result, -4.2*CkNumPes(), 1e-03) self.contribute(None, None, ro.mainProxy.done_group_to_group_bcast)
def SayHi(self): print("Hello from PE", CkMyPe(), "on", time.strftime('%c')) ro.byes[(self.thisIndex + 1) % CkNumPes()].SayGoodbye()
def __init__(self, args): if CkNumPes() < 3: charm.abort("Run program with at least 3 PEs") grp_proxy = Group(Test) grp_proxy[0].start()