我必须处置 8 个处理器。我想做并行调整大小如下:
vector<vector <int> > test;
test.resize(10000);
#pragma omp parallel num_threads(8)
{
#pragma omp for
for (int i = 0;i < 10000;i++)test[i].resize(500000);
}
我注意到该程序没有使用 100% 的处理器能力——它只使用了 15%。当我更改代码时
vector<vector <int> > test;
test.resize(1000000);
#pragma omp parallel num_threads(8)
{
#pragma omp for
for (int i = 0;i < 1000000;i++)test[i].resize(5000);
}
该程序使用了大约 60% 的处理器功率。我不明白这种现象——我希望它在两种情况下都能使用 100% 的处理器能力。我在这里错过了什么吗?