【发布时间】:2017-02-17 19:00:14
【问题描述】:
我在 OpenMP 中并行化了一个 for 循环,我试图为每个线程创建一个优先级队列,以便我可以更新与线程对应的优先级队列,所以我正在尝试这样的事情:
#include <queue>
#include <omp.h>
void test(){
// I need a priority queue per thread
// std::priority_queue<int> q_per_thread;
# pragma omp parallel for num_threads(10)
for(int i = 0; i < 100; i++){
// push i to the queue corresponding to the thread
}
}
这可能吗?
【问题讨论】:
-
并行循环后队列中的数据要做什么?
-
为什么每个线程都有一个队列和循环?循环用于数据并行,您不和不应该必须关心处理数据的线程。您不应该关注 task 并行性或代理吗?
标签: c++ multithreading openmp