gpt4 book ai didi

parallel-processing - OpenMP:如何使循环分配仅取决于数组大小?

转载 作者:行者123 更新时间:2023-12-01 13:13:45 54 4
gpt4 key购买 nike

考虑以下代码块:

int array[30000]

#pragma omp parallel
{
for( int a = 0; a < 1000; a++ )
{
#pragma omp for nowait
for( int i = 0; i < 30000; i++ )
{
/*calculations with array[i] and also other array entries happen here*/
}
}
}

竞态条件在我的应用程序中不是问题,但我想强制并行区域中的每个线程处理 正是 每次通过内部 for 循环运行相同的数组 block 。

据我了解, schedule(static) 根据线程数和数组长度分配 for 循环项。然而,对于不同循环或同一循环的不同重复(即使线程数和长度相同),分布是否会发生变化尚不清楚。

标准对此有何评论? schedule(static) 是否足以强制执行此操作?

最佳答案

我相信这句话来自 OpenMP Specification提供这样的保证:

A compliant implementation of the static schedule must ensure that the same assignment of logical iteration numbers to threads will be used in two worksharing-loop regions if the following conditions are satisfied: 1) both worksharing-loop regions have the same number of loop iterations, 2) both worksharing-loop regions have the same value of chunk_size specified, or both worksharing-loop regions have no chunk_size specified, 3) both worksharing-loop regions bind to the same parallel region, and 4) neither loop is associated with a SIMD construct.

关于parallel-processing - OpenMP:如何使循环分配仅取决于数组大小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57820933/

54 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com