Dana Vrajitoru
B424/B524 Parallel and Distributed Programming

B424/B524 Homework 1

Due date: Thursday, September 3, 2020.

Ex. 1. Integral Computation

a. Download the following files:
Makefile
main.cc
integral.cc
integral.h

These files contain an implementation of the integral problem discussed in the lecture.

From the computer science Linux labs, you can copy these files directly with the command

cp /home/dvrajito/public_html/teach/b424/hw1 ./ -R

Compile these files with the command make and execute the program with the command integral or ./integral.

b. Modify the program to create a global float array of the size equal to the number of threads - declare it as a pointer and allocate it in the function input_data. Then make each thread store the sum they compute in the function compute_integral in the element of the array based on their index instead of adding it to the global integral.

Add another function called sum_integral with no parameters. This function should go through the global array of sums where the threads have written their results and add them all up, then store the result in the variable integral. Call this function from the main after synchronizing the threads and before outputting the results. The purpose of this is to avoid potential conflicts between the threads when modifying the global variable integral.

c. Test the program with several values and density of intervals to see how close it is to the correct value. Since the function is F(x) = 1/x, if a = 1 and b has some larger value, then the integral should be equal to ln(b). The integral from 0 to anything should be equal to minus infinity! In general, the integral from a to b is equal to ln(b) - ln(a). Add a few of these examples that you tried and what value you expected in the main inside the comment at the end of it.

Upload to Canvas

Upload the source files you have modified to Canvas, including the header file if more prototypes are added.