我有一个令人尴尬的并行循环:
# Definitions
def exhaustiveExplorationsWithSimilarityAll(inputFolder, outputFolder, similarityMeasure):
phasesSpeedupDictFolder=parsePhasesSpeedupDictFolder(inputFolder)
avgSpeedupProgramDict=computeAvgSpeedupProgram(phasesSpeedupDictFolder)
parameters={
PROGRAMSPHASESSPEEDUPDICTS:phasesSpeedupDictFolder,
PROGRAMSAVGSPEEDUPDICT:avgSpeedupProgramDict
}
similarityHandler= SimilarityHandler(similarityMeasure,parameters)
# Sequential running
for fileName in os.listdir(inputFolder):
print fileName
exhaustiveExplorationsWithSimilarity(inputFolder + fileName, outputFolder + fileName, similarityHandler)
我想使用Joblib
Parallel 使其并行:
# Parallel version
num_cores = multiprocessing.cpu_count()
parallel= Parallel(n_jobs=num_cores)
for fileName in os.listdir(inputFolder):
print fileName
parallel(delayed(exhaustiveExplorationsWithSimilarity(inputFolder + fileName, outputFolder + fileName, similarityHandler)))
或其他版本:
arg_generator = ((inputFolder + fileName, outputFolder + fileName, similarityHandler) for fileName in os.listdir(inputFolder))
parallel(delayed(exhaustiveExplorationsWithSimilarity)(arg_generator))
但是在运行它时会抱怨:
parallel(delayed(exhaustiveExplorationsWithSimilarity(inputFolder + fileName, outputFolder + fileName, similarityHandler)))
File "/usr/lib/pymodules/python2.7/joblib/parallel.py", line 516, in __call__
for function, args, kwargs in iterable:
TypeError: 'function' object is not iterable
我在这里想念什么?任何帮助表示赞赏。