diff --git a/intro_lab/README.md b/intro_lab/README.md index a3644dbe6f847cb7a94e9a30db176c3c5d28d73e..8152b147d9bf925acac196c12fdedc5824dda10d 100644 --- a/intro_lab/README.md +++ b/intro_lab/README.md @@ -94,7 +94,7 @@ Questions: - How many different ways are there to change the number of threads? Which one are those? - How can you make the output ordered from thread 0 to thread 4? -## Exercise 2 - Creating Threads: calculate π in parallel using only pragma omp parallel +## Exercise 2 - Creating Threads: calculate π in parallel using pragma omp parallel _Concepts: Parallel, default data environment, runtime library calls_ @@ -213,15 +213,15 @@ Questions: - What would happen if you hadn’t used critical or atomic a shared variable? - How does the execution time change varying the number of threads? Is it what you expected? -- Do the two version of the codes differ in performance? If so, what do you - think it is the reason? +- Do the two versions of the code differ in performance? If so, what do you + think is the reason? ## Exercise 4 - Calculate π with a loop and a reduction _Concepts: worksharing, parallel loop, schedule, reduction_ Here we are going to implement a fourth parallel version of the pi.c / pi.f90 -code to calculate the value of π using omp for and reduction operations. +code to calculate the value of π using ``omp for`` and ``reduction`` operations. Instructions: Create a new parallel versions of the pi.c / pi.f90 program using the parallel construct ``#pragma omp for`` and ``reduction`` operation. Run the new @@ -231,7 +231,7 @@ the execution time for 1, 2, 4, 8, 16, 32 threads. Hints: -To change the schedule, you can either change the environment variable with +- To change the schedule, you can either change the environment variable with ``export OMP_SCHEDULE=type`` where ``type`` can be any of static, dynamic, guided or in the source code as ``omp parallel for schedule(type)``. @@ -239,5 +239,5 @@ Questions: - What is the scheduling that provides the best performance? What is the reason for that? - What is the fastest parallel implementation of pi.c / pi.f90 program? What is - the reason for being the fastest? What would be an even faster implementation + the reason for it being the fastest? What would be an even faster implementation of pi.c / pi.f90 program? diff --git a/intro_lab/hello.c b/intro_lab/hello.c index 04a6c145b2cfeb1dc4dd93f3751e2d991ac8bda8..9cdc610c2107b6911af1be807e5b10adc727d59d 100644 --- a/intro_lab/hello.c +++ b/intro_lab/hello.c @@ -1,7 +1,8 @@ #include <stdio.h> + int main () { - int ID = 0; // thread id + int thread_id = 0; - printf("Hello World from thread %d \n", ID); + printf("Hello World from thread %d \n", thread_id); } diff --git a/intro_lab/pi.c b/intro_lab/pi.c index b3a66fe4bc6e2cfbea800aee47c366862a4dfae0..8bcfe7e134930e0bd1179742b4cc6e6db16437af 100644 --- a/intro_lab/pi.c +++ b/intro_lab/pi.c @@ -3,7 +3,7 @@ This program will numerically compute the integral of 4/(1+x*x) - + from 0 to 1. The value of this integral is pi -- which is great since it gives us an easy way to check the answer. @@ -13,32 +13,29 @@ from the OpenMP runtime library History: Written by Tim Mattson, 11/99. */ + #include <stdio.h> #include <omp.h> + static long num_steps = 100000000; double step; + int main () { - int i; - double x, pi, sum = 0.0; - double start_time, run_time; - - step = 1.0/(double) num_steps; - - - start_time = omp_get_wtime(); - - for (i=1;i<= num_steps; i++){ - x = (i-0.5)*step; - sum = sum + 4.0/(1.0+x*x); - } - - pi = step * sum; - run_time = omp_get_wtime() - start_time; - printf("\n pi with %ld steps is %lf in %lf seconds\n ",num_steps,pi,run_time); -} - + int i; + double x, pi, sum = 0.0; + double start_time, run_time; + step = 1.0/(double) num_steps; + start_time = omp_get_wtime(); + for (i=1;i<= num_steps; i++){ + x = (i-0.5)*step; + sum = sum + 4.0/(1.0+x*x); + } + pi = step * sum; + run_time = omp_get_wtime() - start_time; + printf("\n pi with %ld steps is %lf in %lf seconds\n ",num_steps,pi,run_time); +}