Skip to content

Conversation

@siddharths2710
Copy link

Filled various lines of code with #pragmas while taking care of race conditions and thread-safety.

Example:

#pragma omp parallel for private(temp) reduction(+:sum)
for (int i = 0; i < ns; i++) {
temp = pow(15.0, 0.4 * (double)(-i-1)); //prevent false sharing and double indirect addressing overhead
freqPercentage[i] = temp;
sum += temp;
}

Here the variable temp is private to every thread created to run a portion of the for loop, and is computed in parallel with other iterations. To prevent racing, all the temp values generated by the threads are added one by one to the variable sum.

Filled various lines of code with #pragmas and added -fopenmp switch in Makefile
Check out the cumulative frequency array. Redundant computations are more parallelizable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant