I'm trying to parallelize some vector functions in a struct using openMP. While it works well with most of my implementations, I find that since the constructor for std::vector<>
has a linear complexity, I can't get better performance and instead get something that's even worse than doing it sequentially for initialization.
Here's one of the initializors
/**
* @brief Construct a new constant parallel Vector object with a given value constantEntry
*
* @param dim
* @param constantEntry
*/
parallelVector(const int dim, const double constantEntry){
dimension = dim;
values = std::vector<double>(dimension);
#pragma omp parallel for schedule(static)
for (int i=0 ; i<dimension; i++){
values[i] = constantEntry;
}
}
The std::vector<>
documentation says I can get O(1) complexity using allocators, but since I'm not too familiar with them, I was wondering if something with unique pointers is possible instead?