From 7c7494c91dc8501d51fbe149a3782e13df456363 Mon Sep 17 00:00:00 2001 From: Damian Birchler Date: Fri, 26 Apr 2024 16:16:04 +0200 Subject: [PATCH] Let the OS handle processor affinities. --- pytrnsys/rsim/getConfigMixin.py | 2 +- pytrnsys/rsim/runParallel.py | 15 +++------------ 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/pytrnsys/rsim/getConfigMixin.py b/pytrnsys/rsim/getConfigMixin.py index 7bf5c993..119cdbb9 100644 --- a/pytrnsys/rsim/getConfigMixin.py +++ b/pytrnsys/rsim/getConfigMixin.py @@ -59,7 +59,7 @@ def addParametricVariations(self, variations): sizeCase = len(variations[n]) - 2 if sizeCase != sizeOneVariation: raise ValueError( - "for combineAllCases=False all variations must have same lenght :%d case n:%d has a lenght of :%d" + "for combineAllCases=False all variations must have same length :%d case n:%d has a length of :%d" % (sizeOneVariation, n + 1, sizeCase) ) diff --git a/pytrnsys/rsim/runParallel.py b/pytrnsys/rsim/runParallel.py index fb3fd6cf..25f75314 100644 --- a/pytrnsys/rsim/runParallel.py +++ b/pytrnsys/rsim/runParallel.py @@ -15,9 +15,6 @@ logger = logging.getLogger("root") import pytrnsys.trnsys_util.LogTrnsys as LogTrnsys -# from __future__ import print_function - - def getNumberOfCPU(): """Returns the number of CPUs in the system""" num = 1 @@ -40,10 +37,6 @@ def getNumberOfCPU(): return num -def getExclusiveAffinityMask(cpu): - return 2 ** (cpu - 1) - - def runParallel( cmds, reduceCpu=0, outputFile=False, estimedCPUTime=0.33, delayTime=0.3, trackingFile=None, masterFile=None ): @@ -102,7 +95,7 @@ def runParallel( cpu = 1 for cmd in cmds: - newTask = "start /wait /affinity %s " % (getExclusiveAffinityMask(cpu)) + cmd + newTask = cmd newCmds.append(newTask) @@ -132,7 +125,7 @@ def runParallel( for core in cP.keys(): # print cP[core] - cP[core]["cmd"] = "start /wait /affinity %s " % (getExclusiveAffinityMask(cP[core]["cpu"])) + openCmds.pop(0) + cP[core]["cmd"] = openCmds.pop(0) cP[core]["case"] = caseNr caseNr += 1 @@ -300,9 +293,7 @@ def fail(): # assign new command if there are open commands: if openCmds: - cP[core]["cmd"] = "start /wait /affinity %s " % ( - getExclusiveAffinityMask(cP[core]["cpu"]) - ) + openCmds.pop(0) + cP[core]["cmd"] = openCmds.pop(0) cP[core]["case"] = caseNr caseNr += 1 activeP[cP[core]["cpu"] - 1] = 1