Professional Documents
Culture Documents
PROGRAMMING CONSIDERATIONS
2.1 Introduction
The use of digital computers imposes two main limitations: time, and
memory. In some applications, it is possible to trade time (speed) for
memory or vice versa. A programming technique is considered to be an
efficient one when both time and memory requirements cab be improved.
There are three factors that affect the performance of any programming
technique:
- computer type (Tianhe-2 (China), Titan (US), SUN, DC-Station,
PC,...etc.),
- programming language (FORTRAN, BASIC, C+, JAVA ...etc.), and
- application (power systems, VLSI, NASA, ... etc.).
Example (1):
a) Consider a 3 x 3 matrix with 4 nonzeros, then
no of entries using normal storage method is 9
no of entries using first storage method is 12
A major drawback of this method is the long access time it takes whenever
a new entry is inserted to the list or an entry is deleted from the list.
Example (2):
0 1 0
A 3 0 0
0 0 2
Counter STO IR IC
1 1.0 1 2
2 3.0 2 1
3 2.0 3 3
0 1 4
A 3 0 0
0 0 2
Counter STO IR IC
1 1.0 1 2
2 4.0 1 3
3 3.0 2 1
4 2.0 3 3
0 0 4
A 3 0 0
0 0 2
The deletion of this entry will push up all entries of STO, IR, and IC arrays
as
Counter STO IR IC
1 4.0 1 3
2 3.0 2 1
3 2.0 3 3
In this method, the nonzeros and the corresponding row (or column)
locations are stored in three parallel arrays:
- STO (for storing nonzero entries),
- IR (for storing corresponding row locations), or
- IC (for storing corresponding column locations), and
- NX (for telling how far down the list the next entry will be found).
It is also necessary to employ a forth array NFIRST which tells where a
certain row/column starts in the list. The size of NFIRST array is equal to
the number of rows (if row fashion is used) or the number of columns (if
column fashion is used).
Example (3)
a) Consider a 3 x 3 matrix with 4 nonzeros, then
no of entries using normal storage method is 9
no of entries using second storage method is 15
The nonzeros of this method can be stored in either row or column fashion.
A major advantage of this method is the high speed access time it takes
whenever a new entry is inserted to the list or an entry is to be deleted from
the list.
Example (4):
Consider the 3 x 3 sparse matrix of Example (2). The four arrays required
by this storage method, using the row fashion approach, are
In this case, the old value is replaced with the new value directly on the
STO array (using any of the two storage methods) without affecting the
other arrays.
1 0 0 1 0 0 0
0 2 0 0 0 0 2
0 0 3 0 0 0 0
0 0 0 4 4 0 0
A0 0 0 0 5 0 0
6 0 0 0 0 6 0
0 0 0 0 0 0 7
0 0 0 0 0 8 8
9 0 0 9
0 0 0
Assume now the addition of a new entry -5.0 (in row 5 and column 1).
Update will take place on the parallel arrays ONLY as follows:
Assume now the addition of a new row with two entries: -10 (in row 10 and
column 3), and 10 (in row 10 and column 6). Update will take place on all
arrays as follows:
In symmetry matrices, only the upper right (or lower left) triangle,
including the diagonal entries, is stored. If the upper right triangle entries
are stored, a lower left triangle position can be accessed by interchanging
the row column subscripts.
Example (6):
1 0 1 0
0 2 0 2
A
1 0 3 0
0 2 0 4
If the access to the entry -1.0 (in row 3 and column 1) needs to be accessed,
then the corresponding entry from the upper right triangle in row 1 and
column 3 is used (i.e., changing the subscript a31 to a13).