2

我在并行化new_textunicode 类型的那部分代码时遇到了困难:

for old, new in self.replacements:
    line = pywikibot.replaceExcept(
        line, old, new, self.excsInside, self.site)
if new_text != entry.text:
    yield pywikibot.Page(self.site, entry.title)

使用joblibprocess-pool ,该任务看起来很容易,但是new_text在循环之外使用了它。我不知道 or 的等价物#pragama omp ordered,因为Python#pragma omp atomic没有 OpenMP 包装器......

if如果它并行运行,我如何确定 new_next 的值将在语句中是什么?

4

1 回答 1

0

由于它本质上是顺序的,因此您可以按行并行化:

for line in new_text
    for old, new in self.replacements:
        line = pywikibot.replaceExcept(
            line, old, new, self.excsInside, self.site)

并且你并行化外for循环(每次替换映射,然后通过连接减少)。

于 2014-05-30T19:51:30.830 回答