在CPU端加速时,发现加速比一直上不去,甚至出现并行速度比串行慢10倍以上的情况
CPU为 移动端 AMD 7945HX,16个物理核,32个线程
测试代码如下
#include <oneapi/tbb/parallel_for.h>
#include <oneapi/tbb/blocked_range.h>
#include <oneapi/tbb/tick_count.h>
#include <oneapi/tbb.h>
#include <iostream>
#include <vector>
#include <cmath> // 添加头文件以使用 sqrt 函数
using namespace std;
using namespace oneapi::tbb;
constexpr int loops_num = 1;
typedef vector<double>::iterator IntVecIt;
IntVecIt vecbegin;
struct body {
vector<double>* result; // 指向结果数组的指针
body(vector<double>& res) : result(&res) {}
void operator()(const blocked_range<IntVecIt>& r) const {
for (auto i = r.begin(); i != r.end(); ++i) {
// 增加计算复杂度,并将结果存储到结果数组中
double sum = 0.0;
for (int j = 0; j < loops_num; ++j) {
sum += sqrt(*i + j) / 100.0;
}
(*result)[std: