Changes

Jump to: navigation, search

DPS921/Group 8

217 bytes added, 04:08, 28 November 2018
Critical construct
struct MyStruct
{ float int value; //int padding[24];};
int main(int argc, char** argv){
MyStruct testArr[4];
float partial_val int value[4] = 0.0{};
int threads_used;
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++) {
partial_val #pragma omp critical testArr[i].value = testArr[i].value + 21;
}
#pragma omp critical testArr[i].value += partial_val;
}
 
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.
42
edits

Navigation menu