def say(self, msg): """ Helper method which is called by invoking the element proxy. This method is expected to be called on only the PE for which the proxy is created. """ self.count += 1 print("Say", msg, "on PE", CkMyPe()) if self.count == 2: assert CkMyPe() == 2 charm.exit()
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 SayHi(self, hiNo): print("Hi[" + str(hiNo) + "] from element " + str(self.thisIndex) + " on PE " + str(CkMyPe())) if self.thisIndex == ro.lastIdx: ro.mainProxy.done() else: nextIndex = list(self.thisIndex) for i in range(ro.nDims - 1, -1, -1): nextIndex[i] = (nextIndex[i] + 1) % ro.ARRAY_SIZE[i] if nextIndex[i] != 0: break return self.thisProxy[nextIndex].SayHi(hiNo + 1)
def doReduction(self): print("TestGroup element on PE " + str(CkMyPe()) + " is starting its contributions.") # test contributing single int back to Main self.contribute(42, Reducer.sum, ro.mainProxy.done_int) # test contributing list of floats back to Main num = [10.1, 13.4] self.contribute(num+[float(self.thisIndex)], Reducer.sum, ro.mainProxy.done_float) # test nop reduction to main self.contribute(None, Reducer.nop, ro.mainProxy.done_nop) # test contributing to TestArray[0] self.contribute([4.2, 13.1], Reducer.sum, ro.arrayProxy[0].reduceGroupToArray) # test contributing to TestArray (broadcast) self.contribute(-4, Reducer.sum, ro.arrayProxy.reduceGroupToArrayBcast) # test contributing to TestGroup[0] self.contribute([5, 7, -3, 0], Reducer.sum, self.thisProxy[0].reduceGroupToGroup) # test contributing to TestGroup (broadcast) self.contribute(-4.2, Reducer.sum, self.thisProxy.reduceGroupToGroupBcast)
def doReduction(self): print("Test element " + str(self.thisIndex) + " on PE " + str(CkMyPe()) + " is starting its contributions.") # test contributing single int back to Main self.contribute(42, Reducer.sum, ro.mainProxy.done_int) # test contributing list of floats back to main num = [10.1, 13.4] self.contribute(num+[float(self.thisIndex[0])], Reducer.sum, ro.mainProxy.done_float) # test nop reduction to main self.contribute(None, Reducer.nop, ro.mainProxy.done_nop) # test contributing to Test[0] self.contribute(4.2, Reducer.sum, self.thisProxy[0].reductionTarget) # test contributing to Test (broadcast) self.contribute(numpy.array([4.2, 8.4]), Reducer.sum, self.thisProxy.reductionTargetBcast) # test contributing to TestGroup[0] self.contribute(4, Reducer.sum, ro.groupProxy[0].reduceFromArray) # test contributing to TestGroup (broadcast) self.contribute(array.array('i', [0, 8, 3]), Reducer.sum, ro.groupProxy.reduceFromArrayBcast)
def __init__(self): print("Hello " + str(self.thisIndex) + " created on PE " + str(CkMyPe()))
def __init__(self): print("TestGroup " + str(self.thisIndex) + " created on PE " + str(CkMyPe()))
def SayGoodbye(self): print("Goodbye from PE", CkMyPe()) self.contribute(None, None, ro.mainProxy.done)
def SayHi(self): print("Hello from PE", CkMyPe(), "on", time.strftime('%c')) ro.byes[(self.thisIndex + 1) % CkNumPes()].SayGoodbye()
def __init__(self, arg0, arg1): assert [arg0, arg1 ] == [42, "testing" ], "Constructor args for dynamic array insertion failed." print("Hello " + str(self.thisIndex) + " created on PE " + str(CkMyPe()))
def run(self): if CkMyPe() == 0: return #print("Group " + str(self.thisIndex) + " sending msg " + str(self.msgsSent)) self.thisProxy[0].testWhen(CkMyPe(), "hi") self.msgsSent += 1 if self.msgsSent < GRP_TO_SEND: self.thisProxy[self.thisIndex].run()