我目前正在学习使用SCOOP在群集上的多个节点之间分布地图。我正在使用以前在类中使用的方法,该方法使用标准的多处理Pool方法将一个任务映射到sinlge节点上,即 从多处理导入池,current_process
class ExampleClass():
def __init__(self, list_of_genomes):
self.list_of_genomes = list_of_genomes
def distance_function(self, genome1, genome2):
# perform some kind of distance calculation and return the result
return distance
def createDistanceMatrix(self, child_process_chunksize, number_of_cores):
distance_matrix = []
for genome in tqdm(self.list_of_genomes):
with Pool(processes = number_of_cores) as pool:
fut = pool.starmap_async(self.distance_function, zip([genome] * len(self.list_of_genomes), self.list_of_genomes), chunksize = child_process_chunksize)
fut.wait()
distance_matrix.append(fut.get())
return distance_matrix
但是,如果我正确理解SCOOP,则map
必须在if __name__ == "__main__":
之内。这是否意味着您不能在类方法中使用SCOOP?如果是这样,还有其他方法可以从类方法中利用多个节点吗?