Lab Report to: Homework 1 & 2 Matrix Multiplication
Gaussian Elimination
Harald Höller, 0104177
1 Matrix Multiplication
1.1 Ex. 1: Implementation - see code in Appendix 1
I implemented a very simple matrix multiplication algorithm assuming a purely symmetric problem with two N × N matrices A and B. The result of the multiplication
AB = C results in an N × N matrix as well of course.
There are three four-loops for this multiplication, since we have two free and one
summation index for filling a matrix with N 2 entries, resulting in N 3 operations.
I decided not to print the resulting matrix into the ouput file in order to test the
execution itself really, rather than the ouput effort.
1.2 Ex. 2: Execution on o3800
On the machine o3800.uibk.ac.at I executed four different problem sizes. All programs were compiled with gcc -o NXXX without flags and submitted using bsub -q
lva -o std_NXXX.out -e std_NXXX.err NXXX.
Outputs
N=333 (ID: 1152231)
Successfully completed.
Resource usage summary:
CPU time
:
2.65 sec.
Max Memory :
1 MB
Max Swap
:
5 MB
Max Processes :
1
N=666 (ID: 1152232)
1
Successfully completed.
Resource usage summary:
CPU time
:
21.34 sec.
Max Memory :
1 MB
Max Swap
:
5 MB
Max Processes :
1
N=999 (ID: 115229)
Successfully completed.
Resource usage summary:
CPU time
:
133.96 sec.
Max Memory :
12 MB
Max Swap
:
17 MB
Max Processes :
3
N=3333 (ID: 115228)
Exited with exit code 145.
Resource usage summary:
CPU time
:
601.69 sec.
Max Memory :
90 MB
Max Swap
:
133 MB
Max Processes :
3
Discussion
My first observation is, that the CPU time obviously does not increasy linearly which
is no surprise, since the problem is not linear in N .
I ran several unreasonably big jobs which all exited with code 145 after about 600sec
CPU time, as did e.g. the run with N = 3333. At that time I do not know, if there is
such a rigid restriction on the CPU time of one job, or if there occurs an other internal
problem with increasing sice, e.g. with memory. However, the meomory of 90MB and
Swap of 133MB do not really seem to be the cause of the exiting. The error files are
not revealing the problem either.
2 Gaussian Elimination
2.1 Ex. 1: Implementation - see code in Appendix 2
As starting point I used the code from matrix multiplication of course and changed
accordingly. Since the numbers arising became very large with bigger problems, I changed the definition types of my matrix and the vectors to double. Also in this case I
omitted printing the results in order to measure the computation time only.
The actual algorithms for bringing the matrix to triangular shape and then solving
the resulting transformed system has much less operations to do than the matrix
2
multiplication. In both cases, the loops do not cover the whole N 2 index-space, but
due to the triangular form of the problem, the order operations increases slower than
quadratic in N .
What would have to be implemented yet, is to test linear dependencies of rows,
which is very unlikely in when random numbers are used but not toally impossible. In
that case, the system would be under-determined and the algorithm would produce a
solution space in the dimnesion of the multiplicity of rows. Or in other words, the rank
of the matrix must be equal to the dimension of the problem, in order to produce one
unique solution as assumed in my program.
2.2 Ex. 2: Execution on o3800
On the machine o3800.uibk.ac.at I executed four different problem sizes. All programs were compiled with gcc -o gaussian_NXXX without flags and submitted using
bsub -q lva -o std_NXXX.out -e std_NXXX.err NXXX.
Outputs
N=333 (ID: 115476)
Successfully completed.
Resource usage summary:
CPU time
:
0.07 sec.
Max Memory :
1 MB
Max Swap
:
5 MB
Max Processes :
1
N=666 (ID: 115478)
Successfully completed.
Resource usage summary:
CPU time
:
0.14 sec.
Max Memory :
1 MB
Max Swap
:
5 MB
Max Processes :
1
N=999 (ID: 115479)
Successfully completed.
Resource usage summary:
CPU time
:
0.26 sec.
Max Memory :
1 MB
Max Swap
:
5 MB
Max Processes :
1
N=3333 (ID: 115477)
3
Successfully completed.
Resource usage summary:
CPU time
:
3.13 sec.
Max Memory :
1 MB
Max Swap
:
5 MB
Max Processes :
1
Discussion
As assumed, the time comsumption does rise slower than quadratic in problem size
(N ). Since not the whole index-space is used in the loops, this reduces the execution
time significantly compared to the matrix multiplication problem we discussed before.
Appendix 1
/*
/ Parallel + Optim SS11
/ hw1: Matrix Multiplication
/ last change: 2011/03/20
/ author: Harald Hoeller, 0104177
/ comment: my first program in C
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
// DECLARING VARIABLES
// A, B, C are matrices of N x N size
// -> N defines the size of the problem
const int N = 333;
float A[N][N], B[N][N], C[N][N];
// indices for matrix multiplication
int i, j, m;
// FILLING MATRICES WITH RANDOM REALS
srand ( time(NULL) );
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
// for easier debugging, the random numbers should
// be between 0 and 10
4
A[i][j]=(rand()%10);
B[i][j]=(rand()%10);
}
}
// MATRIX MULTIPLICATION
for(i=0;i<N;i++) {
for(j=0;j<N;j++) {
// set all initial values of resulting matrix C = 0
C[i][j]=0.;
for(m=0;m<N;m++) {
C[i][j]=A[i][m]*B[m][j]+C[i][j];
}
}
}
// TERMINATE PROGRAM
return 0;
}}
Appendix 2
/*
/ Parallel + Optim SS11
/ hw2: Gaussian Elimination
/ last change: 2011/03/21
/ author: Harald Hoeller, 0104177
/ comment: this is my second C program
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
// DECLARING VARIABLES
// A is matrix of N x N size, X, AX are vectors of dim=N
// -> N defines the size of the problem
// norm is a temporal variable for normalization
const int N = 3333;
double A[N][N+1], X[N], B[N], AX[N];
double norm;
// indices for elimination algorithm and summation
int i, j, m;
5
// FILLING MATRIX A AND VECTOR B WITH RANDOM REALS
srand ( time(NULL) );
for(i=0;i<N;i++) {
for(j=0;j<N+1;j++) {
//
//
//
//
for easier debugging, the random numbers should
be between 0 and 10 in general
speciality for matrix A: elements between 1 and 10
so that A[i][i] can never be 0!
A[i][j]=(rand()%10+1);
}
}
// TRANSFORMATION TO TRIANGULAR FORM
// first normalization of first row
norm=A[0][0];
for(i=0;i<N+1;i++) {
A[0][i]=A[0][i]/norm;
}
// Elimination Algorithm by replacing the i-th rows as follows
// [ has to be done for right hand side vector B as well of course // which is here the last column of the matrix A! ]
for(i=1;i<N;i++) {
for(j=i;j<N;j++) {
A[i][j]=A[i][j]-A[i-1][j]*A[i][i-1]/A[i-1][i-1];
}
}
// SOLUTION OF LINEAR SYSTEM
// Initialization of backward loop with last pivot row
X[N-1]=A[N-1][N]/A[N-1][N-1];
for(i=N-1;i>=0;i--) {
AX[N-1]=0.;
for(j=N-1;j>=i+1;j--) {
// evaluate aiding variable AX which is A.X
AX[i]=AX[i]+A[i][j]*X[j];
}
6
// evaluate solution vector X
X[i]=1/A[i][i]*(A[i][N]-AX[i]);
}
// TERMINATE PROGRAM
return 0;
}}
7
© Copyright 2026 Paperzz