Exercises
Overview
Teaching: 0 min
Exercises: 60 minQuestions
Objectives
Exercise 1:
Write a Fortran program that writes “Hello OpenMP”. Compile and execute.
Convert the previous Fortran program in multithreaded with a
paralell
directiveLoad the omp_lib module and print also the thread number using the function
omp_get_thread_num()
andomp_get_num_threads()
Store the values for the number of threads and thread ID on variables before printing
What is the difference bettween making those variables public or private.
Exercise 2:
Write a Fortran code that computes the integral of a function f(x)=log(pix)sin(pi*x)**2 + x in the range [1,10]
Use rectangles to approximate the integral and use an OpenMP parallel loop. (*) An alternative could be using trapezoids instead of triangles.
Compare the performance of the serial code compared with the parallel version.
Use the function omp_get_wtime() to get the time spent on the loop. The function returns a real and can be used before and after the loop.
Exercise 3:
Use the following product to approximate pi
Use the reduction for a product to an approximation of pi
How many terms are needed to get 4 good digits?
Key Points