Lab 3. Simple
Computation with Arrays.
This lab is to develop some parallel programs for the main operations on arrays e.g. sum, product, maximum, minimum. The program will require you to exercise with the rule “scatter, process, reduce/gather”.
Task 0 – Recall Working with Pointers (addresses).
1. General rules in working with pointers:
1. int var; &var is the pointer
2. int * p; *p is the value stored at p.
2. Allocate dynamically an array with n elements: a = (int *) calloc(n, sizeof(int));.
1. a is the pointer where the array elements start
2. a + i is the pointer of the element a[i]
3. a+i can also be considered array but with n-i elements.
Task 1 – Sum, Product, Max, Min.
3. Get organised. (create the folder lab4 + a subfolder array). Start from the file sum.c.
4. Add some lines of code to find the overall execution time.
5. Modify the program sum.c to calculate the product, maximum, minimum. More processing plus reduce.
6. Observe whether the execution times decrease.
7. Make some MPI functions to calculate these elements.
Task 2 – Simple Sort.
1. Start from the file sort.c which contains some functions you might like to use.
2. Scatter array to scattered_array..
3. Sort scattered_array.
4. Gather scattered_array to array.
5. If processor 0 then merge the small chucks of array.
1. Strategy 1 (Linear Complexity): for size -1 times do merge the current chunk with the previous elements.
2. Strategy 2 (Log Complexity): for log(size) times do merge always consecutive chunks.
6. Observe the reduction of the execution times and speedup.
7. Table the execution times and check the Amdalh’s law as the program has 2 serial parts.
Remarks: Solutions of Task1 and Task2.