小编use*_*119的帖子

Parallel push back to a vector of vector

I have a vector of vector. I construct this vector in a parallel manner with each index in the vector being dealt with by a single thread. Something similar to this :

vector<vector<int> > global_vec(10, vector<int>({}));

#pragma omp parallel for schedule(dynamic)
for(int i = 0; i < 10; i++)
{
    for(int j = 0; j < i * 5; j++)
    {
        global_vec[i].push_back(i);
    }
}
Run Code Online (Sandbox Code Playgroud)

I know if I had known the size of each vector beforehand, I could have allocated …

c++ openmp thread-safety

4
推荐指数
1
解决办法
172
查看次数

标签 统计

c++ ×1

openmp ×1

thread-safety ×1