The sample code below is a simplified version of my working code. In this code, writing to shared variable is done only at the last line where std::vector::push_back is called.
std::vector<struct FortyByteStruct> results;
#pragma omp parallel for num_threads(8)
for (int i = 0; i < 250; i++)
{
struct FortyByteStruct result = some_heavy_work(i);
#pragma omp critical
{
results.push_back(result);
}
}
I was wondering if this push_back operation would result in false-sharing, giving me some chance to optimize further by getting rid of it. I've decided to do some bench tests first, before digging into this issue.
With chrono, I've measured the wall clock execution time of some_heavy_work() and the critical section separately. The latter took about 10^(-4) times of execution time of the former, so I've concluded that there would be almost no benefit from optimizing this part whether false-sharing is involved or not.
Anyway, I'm still curious whether false-sharing is an issue here. Do I have to look at the internal implementation of std::vector? Any enlightment would be greatly appreciated. (I'm on VS2015)