42
edits
Changes
→Critical construct
struct MyStruct
{ float int value; //int padding[24];};
int main(int argc, char** argv){
MyStruct testArr[4];
omp_set_num_threads(4);
double start_time = omp_get_wtime();
#pragma omp parallel for
for (int i = 0; i < 4; i++) {
testArr[i].value = 0;
for (int j = 0; j < 10000; j++) {
}
}
std::cout << "testArr value 1: " << testArr[0].value << std::endl;
std::cout << "testArr value 2: " << testArr[1].value << std::endl;
std::cout << "testArr value 3: " << testArr[2].value << std::endl;
std::cout << "testArr value 4: " << testArr[3].value << std::endl;
double time = omp_get_wtime() - start_time;
return 0;
}
}
</nowiki>
______________________________________________________________________________________________________________________________________________________________
[[File:4threads_criticalcritical.jpg|1000pxpng]]
=Conclusion =
False sharing is a lurking problem that hinders the scalabilty of a program and it can be easily missed. It is very important to keep and eye out for the problem and recognize it quickly in parallel programming where performance is key. The two methods we explored, padding and thread local variable, are both reliable solution to false sharing but having a local variable to a thread is definitely better than padding as padding is more resource wasteful making it counter intuitive in parallel programming.