C++ C++;OpenMP退出,同时在并行内存中循环
我在Windows7机器上使用VisualStudio2010和OpenMP。我已经编写了以下代码snipplet:C++ C++;OpenMP退出,同时在并行内存中循环,c++,while-loop,multiprocessing,openmp,nested-loops,C++,While Loop,Multiprocessing,Openmp,Nested Loops,我在Windows7机器上使用VisualStudio2010和OpenMP。我已经编写了以下代码snipplet: #pragma omp parallel for for(int jj=0;jj<2;jj++){ MSG msg; // do something in parallel for jj int i_loopcounter = 0; bool b_continue = true; while(GetMessage(&msg, NULL, 0, 0)&&
#pragma omp parallel for
for(int jj=0;jj<2;jj++){
MSG msg;
// do something in parallel for jj
int i_loopcounter = 0;
bool b_continue = true;
while(GetMessage(&msg, NULL, 0, 0)&&b_continue){
TranslateMessage(&msg);
DispatchMessage(&msg);
i_loopcounter++;
if(i_loopcounter==50){
b_continue = false;
//abort(); <- ugly, since a window appears
//exit(0); <- rest of the code is not executed
//break; <- not allowed
//goto end; <- not allowed
}
}
end:;
// do some other stuff in parallel for jj
} //end of parallel for
全局变量\u i\u NoDownloads
统计下载文件的数量,如果达到2,则不再需要消息循环。然而,即使有了这些改变,程序的行为也不会改变,尽管while循环现在不一定需要50次迭代。我认为问题在于同时取消消息循环的采购
更新2:在阅读了大量有关Windows消息的概念后,我找到了一个有效的解决方案。并行部分没有完成的原因是GetMessage的行为
再次,非常感谢对这个问题做出贡献的任何人
干杯
TL您不能在并行区域中止, 可能的解决办法,
您似乎使用了少量的硬编码迭代:
#pragma omp parallel for
for(int jj = 0; jj < 2; jj++){
/* ... */
} //end of parallel for
在不同的OpenMP线程中运行相同的消息循环?我想不出这是怎么回事。消息循环只属于一个线程。您需要完全重新设计代码。从显示i_loopcounter和omp_get_thread_num()的某个cout命令中,似乎有两个消息循环,因为我得到了两个线程号(0和1)。谢谢您的链接,但我得到的结果与问题描述中的结果相同。通常我不想中止并行区域。我想退出while循环,这样并行for就可以完成,如果我没有为while循环设置abort contion,程序将永远不会终止。目前,我正在考虑一个使用节的解决方案。这里我有三个线程,2个用于并行,它向第三个线程发送消息,第三个线程处理它们并在一段时间后终止。但我不知道它是否有效。目前我不太清楚消息的处理方式。
#pragma omp parallel for
for(int jj = 0; jj < 2; jj++){
/* ... */
} //end of parallel for
#pragma omp parallel
{
#pragma omp sections
{
#pragma omp section
{
/* jj = 0 */
}
#pragma omp section
{
/* jj = 1 */
}
} // End sections
#pragma omp single
{
/* While loop */
}
/* ... */
} // End parallel