tbb parallel_reduce 用于 OpenMP 缩减的片段
tbb parallel_reduce for a snippet of OpenMP reduction
我有以下 OpenMP 的代码片段,我知道它肯定可以正常工作。
char cipherChar=plainText[charLoop];
#pragma omp parallel for reduction(^:cipherChar)
for(keyLoop=0;keyLoop<numKeys;keyLoop++) {
cipherChar = cipherChar ^ getBit( &(keyList[keyLoop]), charLoop);
}
cypherText[charLoop]=cipherChar;
但是当我尝试用 tbb 编写此代码时,我没有得到正确的输出
char cipherChar=plainText[charLoop];
cipherChar ^= tbb::parallel_reduce(tbb::blocked_range<int>(0, numKeys), cipherChar,
[&](const tbb::blocked_range<int>& r, char c) -> char {
char result = c;
for(int i = r.begin(); i <= r.end(); i++) {
result ^= getBit( &(keyList[i]), charLoop);
}
return result;
},
[](char a, char b) {
return a ^ b;
}
);
cypherText[charLoop]=cipherChar;
谁能告诉我我在上面的 tbb 代码中可能做错了什么,我得到了错误的结果?
要parallel_reduce
的第二个参数(blocked_range
后面的参数(应该是所用缩减操作的标识值。实现使用此值来初始化累加器。对于独占 OR,标识值为 0。此外,标识值的类型必须与结果的类型匹配。
所以,你的电话应该是
cipherChar ^= tbb::parallel_reduce(
tbb::blocked_range<int>(0, numKeys),
char(0), // <- identity for XOR
body_lambda,
reduction_lambda
);
相关文章:
- OpenMP阵列性能较差
- OpenMP卸载说'fatal error: could not find accel/nvptx-none/mkoffload'
- 使用 GCC 卸载的 OpenMP 卸载失败,并出现"Ptx assembly aborted due to errors"
- OpenMP:并行更新数组总是需要减少数组吗
- 如何使用OpenMP并行这两个循环
- 从python调用openMP共享库时,未定义opnMP函数
- 如何使用OpenMP并行化此矩阵时间矢量运算
- 如何使用OpenMP使这个循环并行
- 如何通过替换顺序代码的while循环来添加OpenMP for循环
- 查找最近配对时的OpenMP竞赛条件
- 使用输入打破 OpenMP 中的循环
- 为什么 openmp 的并行不适用于矢量化色彩空间转换?
- 这个带有模板<类 Vector 的C++代码片段有什么问题>
- Opengl 3.1 GLSL 140 在 C++ 年输出白色在片段着色器中
- 在 openmp 中,omp_get_thread_num是否绑定到物理线程?
- 在C++中使用并行化的预期速度是多少(不是 OpenMp,而是 <thread>)
- OpenMP 加上unordered_map<字符串、双字符串的缩减>
- OpenMP 与有序和关键指令并行
- 我使用 OpenMP 的线程越多,执行时间就越长,这是怎么回事?
- tbb parallel_reduce 用于 OpenMP 缩减的片段