0% found this document useful (0 votes)
18 views4 pages

Lab 3

The document describes a programming assignment to implement a method for solving a system of linear equations using CUDA. The program takes a file with the coefficients, constants, and initial guesses as input and outputs the calculated values within a specified error margin. It outlines the steps to iteratively solve the equations using GPU parallelism and reports the performance compared to a sequential CPU version.

Uploaded by

at4786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views4 pages

Lab 3

The document describes a programming assignment to implement a method for solving a system of linear equations using CUDA. The program takes a file with the coefficients, constants, and initial guesses as input and outputs the calculated values within a specified error margin. It outlines the steps to iteratively solve the equations using GPU parallelism and reports the performance compared to a sequential CPU version.

Uploaded by

at4786
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Graphics Processing Units (GPUs): Architecture and Programming

Programming Assignment # 3

In this lab you will implement a method for solving a group of linear equations using
CUDA.

What will your program do?

Given a set of n equations with n unknowns (x1 to xn), your program will calculate the
values of x1 to xn within an error margin of e%.
The format of the file is:
 line1: #unknowns
 line2: absolute relative error
 line 3: Initial values for each unknown
 line 4 till end: the coefficients for each equation. Each equation on a line. On the
same line and after all the coefficients you will find the constant of the
corresponding equation.
For example, if we want to solve a system of 3 linear equations, you can have a file like
this one:

3
0.01
234
5136
3728
3696

The above file corresponds to the following set of equations:

5X1 + X2 + 3X3 = 6
3X1 + 7X2 + 2X3 = 8
3X1 + 6X2 + 9X3 = 6

The third line in the file tells us that the initial values for X 1 is 2, for X2 is 3, and for X3 is
4. Those values may not be the solution, or are very far from the solution that must be
within 1% of the real values (as given by the 0.01 in line 2).
How will your program do that?

We start with a set of n equations and n unknowns, like this:

You are given all aij and b1 to bn. You need to calculate all Xs.

Here are the steps:

1. Rewrite each equation such has the left-hand-side is one of the unknowns.

Note: The Cs above refer to the constants, which are the b 1 to bn.

In general: n
ci   aij x j
j 1
j i
xi  , i  1,2,  , n.
aii

2. Remember that you were given some initial values for the Xs in the input file.
The absolute relative error is:
new
x x
old
 a i  i
new
i
 100
i x
Therefore, our goal is to reduce absolute relative error for each unknown to make
it less or equal to relative error given in the input file (2nd line of the intput file).
Note: You need to multiply the error given in the file by 100 to match it with the
above equation, or to not multiply the above equation by 100.
3. Substitute the initial values in the equation of each X i to get new value for Xi.
Now we have a new set of Xs.
Important: Let’s say you calculated a new X1. When you calculate X2 DO NOT
use the new value for X1 but the old value, in the current iteration. In the
following iteration, use all new values.

4. Calculate the absolute relative errors for each X.

5. If all errors are equal or less the given number (2nd line in the file) then you are
done.

6. Otherwise go back to step 3 with the set of new Xs as X old.

What is the input to your program?

The input to your program is a text file named A.txt where A can be any name. We
already discussed the file format.

So, if your program is called solve then I must be able to run your program as

./solve inputfile.txt

What is the output of your program?

Your program must output to a text file with the name x.sol, where x is the number of
unknowns. For the above example, your program must generate a file 3.sol that contains:
2
3
4
Where 2 correspond to the value of X1, 3 corresponds to X2, and 4 corresponds to X3, ... .
That is, each value on a line.

The number of iterations is printed on the screen:


total number of iterations: 5

What do I do after I finish my program?

We have provided you with a reference program solve so you can check the correctness
of your results. We will test your submission against this reference (for correctness of
solution not the number of iterations). We will compare till the third digit after the
floating point. Before you use solve it do the following:
 sftp it to crunchy machine
 execute: chmod 777 ./solve
 type: ./solve filename
 The output will be a file A.sol where A is the number of unknowns.
We also provided you with a file ./gengs that generates a test file. You use it as follows:
 sftp it to a crunchy machine
 execute: chmod 777 ./gengs
 type: ./gengs A e where A is the number of variables and e is the error.
 The program will generate a file A.txt in the format shown at the beginning of this
document.

The report
Draw a br-graph: x-axis is the number of unknowns and y-axis is speedup, or
slowdown, over the sequential version (the executable provided ./solve). Use number
of unknowns: 10, 100, 1000, 10000, and 100000.
Below that graph show a table like this:

Number of Unknowns Best configuration


(# blocks, #threads per block)
10
100
1000
10000
100000

Not that this means for each problem size, you need to do some experiments to find the
configuration that gives the best speedup.

What to submit:

 The source code solve.cu


 A report that contains the graph and the table.

Put all the above in a zip file named by your netID.zip and upload them to Brightspace.

You might also like