通过基本的 Minimax 搜索,使用 OMP For 在多个线程之间拆分工作似乎很容易。例如 -
#pragma omp parallel for
for (each child node)
{
val = minimax(child, depth - 1, FALSE);
bestValue = max(bestValue, val);
}
然而,似乎这对于 Alpha-Beta 修剪来说是不可能的,至少在我的理解中是这样。
#pragma omp parallel for
for (each child node)
{
α = max(α, alphabeta(child, depth - 1, α, β, FALSE));
if (β ≤ α)
break;
}
在 OpenMP 中,如果要使循环并行,则要求 For 循环只能有一个入口/出口点。然而,Alpha-Beta 剪枝打破了这个规则,因为只要需要完成剪枝,就有可能跳出循环(在上面的伪代码中,这将在 β 小于或等于 α 时发生)。
所以我的问题是,有没有办法解决 OpenMP 的这种限制?我想使用 OpenMP 并行运行我的 Alpha-Beta 搜索,但这个限制让我现在很难过。