OpenMP False Sharing

≡放荡痞女 提交于 2019-12-08 07:53:28

Use reduction instead of explicitly indexing an array based on the thread ID. That array virtually guarantees false sharing.

i.e. replace this

#pragma omp parallel for 
    clones[omp_get_thread_num()]->mse() += norm_2(dedy);

for (int i = 0; i < omp_get_max_threads(); i++) {
     neural_network->mse() += clones[i]->mse();

with this:

#pragma omp parallel for reduction(+ : mse)
     mse += norm_2(dedy);

neural_network->mse() = mse;
ThomasBastiani

One way of knowing for sure is looking at cache statistics with a tool like cachegrind :

valgrind --tool=cachegrind [command]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!