def run(self): if charm.myPe() == 0 or charm.myPe() > ro.numParticipants: return #print("Group " + str(self.thisIndex) + " sending msg " + str(self.msgsSent)) self.thisProxy[0].testWhen(charm.myPe(), "hi") self.msgsSent += 1 if self.msgsSent < GRP_TO_SEND: self.thisProxy[self.thisIndex].run()
def start(self): """ Invoke the starter code for test. """ if charm.myPe() == 0: print("On PE", charm.myPe(), "before migration") self.thisProxy[self.thisIndex].test() self.toPe = (charm.myPe() + 1) % charm.numPes() self.migrate(self.toPe)
def test(self): """ Test method called after migration to assert that the chare has migrated. """ if self.thisIndex == (0,): print("Test called on PE ", charm.myPe()) assert charm.myPe() == self.toPe self.contribute(None, None, self.thisProxy[0].done)
def __init__(self): assert ( not all_created ) # makes sure constructor is only called for creation, not migration self.iteration = 0 self.originalPe = charm.myPe() self.data = numpy.arange(100, dtype='int64') * (self.originalPe + 1) # notify controllers that array elements are created and pass home PE of every element self.gather(charm.myPe(), ro.controllers.arrayElemsCreated)
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", charm.myPe()) if self.count == 2: assert charm.myPe() == 2 charm.exit()
def testWhen(self, id, msg): assert (charm.myPe() == 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 > ro.numParticipants: charm.exit()
def getVal(self, iteration): result = 53 * ro.testGroup[charm.myPe()].getVal( ret=True).get() * self.thisIndex[0] * self.iteration #assert result == 53 * (73 + charm.myPe()) * self.thisIndex[0] * self.iteration self.msgsRcvd += 1 if self.msgsRcvd == ro.numChares: self.msgsRcvd = 0 self.iteration += 1 return result
def recvLocations(self, locations): loc = defaultdict(list) for chare_idx, pe in enumerate(locations): loc[pe].append(chare_idx) myPe = charm.myPe() myPos = loc[myPe].index(self.thisIndex[0]) # i-th chare in a PE sends to i-th chare in PE-1 and PE+1 and to itself nb1 = self.thisProxy[loc[(myPe - 1) % charm.numPes()][myPos]] nb2 = self.thisProxy[loc[(myPe + 1) % charm.numPes()][myPos]] self.nbs = [nb1, nb2, self.thisProxy[self.thisIndex]] self.contribute(None, None, ro.mainProxy.start)
def __init__(self): self.x = numpy.arange(DATA_LEN, dtype='float64') y = self.x * (self.thisIndex[0] + 1) self.S1 = y.tobytes() self.S2 = array.array('d', y) self.S3 = y self.msgsRcvd = 0 self.gather(charm.myPe(), self.thisProxy.recvLocations)
def start(self): if self.thisIndex == (0, ): print("Iteration " + str(self.iteration)) self.check() A = numpy.arange(1000, dtype='float64') work = 1000 * (charm.myPe() + 1) # elements in higher PEs do more work for i in range(work): A += 1.33 self.iteration += 1 if self.iteration == MAX_ITER: self.contribute(None, None, ro.controllers[0].done) elif self.iteration % 20 == 0: self.AtSync() else: self.thisProxy[self.thisIndex].start()
def __init__(self, last): assert charm.myPe() == index_to_pe(self.thisIndex), "ArrayMap failed" if last: self.contribute(None, None, self.thisProxy.done)
def SayHi(self): print("Hello from PE", charm.myPe(), "on", time.strftime('%c')) ro.byes[(self.thisIndex + 1) % charm.numPes()].SayGoodbye()
def getVal(self): return 53 * ro.testGroup[charm.myPe()].getVal( ret=True).get() * self.thisIndex[0]
def __init__(self): self.iteration = 0 self.msgsRcvd = 0 # gather list of PEs on which each array element is located and broadcast to every member self.gather(charm.myPe(), self.thisProxy.start)
def __init__(self): print("Hello from MyChare instance in processor", charm.myPe())
def main(args): print("Charm program started on processor", charm.myPe()) print("Running on", charm.numPes(), "processors") charm.exit()
def SayGoodbye(self): print("Goodbye from PE", charm.myPe()) self.contribute(None, None, ro.mainProxy.done)
def getVal(self): return (73 + charm.myPe())