c - 如何动态选择调度类型?

标签 c openmp schedule pragma

我需要比较具有不同调度类型和线程数的循环与 openMP 的执行时间。

我可以通过直接在 pragma 宏中传递一个 int 变量来动态设置线程数:

int threads_number = 4;
#pragma omp parallel for num_threads(threads_number)

但我正在尝试为 schedule 做同样的事情,我需要比较 staticdynamicguided类型。但是看来我不能使用 int 作为枚举,也不能使用 char* 作为这个的名称。

有什么方法可以动态选择它,还是我必须写 3 次循环然后用 if 选择调用哪一个,这看起来有点脏?

最佳答案

当应用的调度为运行时时,您可以设置调度类型。

When schedule(runtime) is specified, the decision regarding scheduling is deferred until runtime. The schedule kind and size of the chunks can be chosen at run time by setting the environment variable OMP_SCHEDULE. If this environment variable is not set, the resulting schedule is implementation-defined. When schedule(runtime) is specified, chunk_size must not be specified. - OpenMP-4.5 Specification

这是通过函数 void omp_set_schedule(omp_sched_t kind, int chunk_size);

完成的

可用的调度类型在 omp.h 中定义为下面的枚举

typedef enum omp_sched_t {
    omp_sched_static = 1,
    omp_sched_dynamic = 2,
    omp_sched_guided = 3,
    omp_sched_auto = 4
} omp_sched_t;

关于c - 如何动态选择调度类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37288493/

相关文章:

mysql - 日程选择器,保存 SQL 的最佳方式

python - 如何在一段时间内启动/停止 Python 函数(例如从上午 10 点到 12 点 :30pm)?

c - pthreads,我如何使用不同的类型?

c - 有没有办法创建一个空的 C 数组,并在更新它时跟踪它的空性?

c - 无限提示循环问题

c - 使用 openmp 并行化矩阵以避免错误共享

c - 为什么这段与 OpenMP 并行化的代码不能正常工作?

tensorflow - 减少控制台冗长

angular2 使用 PrimeNG-Scheduler 实现 FullCalendar-Scheduler

c - GStreamer : Sending string to another pipeline via UDP