Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

ALGORITHM 575

Permutations for a Zero-Free Diagonal [F1 ]


I S. Duff
AERE Harwell, England

Key Words and Phrases unsymmetrlc permutahons, maximum transversal, maximum assignment,
block if)angular form, sparse matr)ces
CRCategor)es 5 0 , 5 1 , 5 3 , 5 4
Language FORTRAN

DESCR)PTION
T h e subroutine is evoked by the F O R T R A N s t a t e m e n t
CALL MC21A(N, ICN, LICN, IP, LENR, IPERM, NUMNZ, IW)
where the p a r a m e t e r s are described in the listing given here.
Given the p a t t e r n of nonzeros of a sparse matrix, this subroutine a t t e m p t s to
find a row p e r m u t a t i o n t h a t makes the matrix have no zeros on its diagonal. It is
possible t h a t the user m a y input a matrix for which there is no p e r m u t a t i o n t h a t
makes the diagonal zero-free. An example of this is
0)
In such instances the algorithm will produce a p e r m u t a t i o n t h a t will p u t as m a n y
nonzeros on the diagonal as possible (1 in the above example). This n u m b e r will
be o u t p u t in N U M N Z . T h e array I P E R M will still hold a p e r m u t a t i o n of the
integers 1, 2 . . . . , N, but in this case N - N U M N Z of the elements (IPERM(I), I)
will be zero.
It is envisaged that a c o m m o n use of the subroutine will be as the first part of
a two-stage process for the determination of the block triangular form of a sparse
matrix (see, for example, [1]). T h e second stage could be p e r f o r m e d by Harwell
subroutine MC13D [4], and the two stages are combined by using subroutine
MC23A in the Harwell package MA28 [2].
T h e subroutine is based on a d e p t h first search with look-ahead technique and
is described in detail in [3]. There, numerical results from using this subroutine,

Received 24 October 1978, revised 10 January 1980, accepted April 1980


Permission to copy without fee all or part of this material is granted provided that the copies are not
made or distributed for dLrect commercial advantage, the ACM copyright notice and the title of the
pubhcation and its date appear, and notice 18 given that copying is by permission of the Assomatlon
for Computing Machinery. To copy otherwise, or to republish, requires a fee and/or specific
permission.
Author's address Computer Science and Systems Divmlon, Building 8 9, AERE Harwell, Oxon.,
England
© 1981 ACM 0098-3500/81/0900-0387 $00 75
ACM Transactions on Mathematical Software, Vol 7, No 3, September 1981, Page 387-390
388 Algonthrns

which has been tested on a wide range of both structured and randomly generated
matrices, are also discussed.
This subroutine has been written in American National Standard FORTRAN.
Special comment cards have been included so that Harwell subroutine OE04A
can be used to make an IBM FORTRAN version that uses half-length integers
(INTEGER*2) for all the arrays except IP. This approximately halves the core
requirements at the cost of restricting the order of the system to 2 ~5 - 1.

REFERENCES
1 DUFF, LS On permutations to block triangular form. J Inst Math, AppL 19 (1977), 339-342.
2 DUFF, I.S MA28--A set of Fortran subroutines for sparse unsymmetrlc hnear equations. AERE
Rep R 8730, Her MaJesty's Stationery Office, London, 1977.
3 DUFF, I S On algorithms for obtaining a maximum transversal A C M Trans. Math Softw. 7, 3
(Sept. 1981), 315-330.
4. DUFF, I.S., AND REID, J K. Algorithm 529. Permutations to block triangular form A C M Trans.
Math Softw 4, 2 {June 1978), 189-192.

ALGORITHM
[A part of the listing is printed here. The complete listing is available from the
ACM Algorithms Distribution Service (see page 407 for order form).]

C S IS THE STANDARD FORTRAN VERSION SI/


C I IS THE IBM VERSION
C
SUDROUTINE MC~IA(N, ICN, LICN, IP, LENR, IPERM, NUMNZ, IW)
C
C DESCRIPTION OF PARAMETERS
C INPUT VARIABLES N, ICN, LICN, IP, LENR
C OUTPUT VARIABLES IPERM,NUMNZ
C
C N ORDER OF MATRIX
C ICN ARRAY CONTAININg THE COLUMN INDICES OF THE NON-ZEROS THOSE
C B E L O N g I N gTO A SINGLE ROW MUST BE CONTIGUOUS BUT THE ORDERINg
C OF COLUMN INDYCES WITHIN EACH ROW I S UNIMPORTANT AND WASTED
C SPACE BETWEEN ROWS IS PERMITTED
C LICN LENGTH OF ARRAY ICN
C IP IP(1), I=I,~, ~{, I S THE POSITION IN ARRAY ICN OF THE FIRST
C COLUMNINDEX OF A NON-ZERO IN ROW I
C LENR LENR(I) IS THE NUMBER OF NON-ZEROS IN ROW I , I = l , 2 , N
C IPERM CONTAINS PERMUTATION TO MAKE DIAGONAL HAVE THE SMALLEST
C NUMBEROF ZEROS ON I T ELEMENTS ( I P E R M ( I ) , I ) I = 1 , N ARE
C NON-ZEROAT THE END OF THE ALGORITHM UNLESS MATRIX
C IS STRUCTURALLY SINGULAR IN THIS CASE, ( I P E R M ( I ) , I ) WILL
C BE ZERO FOR N--NUMNZ ENTRIES
C NUMNZ NUMBER OF NON-ZEROS ON DIAGONAL OF PERMUTED MATRIX
C IW WORK ARRAY SEE LATER COMMENTS
C
INTEGER ] P ( N )
C I N T E g E R ~ 2I C N ( L I C N ) , L E N R ( N ) , IPERM(N), IW(N, 4) I/
INTEGER I C N ( L I C N ) , LENR(N), IPERM(N), IW(N, 4)
CALL MC~IB(N, ICN, LICN, IP, LENR, IPERM, NUMNZ, IW(1, 1 ) ,

ACM TransactlonsonMathematm~Softw~e, Vol7, No 3, September1981


Algorithms • 389

* IW(1,2), IW(1,3), IW(1,4))


RETURN
END
C/
SUBROUTINE MC21B(N, ICN, LICN, IP, L E N R , IPERM, NUMNZ, PR, ARP,
CV, OUI )
INTEGER I P ( N )

D I V I S I O N OF WORK ARRAY I S NOW DESCRIBED

C PR(1) I S THE PREVIOUS ROW TO I IN THE DEPTH F I R S I SEARCH


C A R P ( I ) IS ONE L E S S THAN THE NUMBER OF NON-ZEROS IN ROW I
C WHICH HAVE NOT BEEN SCANNED WHEN LOOKING FOR A CHEAP ASSIGNMENT
C C V ( I ) I S THE MOST RECENT ROW EXTENSION AT WHICH COLUMN I
C WAS V I S I T E D
C O U T ( I ) IS ONE L E S S THAN THE NUMBER OF NON-ZEROS IN ROW I
C WHICH HAVE NOT BEEN SCANNED DURINg ONE PASS THROUGH THE
MAIN LOOP

INTEGER*2 I C N ( L I C N ) , L E N R ( N ) , I P E R M ( N ) , P R ( N ) , C V ( N ) , I /
IARP(N),OUT(N) I/
INTEGER I C N ( L I C N ) , LENR(N), IPERM(N), PR(N), CV(N), ARP(N), OUI(N)

I N I T I A L I Z A T I O N OF ARRAYS
DO 10 I = I , N
ARP(1) = LENR(1) - I
CV(1) = 0
IPERM(1) = 0
I0 CONTINUE
NUMNZ = O

MAIN LOOP
EACH PASS ROUND THIS LOOP EITHER RESULTS IN A NEW ASSIGNMENT
C OR gIVES A ROW WITH NO ASSIGNMENT
DO 100 JORD=I,N
J = JORD
PR(J) = -!
DO 70 K=I,JORD
C LOOK FOR A CHEAP ASSIGNMENT
IN1 = ARP(J)
I F ( I N I LT O) gO TO 30
IN2 = I P ( J ) + LENR(J) - 1
I N I = IN2 -- I N I
DO 20 I I = I N I , IN2
I = ICN(II)
I F ( I P E R M ( 1 ) EQ 07 gO TO 80
20 CONTINUE
C NO CHEAP ASSIGNMENT IN ROW
ARP(J) . . . . I
C BEGIN LOOKING FOR ASSIGNMENT CHAIN STARTING WITH ROW d.
30 OUT(J) = LENR(J) - i
C INNER L O O P EXTENDSCHAIN BY ONE OR BACKTRACKS
DO 60 KK=I, JORD
INI = OUT(O)
IF (INI IT O) gO TO 50
IN~ = If~(J) + LENR(U) "- I
INI = ]N2 - INI
C FORWARD SCAN
DO 40 I I = INJ, IN2
I =- T C N ( I I )
IF ( C V ( I ) EQ JORD) gO TO 40
ACM Transactlo~on MathematmalSo~ware, Vol. 7, No. 3 ~ B ~ m b e r 1 9 8 1 .
390 Algorithms

COLUMN I HAS NOT YET BEEN ACCESSED DURING THIS PASS


Jl = J
O = IPERM(I)
C V ( 1 ) : OORD
PR(J) = Jl
O U F ( J I ) = IN2 - 11 I
GO TO 70
40 CONTINUE

BACKTRACKING SIEP
50 J = PR(J)
I F (O E ~ - 1 ) GO T O I00
6O CONTINUE

70 CONTINUE

NEW ASSIGNMENT IS MADE


80 IPERM(1) = J
A R P ( J ) = IN~ - I I - 1
NUMNZ = NUMNZ + I
DO 90 K = I , J O R D
J = PR(J)
I F ( J EQ - I ) GO TO I 0 0
I I = I P ( J ) + L E N R ( J ) -- O b { ( 4 ) - 2
I = ICN(II)
IPERM(1) = J
90 CONI'INUE

100 CONTINUE
C
C I F MATRIX I S STRUCTURALLY SINGULAR, WE NOW COMPLETE THE
C PERMUTATION IPERM
I F (NUMNZ EQ N) CO TO 150
DO 110 I=I,N
ARP(1) = 0
110 CONTINUE
K=O
DO 130 I = I , N
I F ( I P E R M ( I ) NE O) GO TO 120
K = K ~ I
OUT(K) : I
GO TO 130
120 J = IPERM(I)
AHP(J) = 1
130 CONTINUE
K=O
DO 140 I = I , N
I F ( A R P ( 1 ) NE O) GO TO 140
K=K+I
IOUTK = OUI(K)
IPERM(IOUIK) = I
140 CONTINUE
150 RETURN
END

ACM Transactions on Mathematmal Software, Vol 7, No 3, September 1981

You might also like