Introduction to Programming with OpenMP --------------------------------------- Practical Exercise 6 (Tasks) ---------------------------- Use similar commands to compile and run the program as in practical exercise 2. These exercises need minimal changes, but they are a bit tricky - the hints describe what to watch out for. Question 1 ---------- 1.1 The programs Programs/Carmichael.f90 and Programs/Carmichael.c search for Carmichael numbers (see Wikipedia), using a very crude and approximate approach. Number theorists will blench at their crudeness, so please ignore that. Take one of them and parallelise it using tasks. Divide the work of the loop in the main program between tasks, creating 90% as many of them as there are OpenMP threads. In procedure Search, perform the weak and strong tests in separate tasks, wait for them to complete. Also remember to synchronise the array update. Question 2 ---------- 2.1 The programs Programs/Quicksort.f90 and Programs/Quicksort.c contain a recursive quicksort for double precision floating-point. The algorithm is good, but there are better ways to code quicksort than by using recursion - it is written that way to make this exercise easier to code. Also, this is not the best sort for SMP performance. Take one of them and parallelise it using tasks. You should also not create a task if it has very little work to do - the specimen answer used a criterion of 1000 elements, but that was picked out of a hat and is not optimal. In the last lecture, you will learn a better way to do the last than by simply using if statements. Perceptive people will also note that it potentially generates a huge number of tasks - as commented, that will work if you use just the techniques taught in this course. Because of that, a very wide range of values of the criterion will give similar performance. For reasons mentioned in the course, Fortran users will need to use taskwait where C ones will not (and will use a dirty trick, instead). In both cases, this is because the OpenMP specification assumes a data model that is incompatible with both languages, and this is exposed when it comes to array arguments.