OpenMP and STL vector

前端 未结 2 1819
庸人自扰
庸人自扰 2021-01-01 16:19

I\'ve got some code for which I\'d like to use OpenMP in the following way:

std::vector v(1000);
# pragma omp parallel for
for (int i = 0; i <          


        
2条回答
  •  情深已故
    2021-01-01 16:46

    Multiple reads are safe but I would recommend to avoid multiple writes to the same container. But you can write to memory you manage on your own. The difference to a vector would be that you can be sure that the memory would not be changed or reallocated at the same time. Otherwise you can also use a semaphore but this would probably decrease the efficiency and if you use several it can even cause deadlocks if you don't work properly.

提交回复
热议问题