等待整个 omp 块完成,然后再调用第二个函数
Wait for the whole omp block to be finished before calling the second function
我没有C++使用openmp的经验,我想学习如何正确解决我的问题。我有 30 个文件需要由同一功能独立处理。每次激活该函数时,都会生成一个新的输出文件(out01.txt 到 out30.txt(,保存结果。我的机器中有 12 个处理器,想使用 10 个处理器来解决此问题。
我需要更改我的代码以等待所有 30 个文件被处理以执行 C++ 中的其他例程。目前,我无法强制我的代码等待所有 omp 范围执行,然后移动第二个函数。
请在下面找到我的代码草案。
int W = 10;
int i = 1;
ostringstream fileName;
int th_id, nthreads;
omp_set_num_threads(W);
#pragma omp parallel shared (nFiles) private(i,fileName,th_id)
{
#pragma omp for schedule(static)
for ( i = 1; i <= nFiles; i++)
{
th_id = omp_get_thread_num();
cout << "Th_id: " << th_id << endl;
// CALCULATION IS PERFORMED HERE FOR EACH FILE
}
}
// THIS is the point where the program should wait for the whole block to be finished
// Calling the second function ...
"omp for"和"omp parallel"编译指示在其范围的末尾都有一个隐式障碍。因此,在并行部分结束之前,无法执行并行部分之后的代码。因此,您的代码应该完美运行。
如果仍然存在问题,则不是因为您的代码没有在并行区域的末尾等待。
请向我们提供有关执行此代码期间发生的情况的更多详细信息。这样,我们也许能够找到问题的真正原因。
相关文章:
- 等待整个 omp 块完成,然后再调用第二个函数
- 如何为 std::vector 分配内存,然后稍后为某些元素调用构造函数?
- 我的 cout 上有一个奇怪的输出,它把答案放在第一位,然后在我调用它的地方放一个奇怪的输出.我该怎么办?
- 如何在C++中获取lua函数作为参数,然后调用它
- 钩/绕道 d3d9 (现在/结束场景) - 似乎调用我的函数然后崩溃
- C++当您取消引用指向类对象的指针,然后将其作为引用返回时,是否可以对此引用调用方法
- C++:将向量传递给函数,然后在main中调用函数.错过了什么
- 努力将指向成员函数的指针绑定到类模板的T成员,然后在槽中调用
- 缓存大量回调,然后批量调用它们,无需v表成本
- 为什么部分初始化一个类然后调用委托 ctor 失败?
- 将整数向量转换为字节数组向量,然后调用每个字节数组
- 存储在基本分配中,然后调用基本功能
- 将复制构造函数超载与DELETE,然后调用C 子类的默认构造函数
- 复制指针,然后调用 delete
- C++如何将数组传递给函数,然后调用它来显示数组的值
- munmap_chunk 当操作员调用时指针无效,然后调用 destroctor
- 用管理器注册一个类,然后调用子类被覆盖的方法
- 需要某种方法将函数存储在列表中,然后调用它们
- 如何从类型列表继承,然后调用继承成员列表中的成员
- 创建结构实例数组,然后调用其他结构内部的函数,传递对象数组(指针)