我正在 redhat8 上使用 g++8.5 编译我的代码,我注意到当我设置 OMP_SCHEDULE=static 时,然后在我的应用程序中 omp_get_schedule() 返回一个“单调”计划而不是“静态”计划。为什么会发生这种情况?如果我将 OMP_SCHEDULE 设置为其他内容(例如“动态”),那么我的应用程序会将其识别为“动态”。这是有问题的代码。有任何想法吗?谢谢
omp_sched_t kind;
int chunk_size;
omp_get_schedule(&kind, &chunk_size);
switch(kind)
{
case omp_sched_static:
{
schedule_msg = schedule_msg + "schedule=static, chunk_size="+std::to_string(chunk_size);
break;
}
case omp_sched_dynamic:
{
schedule_msg = schedule_msg + "schedule=dynamic, chunk_size="+std::to_string(chunk_size);
break;
}
case omp_sched_guided:
{
schedule_msg = schedule_msg + "schedule=guided, chunk_size="+std::to_string(chunk_size);
break;
}
case omp_sched_auto:
{
schedule_msg = schedule_msg + "schedule=auto, chunk_size="+std::to_string(chunk_size);
break;
}
default:
{
schedule_msg = schedule_msg + "schedule=monotonic, chunk_size="+std::to_string(chunk_size);
break;
}
}
Run Code Online (Sandbox Code Playgroud)
omp_sched_t定义为:
typedef enum omp_sched_t {
omp_sched_static = 1,
omp_sched_dynamic = 2,
omp_sched_guided = 3,
omp_sched_auto = 4,
omp_sched_monotonic = 0x80000000
} omp_sched_t;
Run Code Online (Sandbox Code Playgroud)
请注意,omp_sched_monotonic是修饰符而不是类型,因此monotonic:static表示为omp_sched_monotonic | omp_sched_static(并且其值为0x80000001)。
根据 OpenMP 标准:
如果指定了静态调度类型或指定了ordered 子句,并且未指定monotonic修饰符,则效果将与指定了monotonic修饰符一样。
因此, ifOMP_SCHEDULE设置为isstatic的返回值,但您的代码未正确处理单调修饰符。omp_get_schedule()0x80000001