Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/145.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用OpenMP并行化while循环处理基于堆栈的深度优先搜索? 我有一个while循环,像下面的pSuedoC++代码< /p> stack.push(init.left); stack.push(init.right); while(!stack.empty) { t = stack.pop(); if(foo(t)) { t->left = new node; t->right = new node; stack->push(t.left) stack->push(t.right) } } 当其他线程正在计算foo(t)时,如果堆栈暂时为空,如何防止循环过早退出?如何知道堆栈是否为空?如果按顺序执行此操作,则仅当它通过所有节点时才为空_C++_Stack_Openmp - Fatal编程技术网

如何使用OpenMP并行化while循环处理基于堆栈的深度优先搜索? 我有一个while循环,像下面的pSuedoC++代码< /p> stack.push(init.left); stack.push(init.right); while(!stack.empty) { t = stack.pop(); if(foo(t)) { t->left = new node; t->right = new node; stack->push(t.left) stack->push(t.right) } } 当其他线程正在计算foo(t)时,如果堆栈暂时为空,如何防止循环过早退出?如何知道堆栈是否为空?如果按顺序执行此操作,则仅当它通过所有节点时才为空

如何使用OpenMP并行化while循环处理基于堆栈的深度优先搜索? 我有一个while循环,像下面的pSuedoC++代码< /p> stack.push(init.left); stack.push(init.right); while(!stack.empty) { t = stack.pop(); if(foo(t)) { t->left = new node; t->right = new node; stack->push(t.left) stack->push(t.right) } } 当其他线程正在计算foo(t)时,如果堆栈暂时为空,如何防止循环过早退出?如何知道堆栈是否为空?如果按顺序执行此操作,则仅当它通过所有节点时才为空,c++,stack,openmp,C++,Stack,Openmp,我不熟悉并行编程和OpenMP,请耐心听我说:)。我试图用#pragma omp parallel private(t)来封装整个循环,但该seg出现了故障 1)无法按原样并行化while循环:您需要使用OpenMP任务或将while循环转换为规范形式的for循环。2) 标准库不是线程安全的,因此您需要使用#pragma omp critical围绕循环中的每个stdlib调用,以确保一次只有一个线程执行它。如果您使用自己的实现而不是std::stack,则需要自己使其线程安全。3) 您必须接受

我不熟悉并行编程和OpenMP,请耐心听我说:)。我试图用#pragma omp parallel private(t)来封装整个循环,但该seg出现了故障

1)无法按原样并行化while循环:您需要使用OpenMP任务或将while循环转换为规范形式的for循环。2) 标准库不是线程安全的,因此您需要使用
#pragma omp critical
围绕循环中的每个stdlib调用,以确保一次只有一个线程执行它。如果您使用自己的实现而不是
std::stack
,则需要自己使其线程安全。3) 您必须接受线程弹出和推送的顺序可以从当前执行更改。你当前的算法能正确处理这个问题吗?