def __init__(self, simName, startTime, endTime, minDelay=1, useMPI=False, mpiLibName=defaultMpichLibName): self.Entity = Entity #Include in the top Simian namespace self.name = simName self.startTime = startTime self.endTime = endTime self.minDelay = minDelay self.now = startTime #If simulation is running self.running = False #Stores the entities available on this LP self.entities = {} #Events are stored in a priority-queue or heap, in increasing #order of time field. Heap top can be accessed using self.eventQueue[0] #event = {time, name, data, tx, txId, rx, rxId}. self.eventQueue = [] #Stores the minimum time of any event sent by this process, #which is used in the global reduce to ensure global time is set to #the correct minimum. self.infTime = endTime + 2*minDelay self.minSent = self.infTime #[[Base rank is an integer hash of entity's name]] self.baseRanks = {} #Make things work correctly with and without MPI if useMPI: #Initialize MPI try: global MPI from MPILib import MPI self.useMPI = True self.MPI = MPI(mpiLibName) self.rank = self.MPI.rank() self.size = self.MPI.size() except: raise SimianError("Please ensure libmpich is available to ctypes before using Simian for MPI based simulations.\nTry passing absolute path to libmpich.[dylib/so/dll] to Simian.") else: self.useMPI = False self.MPI = None self.rank = 0 self.size = 1 #One output file per rank self.out = open(self.name + "." + str(self.rank) + ".out", "w") #Write some header information for each output file self.out.write("===========================================\n") self.out.write("----------SIMIAN-PIE PDES ENGINE-----------\n") self.out.write("===========================================\n") if self.useMPI: self.out.write("MPI: ON\n\n") else: self.out.write("MPI: OFF\n\n")
def __init__(self, simName, startTime, endTime, minDelay=1, useMPI=False, mpiLibName=defaultMpichLibName, optimistic=False, optimistic_GVT_Threshold=1, customHeap='heap'): self.Entity = Entity #Include in the top Simian namespace self.name = simName self.startTime = startTime self.endTime = endTime self.minDelay = minDelay self.now = startTime #If simulation is running self.running = False #Stores the entities available on this LP self.entities = {} #Stores the minimum time of any event sent by this process, #which is used in the global reduce to ensure global time is set to #the correct minimum. self.infTime = endTime + 2 * minDelay self.minSent = self.infTime #[[Base rank is an integer hash of entity's name]] self.baseRanks = {} #Events are stored in a priority-queue or heap, in increasing #order of time field. Heap top can be accessed using self.eventQueue[0] #event = {time, name, data, tx, txId, rx, rxId}. #self.eventQueue = [] self.heap = customHeap assert self.heap in [ 'heap', '2tHeapBin', '2tHeapFib', '2tHeapBinFib', '2tHeapFibBin', 'pyheap', 'fibHeap', 'calendarQ' ] #, '2tLadderQ', '3tHeap', 'ladderQ', 'splay'] try: global heap heap = getattr(__import__('%s.heap' % self.heap), 'heap') #heap = __import__('%s.heap' % self.heap) #, 'heap') self.heap = heap self.eventQueue = heap.init(self) except: raise SimianError("Can not find heap library: %s.heap" % self.heap) #Make things work correctly with and without MPI if useMPI: #Initialize MPI try: global MPI from MPILib import MPI except: raise ("here") try: self.useMPI = True self.MPI = MPI(mpiLibName) self.rank = self.MPI.rank() self.size = self.MPI.size() except: raise SimianError( "Please ensure libmpich is available to ctypes before using Simian for MPI based simulations.\nTry passing absolute path to libmpich.[dylib/so/dll] to Simian." ) else: self.useMPI = False self.MPI = None self.rank = 0 self.size = 1 self.optimistic = optimistic if self.optimistic: if not self.useMPI or self.size == 1: self.optimistic = False # switch to conservative we need MPI and ranks > 1 if self.rank == 0: print('using heap: %s' % self.heap) self.optimistic_GVT = 0 self.optimisticNumAntimessagesSent = 0 self.optimisticNumEventsRolledBack = 0 self.optimisticNumEvents = 0 self.optimistic_count_round = 0 self.optimistic_t_min = self.infTime self.optimistic_white = 0 self.optimistic_color = "white" self.optimistic_GVT_Threshold = optimistic_GVT_Threshold self.optimistic_GVT_mem_req = 10 self.optimisticGVTNumTimesCalcd = 0 self.optimisticGVTNumTimesCalc = (endTime - startTime) / 300 # every 0.3% # statistic collection # self.statistics = 0 if self.statistics: self.statsQSize = [] self.statsAvgQSize = 0 self.statsStdQSize = 0 self.GVTCalcNum = 0 #self.rollbackLength = [] #self.avgRollbackLength = 0 #self.stdRollbackLength = 0 self.statsOpsLen = [] self.statsAvgOpsLen = 0 self.statsStdOpsLen = 0 self.statsFirstQOpsLen, self.statsSecondQOpsLen, self.statsThirdQOpsLen = 0, 0, 0 self.statsNumEnt = 0 self.statsRecvEventsPerEnt = [] # reciever self.statsAvgRecvEventsPerEnt = 0 self.ststsStdRecvEventsPerEnt = 0 self.statsSendEventsPerEnt = [] # sender self.statsAvgSendEventsPerEnt = 0 self.ststsStdSendEventsPerEnt = 0 ## TODO USE quantiles??? ## end statistics ## #One output file per rank self.out = open(self.name + "." + str(self.rank) + ".out", "w") #Write some header information for each output file self.out.write("===========================================\n") self.out.write("----------SIMIAN-PIE PDES ENGINE-----------\n") self.out.write("===========================================\n") if self.useMPI: self.out.write("MPI: ON\n\n") else: self.out.write("MPI: OFF\n\n")