I intend to use buffers std::vector<size_t> buffer(100), one in each thread in parallelizing the loop, as suggested in this code:
std::vector<size_t> buffer(100);
#pragma omp parallel for private(buffer)
for(size_t j = 0; j < 10000; ++j) {
}
This code does not work. Although there is a buffer for each thread, the size can be 0.
How can I allocate a buffer at the beginning of each thread? Can i use #pragma omp parallel for? And I can do it more elegantly than this:
std::vector<size_t> buffer;
#pragma omp parallel for private(buffer)
for(size_t j = 0; j < 10000; ++j) {
if(buffer.size() != 100) {
#pragma omp critical
buffer.resize(100);
}
}
source
share