astrodatagui: CalcAllFlaresThread: split list of dictionaries
previously we had a lot of overhead spawning new processes for every single list entry. Splitting it this way only spawns <core count> processes once, heaving no continuous overhead.
This commit is contained in:
@@ -6,7 +6,9 @@ from ..flaredetector.flaredetector import calculateFlareFitsForLightcurve
|
|||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
def getFlareCount(filesDict):
|
def getFlareCount(filesDictList):
|
||||||
|
retDictList = []
|
||||||
|
for filesDict in filesDictList:
|
||||||
lc = lk.read(filesDict["FilePath"])
|
lc = lk.read(filesDict["FilePath"])
|
||||||
lc.flux = lc["sap_flux"]
|
lc.flux = lc["sap_flux"]
|
||||||
lc_flattenend = lc.flatten()
|
lc_flattenend = lc.flatten()
|
||||||
@@ -22,8 +24,9 @@ def getFlareCount(filesDict):
|
|||||||
retDict["pdcsapPeaks"] = pdcsapPeaks
|
retDict["pdcsapPeaks"] = pdcsapPeaks
|
||||||
retDict["pdcsapPeaksCount"] = len(pdcsapPeaks)
|
retDict["pdcsapPeaksCount"] = len(pdcsapPeaks)
|
||||||
retDict["pdcsapFits"] = pdcsapFits
|
retDict["pdcsapFits"] = pdcsapFits
|
||||||
|
retDictList.append(retDict)
|
||||||
|
|
||||||
return retDict
|
return retDictList
|
||||||
|
|
||||||
class CalcAllFlaresThread(QThread):
|
class CalcAllFlaresThread(QThread):
|
||||||
progress = pyqtSignal(int)
|
progress = pyqtSignal(int)
|
||||||
@@ -36,18 +39,14 @@ class CalcAllFlaresThread(QThread):
|
|||||||
#@pyqtSlot()
|
#@pyqtSlot()
|
||||||
def run(self):
|
def run(self):
|
||||||
cpuCount = multiprocessing.cpu_count()
|
cpuCount = multiprocessing.cpu_count()
|
||||||
print(len(self.allFlaresDictList))
|
splitList = [self.allFlaresDictList[i:i + cpuCount] for i in range(0, len(self.allFlaresDictList), cpuCount)]
|
||||||
start = time.time()
|
|
||||||
executor = concurrent.futures.ProcessPoolExecutor(cpuCount)
|
executor = concurrent.futures.ProcessPoolExecutor(cpuCount)
|
||||||
futures = [executor.submit(getFlareCount, starDict) for starDict in self.allFlaresDictList]
|
futures = [executor.submit(getFlareCount, starDictPartList) for starDictPartList in splitList]
|
||||||
concurrent.futures.wait(futures)
|
concurrent.futures.wait(futures)
|
||||||
end = time.time()
|
|
||||||
print("Multiprocess time needed: ", end-start)
|
|
||||||
ret = []
|
ret = []
|
||||||
#for dic in executor.map(getFlareCount, self.allFlaresDictList):
|
|
||||||
# print(dic)
|
|
||||||
# ret.append(dic)
|
|
||||||
for future in futures:
|
for future in futures:
|
||||||
ret.append(future.result())
|
retList = future.result()
|
||||||
|
for dic in retList:
|
||||||
|
ret.append(dic)
|
||||||
|
|
||||||
self.finished.emit(ret)
|
self.finished.emit(ret)
|
||||||
Reference in New Issue
Block a user