You are on page 1of 7

Finite Elements in Analysis and Design 19 (1992) 47-53

47

Elsevier FINEL 234

A sparse matrix scheme for finite elements


M.D. Mikrenska and N.K. Petrov
Institute of Mechanics and Biomechanics, Bulgarian Academy of Sciences, Sofia, Bulgaria

Received July 1991 Revised November 1991 Abstract. This paper presents a scheme for compact representation of sparse matrices arising from finite element solutions of a large number of applied science problems. The proposed scheme is computationally advantageous if more than one degree of freedom of the nodal points is considered and if any iterative method for solving linear systems is used.

Introduction The application of the finite element method to a boundary value problem yields a sparse system of linear algebraic equations. Packed storage of these sparse matrices and solving the linear systems, often of very high order, is a major computational task. Many works deal with this problem (for example, [1-8]). The selection of the most appropriate storage scheme for a particular sparse system depends on its specific structure and the method by which it is solved. Pissanetzky [7] mentioned that the existing universal storage schemes minimize the storage requirements such that further minimization leads to a great increase of the computational time. The special structure of the finite element matrices can be exploited, however, to improve the storage requirement without any considerable increase of the computational time. The finite element graph can be used as the most natural and economic means for storage of the matrix structure. Such an appr.oach has been used in the application of the minimum degree algorithm [9] to finite element systems [3,5]. The schemes [3,5] concern direct solution of the corresponding linear system of equations. We direct our efforts to minimization of the storage requirements in the case that more than one variable is associated with mesh nodes and iterative methods are used to solve the linear system of equations. We shall propose an implementation of a compact sparse matrices representation that considerably reduces the additional storage, i.e. the storage required for informational arrays that allow us to restore the original non-compact form of the matrix. The p a p e r is organized as follows : a brief description of the C S M D F (Compressed Scheme for Multi-Degree of Freedom); an algorithm for matrix-vector multiplication corresponding to the presented storage scheme; a comparison between the proposed scheme and the uncompressed scheme developed by Chang [1] and Gustavson [6].

Description of the scheme Consider a sparse M by M matrix A arising from an application of the finite element method. Suppose that each mesh node has d degrees of freedom (d variables are associated
0168-874x/92/$05.00 1992 - Elsevier Science Publishers B.V. All rights reserved

48

M.D. Mikrenska, N.K. Petrov / A Sparse matrix scheme

with each node) and the matrix A is assembled in such a way that the first d rows (columns) of A correspond to node 1, the next d rows (columns) correspond to node 2 and so on, so that the last d rows (columns) of A correspond to node N. N is the total number of mesh nodes, M=dN. Nodes k and l are said to be neighbors if they belong to a common mesh element. We denote the following sets by N O N Z ( A ) and N O E P ( A ) : N O N Z ( A ) = {{i, j } l a i j 4= 0,} N O E P ( A ) = {{i, j } [ a i j 4= 0 and nodesk = [(i + d and l = [ ( j + d 1)/d]

1 ) / d ] are neighbors},

where [x] denotes the integer part of x. Element aij is said to be a "non-zero" element, if {i, j} ~ NOEP(A). The "non-zero" elements in A are stored in a one-dimensional array AE, situated row by row and inside the row in ascending order of position.
AE= (El, E 2 , . . . , E l , E21, E 2 , . . . , E 2, . . . , EIN, E N, . . . , E N ) . 1 2

The sub array Em stores the "non-zero" elements in the ith row of A, where i = d ( k - 1) k + m. The sub array E~ corresponds to the mth degree of freedom at node k. It might happen that some zero elements are stored in A, but as a rule their number is negligible with respect to the non-zero elements in A, i.e. the following relation is in force : I N O N Z ( A ) I -- I N O E P ( A ) I. Further on, we shall proceed having in mind the fact that the information about the neighbors of each node is sufficient to restore the original non-compact form of the matrix, i.e. it will be sufficient if only the finite element graph has been stored. We use two arrays NB and NNOD for this purpose: NB
= ( n 1, n 2 . . . . .

nN) ,

NNOD

1 2 2 N : ( s l , s'~ . . . . . s,,, s~, s 2 . . . . . s o 2 , . . . , s L s 2 . . . . . s N N)'

where n k is the total number of neighbors of node k, and Sl szk,.. ., s,k are the labels of the g, neighbors of node k arranged in increasing order. We introduce a new array NS: N s = (ll where
,

l~ , " - ,

l.', l~, l~, " " , I n 2 , " 2

~ ~) , l~, l 2 ~ " ' , l n N ,

l~' = (s~ - 1)d + 1.

(2)

We consider that the array NS is more suitable to be used than NNOD. It allows us to reduce the number of operations needed for the restoration of A. The corresponding column indices of the " n o n - z e r o " element stored in E~ are the following :

l~, l k + 1,. . ,l~ .+ d, .l~, 1~. + 1,..

,l k + d , . .

, lkk,

l knk+ 1, . . . , I knk"~- d.

It should be noted that the presented scheme is not adapted for arbitrary element retrieval because of the vast computational labor. CSMDF is computationally advantageous in case consecutive dealing by rows has been done.

Storage scheme for a symmetric matrix


Consider now a symmetric matrix A*. In this case the definition of n k and s~ is modified as follows :

M.D. Mikrenska, N.K.. Petrov / A Sparse matrix scheme

49

n k is the total n u m b e r of the k t h node neighbors with labels not smaller than k; s f is the label of the j t h neighbor of node k such that s~ >/k. The " n o n - z e r o " elements in A* on and above the main diagonal are stored row by row in array AES. The components of the array NSS corresponding to NS are calculated by eqn. (2) :
NBS = (nl, n 2..... nu).

M a t r i x - v e c t o r product

In using iterative methods for solving linear systems there is no fill-in during the computational process. That is why the proposed scheme can be successfully applied for solving linear systems with sparse matrix coefficients by iterative methods. We restrict ourselves to the calculation of the product (A, X ) as the fundamental operation in the use of iterative methods. X is an M-dimensional vector. The following FORTRAN program implements (A, X ) : Algorithm 1 input : ID - n u m b e r of nodal degrees of freedom (ID = d) N - total n u m b e r of nodal points NB, NS, A E - compact form of A X - M-dimensional array, M = I D * N output: A X - M-dimensional array, A X = (A, X) LBB = 0 I=0 II -- 0 I I D -- ID - 1 D O 20 K = 1, N LB = LBB + 1 LBB = LBB + NB(K) D O 20 I D D -- 1, ID U=0. I=I+l D O 10 N N = LB, LBB L = NS(NN) LL -- L + I I D D O 1 0 M D = L , LL II = II + 1 10 U = U + AE(II) * X(MD) 20 AX(I) = U A FORTRAN implementation of the algorithm for calculation of (A*, X), where A* is a symmetric matrix, now follows. To simplify the algorithm we suppose that the diagonal elements of A* have already been divided by 2.
Algorithm 2

input: output :

ID, N, X - the same as in Algorithm 1 NBS, NSS, A E S - compact form of A* A X - M-dimensional array, M = I D * N, A X = (A*, X) LBB = 0 I=0

50

M.D. Mikrenska, N.K. Petrov / A Sparse matrix scheme

10 20

II = 0 IID = ID - 1 D O 20 K = 1, N LB = LBB + 1 LBB = LBB + NB(K) D O 20 I D D = 1, ID U=0. I=I+l D O 10 NN = LB, LBB L = NS(NN) LL = L + I I D D O 10 MD = L, LL II = II + 1 U = U + AES(II)* X(MD)
AX0) = U

In order to compare Algorithm 1 with the algorithm for matrix-vector multiplication corresponding to the uncompressed scheme we give here the FORTRAN implementation presented in [7]. The non-zero elements in .4 are stored row. by row in array AN. IA and JA are M-dimensional arrays. I A ( I ) indicates the number of non-zero elements in the l t h row of A. JA contains the column indices of elements stored in AN. Algorithm 3 input : M - number of the matrix rows (columns) IA, JA, A N - compact form of A X - M-dimensional array output : A X - M-dimensional array, A X = (A, X) D O 20 I -- 1, M U=0 I A A = IA(I) lAB = IA(I + 1) - 1 D O 10 K = IAA, IAB 10 U = U + A N ( K ) , X(JA(K)) 20 AX(I) = U

Comparison between CSMDF and uncompressed scheme In this section we shall compare the proposed scheme with a more conventional storage scheme ("uncompressed"). To simplify the discussion we consider that the storage schemes are applied to a non-symmetric matrix. The conclusions of the comparison are also valid for symmetric matrices. We shall not consider here the modification of the uncompressed scheme named "compressed" [8]. We shall only note that the numerical experiments [4] show that the additional storage required in the compressed scheme application is at least two times smaller than in the uncompressed scheme application. When d variables are associated with each mesh node, the application of the compressed scheme does not allow us to reduce the additional storage more than d times. The primary storage (i.e. the storage required for the matrix elements) of the uncompressed and compressed schemes is the same. In reference to the computational time the uncompressed scheme is more effective than the compressed one. This is because the compressed scheme requires some extra references for the restoration of the non-compact matrix.

M.D. Mikrenska, N.K. Petrov / A Sparse matrix scheme

51

Table 1 The storage requirements of CSMDF and the uncompressed scheme Scheme Uncompressed SCMDF Primary storage INONZ(A) I INOEP(A)I Additional storage INONZ(A ) I + M

INOEP(A)I
de

M
d

Table 1 shows the storage required for the compact form of the matrix in CSMDF and in the uncompressed scheme. If we take into account eqn. (1), then it is obvious that the primary storage of both schemes is approximately the same, but the additional storage of CSMDF is considerably reduced compared to the additional storage required by the uncompressed scheme. The number of some basic operations in the implementation of Algorithms 1 and 3 is presented in Table 2. The operations concerning DO loops and the initial assignments are not included here. The integer and real operations are marked by the subscripts i and r, respectively. Some numerical experiments have been carried out to compare the computational time of the implementations considered above. A Personal Computer AT IBM was used. Table 3 presents the CPU time in seconds for a few test examples. According to these results we conclude that as far as the running time is concerned Algorithm 3 is better than Algorithm 1 for d = 2 or 3, but the opposite is true when d > 3. If we combine the information in Tables 2 and 3 we may conclude that Algorithm 1 is a better implementation when d > 3 as far as both storage requirements and running time are concerned. The implementation of Algorithm 1 for d = 2 or 3 is better than Algorithm 3 only as far as the storage requirements are concerned. However, if the storage requirements are supposed to be a more important parameter than the running time, the choice of Algorithm 1 is recommendable.

Conclusions

A new scheme for the compact storage of sparse matrices that arise from the finite element solution of multi-degree-of-freedom problems has been presented. The most important advantage of the proposed scheme is that the additional storage is several times less than in the available storage schemes. An implementation for matrix-vector multiplication as a basic operation in the iterative methods for solving linear systems is also presented. The real alternative, when iterative methods are used, is not to assemble the matrix A at all and to do the matrix-vector multiplication using the element matrices. In the present paper this alternative is not considered. The comparison done in the previous section allows us to draw the following conclusions: (1) for two or three nodal degrees of freedom, despite of some increase of the computational cost, CSMDF is preferable when very large systems have to be solved; (2) for more than three degrees of freedom the general superiority of CSMDF is indisputable. The developed technique is suitable for storage and solving of large systems with sparse matrix coefficients arising from finite element solution of conjugate problems such as thermoelastic, thermoplastic, piezoelectric, multi-component and others.

Table 2 A comparison of the basic operations in the implementations of Algorithms 1 and 3 a Multiplications INONZ(A)Ir INOEP(A)I r (5+5d)N 5 +(6+ ~)INOEP(A)[ References to scalar variables References to subscripted variables Assignments

Implementation

Additions

Algorithm 3

Algorithm 1

((2+d)N+(I+~)INOEP(A)[)~

(2dN)i + INONZ(A)[r 1

7dN+4INONZ(A)[

3dN+3INONZ(A)I
(1+ d)N 1 + ( 2 + ~)INOEP(A)I

4dN+
(2+3d)

INONZ(A)I

@
2 +(2+ ~)INOEP(A)I
e~

+ INOEP(A)I r

Subscripts i and r denote integer and real operations, respectively.

e~

M.D. Mikrenska, N.K. Petrov / A Sparse matrix scheme


Table 3 Comparison of the running times of the implementations of Algorithms 1 and 3 d 2 M 454 690 790 681 1035 1185 908 1236 1380 945 1135 1545 Running time (s) Algorithm 3 0.47 0.77 0.87 1.17 1.77 2.03 2.03 2.80 3.13 2.53 3.07 4.90 Algorithm 1 0.57 0.83 1.00 1.20 1.83 2.10 2.00 2.73 3.10 2.50 3.00 4.17

53

Acknowledgement
This research was supported by the Committee of Science under Grant No. 627.

References
[1] A. CHANG, "Applications of sparse matrix matrix methods in electrical power system analysis", in:Sparse Matrix Proceedings, IBM Rep. RA1 No. 11707, Yorktown Heights, N.Y., 1969. [2] P. D~ FEHCE, A. AGNIFIL~ and E. CLEMENT~N~,"Data structures for compact sparse matrices representation", Adv. Eng. Software 11 (2), pp. 75-83, 1989. [3] A. GEORGE and J. Liu, "A minimal storage implementation of the minimum degree algorithm", SIAMJ. Numer. Anal 17, pp. 282-299, 1980. [4] A. GEORGE and J. Liu, Computer Solution of Large Sparse Positive Definite Systems, Prentice-Hall, Englewood Cliffs, NJ, 1981. [5] A. GEORGE and D.R. MclNTYRE, "On the application of the minimum degree algorithm to finite element systems", SIAMJ. Numer. Anal. 15, pp. 90-112, 1978. [6] F.G. GUSTAVSON,"Some basic techniques for solving sparse systems of equations", in: Sparse Matrices and Their Applications, edited by Rose, D.J. and R.A. Willoughby, Plenum, New York, pp. 41-52, 1972. [7] S. PISSANETZKY,Sparse Matrix Technology, Academic Press, London, 1984. [8] A.H. SHERMAN,"On the efficient solution of sparse systems of linear and non-linear equations", Rep. No. 46, Dep. of Computer Science, Yale University, 1975. [9] W.F. TINNEY, "Comments on using sparsity techniques for power system problems", in:Sparse Matrix Proceedings, IBM Research Rept. RA/3-12-69, Yorktown Heights, NY, 1969.

You might also like