Language: C
5) Although OpenMP makes most variables shared by default and visible to all threads, this is not always what is needed to provide proper and correct behavior of the parallel version of the code. The code segment below produces the sum of integers from 0 up to (COUNT-1). When run in sequential mode, it produces the correct answer. However, when parallelized incorrectly as shown below, non-deterministic errors can occur. The errors are non-deterministic because they do not always happen - they only occur under certain conditions the erroneous answers are different from run to run - and there is no apparent error or warning message, so it appears that everything is fine. Run the code sequentially first for the three values of COUNT to produce the correct answer. Then run it for the following values of NTHREADS and COUNT. Suggested values for NTHREADS include 2, 4, 8, 32, and 64. Suggested values for COUNT include 10, 100, and 1000. Create a table similar to the one below, making at least ten runs at each of the 15 data points. For each of the 15 data points, estimate the probability of an incorrect answer. If you do exactly ten runs at each data point, then this probability will be easy to report. (You can optionally do a larger number runs at each data point to get a better statistical average) Why are some answers incorrect? What is causing the non-deterministic errors? What is the probability of obtaining an incorrect answer as a function of NTHREADS and COUNT? Is there a trend in the probability and what intuitive explanation might there be for it? Optionally, repeat the experiment on a single/dual/quad core machine, if you have access to one. [25 pts] Percent of Incorrect Answers Generated by Flawed Parallel OpenMP Program COUNT NTHREADS=2 NTHREADS=4 NTHREADS=8 NTHREADS=32 NTHREADS=64 10 100 1000 #include <stdio.h> #include <omp.h> int main() { int i; int sum=0; omp_set_num_threads (NTHREADS); #pragma omp parallel for for (i=0; i<COUNT; i++) { sum = sum + i; printf ("Thread number: %d Iteration: %d Local Sum: omp_get_thread_num(), i, sum); } printf ("\n All Threads Done Final Global Sum: %d\n\n", } %d\n", sum);
Language: C
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am