-
Notifications
You must be signed in to change notification settings - Fork 2
/
sparseL.f
executable file
·2644 lines (2604 loc) · 77.4 KB
/
sparseL.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
christen this file sparseL.f
cut here >>>>>>>>>>>>>>>>>
c***************** sparse matrix routines for manipulating L *******************
c ***************************************************
c Basis matrix routines for bqpd with sparse matrices
c ***************************************************
c These routines form and update L-Implicit-U factors LPB=U of a matrix B
c whose columns are the normal vectors of the active constraints. In this
c method only the unit lower triangular matrix L and the diagonal of U (in
c addition to the row permutation P) is stored. B is represented in block form
c | I A_2 | where the last m1 columns (A_2 and A_1) come from the
c | 0 A_1 | general constraint normals (columns of the matrix A in bqpd)
c and the remaining unit columns come from simple bounds. The matrix A must be
c specified in sparse format and the user is referred to the file sparseA.f.
c The data structure used for L is that of a profile or skyline scheme, in
c which the nontrivial rows of L are stored as dense row spikes. The use of
c a Tarjan+spk1 ordering algorithm to control the length of these spikes has
c proved quite effective. The factors are updated by a variant of the
c Fletcher-Matthews method, which has proved very reliable in practice.
c However the B matrix is re-factored every 30 updates to control growth in
c the total spike length.
c Workspace
c *********
c The user needs to supply storage for the rows of L, although the amount
c required is unknown a-priori.
c sparse.f requires
c 5*n+nprof locations of real workspace, and
c 9*n+m locations of integer workspace
c where nprof is the space required for storing the row spikes of the L matrix.
c Storage for sparseL.f is situated at the end of the workspace arrays ws
c and lws in bqpd.
c Allow as much space for nprof as you can afford: the routine will report if
c there is not enough. So far 10^6 locations has proved adequate for problems
c of up to 5000 variables.
c In addition the current version of bqpd.f requires
c kmax*(kmax+9)/2+2*n+m locations of real workspace in ws
c kmax locations of integer workspace in lws
c The user is also allowed to reserve storage in ws and lws, for use in the
c user-supplied routine gdotx. This storage is situated at the start of the
c arrays ws and lws. The user specifies the amount required by
c setting the parameters kk and ll in the common block
c common/wsc/kk,ll,kkk,lll,mxws,mxlws
c The user MUST also set mxws and mxlws to be (respectively) the total amount
c of real and integer workspace for the arrays ws and lws.
c Other information
c *****************
c The methodology behind the L-Implicit-U factors and the row spike storage
c scheme for L is described in the references
c Fletcher R., Dense Factors of Sparse Matrices, in "Approximation Theory
c and Optimization. Tributes to M.J.D. Powell", (M.D. Buhmann and A. Iserles,
c eds), Cambridge University Press (1997), pp. 145-166.
c and
c Fletcher R., Block Triangular Orderings and Factors for Sparse Matrices
c in LP, in "Numerical analysis 1997" (D.F. Griffiths, D.J. Higham and
c G.A. Watson, eds.), Pitman Research Notes in Mathematics 380, (1998),
c Longman, Harlow, pp. 91-110.
c The file contains routines for solving systems with B or its transpose
c which might be of use in association with bqpd. These routines are
c documented below.
c Steepest edge coefficients e(i) are also updated in these routines
c Copyright, University of Dundee (R.Fletcher), January 1998
c Current version dated 16/04/02
subroutine start_up(n,nm,nmi,a,la,nk,e,ls,aa,ll,mode,ifail)
implicit double precision (a-h,r-z), integer (i-q)
dimension a(*),la(0:*),e(*),ls(*),aa(*),ll(*)
common/noutc/nout
common/wsc/kk,ll_,kkk,lll,mxws,mxlws
common/epsc/eps,tol,emin
common/sparsec/ns,ns1,nt,nt1,nu,nu1,nx,nx1,np,np1,nprof,
* lc,lc1,li,li1,lm,lm1,lp,lp1,lq,lq1,lr,lr1,ls_,ls1,lt,lt1
common/factorc/m1,m2,mp,mq,lastr,irow
common/refactorc/nup,nfreq
nfreq=min(30,nfreq)
nup=0
ns=kk+kkk+5*n
nt=ll_+lll+8*n+nmi
nprof=mxws-ns
if(nprof.le.0.or.nt.gt.mxlws)then
write(nout,*)'not enough real (ws) or integer (lws) workspace'
write(nout,*)'you give values for mxws and mxlws as',mxws,mxlws
write(nout,*)'minimum values for mxws and mxlws are',ns,nt
ifail=7
return
endif
3 format(A/(20I5))
4 format(A/(5E15.7))
c set storage map for sparse factors
ns=n
ns1=ns+1
nt=ns+n
nt1=nt+1
nu=nt+n
nu1=nu+1
nx=nu+n
nx1=nx+1
np=nx+n
np1=np+1
lc=n
lc1=lc+1
li=lc+n
li1=li+1
lm=li+nmi
lm1=lm+1
lp=lm+n
lp1=lp+1
lq=lp+n
lq1=lq+1
lr=lq+n
lr1=lr+1
ls_=lr+n
ls1=ls_+1
lt=ls_+n
lt1=lt+1
m=nm-n
mp=-1
mq=-1
c write(nout,*)'ls',(ls(ij),ij=1,nk)
if(mode.ge.3)then
call re_order(n,nm,a,la(1),la(la(0)),ll,ll(lc1),ll(li1),
* ll(lm1),ll(lp1),ll(lq1),ll(lr1),ll(ls1),ll(lt1),aa(np1),
* nprof,ifail)
if(ifail.ge.1)then
c write(nout,*)'failure in re_order (1)'
if(ifail.eq.7)return
mode=2
goto1
endif
call re_factor(n,nm,a,la,ll,ll(lc1),ll(li1),
* ll(lm1),ll(lp1),ll(lq1),ll(lr1),ll(ls1),ll(lt1),aa(np1),
* nprof,aa,ifail)
if(ifail.eq.7)return
call check_L(n,aa,ll(lp1),ifail)
if(ifail.eq.1)then
mode=2
goto1
endif
if(nk.eq.n)return
c reset ls from e
do j=1,nk
i=-ls(j)
if(i.gt.0)e(i)=-e(i)
enddo
j=0
nk=nmi
do i=1,nmi
if(e(i).ne.0.D0)then
j=j+1
if(e(i).gt.0.D0)then
ls(j)=i
else
ls(j)=-i
e(i)=-e(i)
endif
else
ls(nk)=i
nk=nk-1
endif
enddo
if(j.ne.n)then
write(nout,*)'malfunction in reset sequence in start_up'
stop
endif
return
endif
1 continue
if(emin.eq.0.D0)then
c set a lower bound on e(i): setting emin=0.D0 will force emin to be recalculated: do this only if mode<3
emin=1.D0
do i=1,nmi-n
emin=max(emin,ailen(n,a,la,i))
enddo
emin=1.D0/emin
endif
do i=1,n
ll(i)=i
ll(li+i)=i
e(i)=1.D0
enddo
do i=n+1,nmi
ll(li+i)=0
e(i)=0.D0
enddo
nu_=0
if(mode.ne.0)then
c shift designated bounds to end and order the resulting rows and columns
do j=1,nk
i=abs(ls(j))
if(i.le.n)then
nn=n-nu_
nu_=nu_+1
call iexch(ls(nu_),ls(j))
ii=ll(li+i)
ll(ii)=ll(nn)
ll(li+ll(ii))=ii
ll(nn)=i
ll(li+i)=nn
endif
enddo
call order(n,nu_,nk,la,ll,ls,ll(li1),ll(lp1),ll(lq1),ll(lr1),
* aa(np1),nprof,ifail)
if(ifail.gt.0)return
endif
call factor(n,nmi,nu_,nk,a,la,e,ls,aa(ns1),aa(nt1),aa(nu1),
* aa(nx1),ll,ll(lc1),ll(li1),ll(lm1),ll(lp1),ll(lq1),ll(lr1),
* ll(ls1),aa(np1),nprof,aa,ifail)
if(ifail.gt.0)return
c write(nout,*)'steepest edge coefficients',(e(ij),ij=1,nm)
c emax=0.D0
c do i=1,nm
c if(e(i).gt.0.D0)then
c call eptsol(n,a,la,i,a,aa(ns1),aa(nt1),aa,aa(np1),
c * ll,ll(lc1),ll(li1),ll(lp1),ll(lq1))
c ei=xlen(0.D0,aa(ns1),n)
c ei=sqrt(scpr(0.D0,aa(ns1),aa(ns1),n))
c emax=max(emax,abs(ei-e(i)))
c endif
c enddo
c if(emax.ge.tol)
c * write(nout,*)'error in steepest edge coefficients =',emax
return
end
subroutine refactor(n,nm,a,la,aa,ll,ifail)
implicit double precision (a-h,o-z)
dimension a(*),la(0:*),aa(*),ll(*)
common/sparsec/ns,ns1,nt,nt1,nu,nu1,nx,nx1,np,np1,nprof,
* lc,lc1,li,li1,lm,lm1,lp,lp1,lq,lq1,lr,lr1,ls,ls1,lt,lt1
common/factorc/m1,m2,mp,mq,lastr,irow
common/noutc/nout
c write(nout,*)'refactor'
m=nm-n
call re_order(n,nm,a,la(1),la(la(0)),ll,ll(lc1),ll(li1),
* ll(lm1),ll(lp1),ll(lq1),ll(lr1),ll(ls1),ll(lt1),aa(np1),
* nprof,ifail)
if(ifail.ge.1)then
c write(nout,*)'failure in re_order (2)'
return
endif
call re_factor(n,nm,a,la,ll,ll(lc1),ll(li1),ll(lm1),
* ll(lp1),ll(lq1),ll(lr1),ll(ls1),ll(lt1),aa(np1),
* nprof,aa,ifail)
if(ifail.eq.7)return
call check_L(n,aa,ll(lp1),ifail)
return
end
subroutine pivot(p,q,n,nm,a,la,e,aa,ll,ifail,info)
implicit double precision (a-h,r-z), integer (i-q)
dimension a(*),la(0:*),e(*),aa(*),ll(*),info(*)
common/noutc/nout
common/iprintc/iprint
common/sparsec/ns,ns1,nt,nt1,nu,nu1,nx,nx1,np,np1,nprof,
* lc,lc1,li,li1,lm,lm1,lp,lp1,lq,lq1,lr,lr1,ls,ls1,lt,lt1
common/factorc/m1,m2,mp,mq,lastr,irow
common/mxm1c/mxm1
common/refactorc/nup,nfreq
common/epsc/eps,tol,emin
c write(nout,*)'pivot: p,q =',p,q
ifail=0
if(p.ne.mp)then
call eptsol(n,a,la,p,a,aa(ns1),aa(nt1),aa,aa(np1),
* ll,ll(lc1),ll(li1),ll(lp1),ll(lq1))
if(p.gt.n)then
e(p)=xlen(0.D0,aa(ns1+m2),m1)
else
e(p)=xlen(1.D0,aa(ns1+m2),m1)
endif
epp=e(p)
mp=p
endif
if(q.ne.mq)then
call aqsol(n,a,la,q,a,aa(nt1),aa(nx1),aa,aa(np1),
* ll,ll(lc1),ll(li1),ll(lp1),ll(lq1))
mq=q
endif
c update steepest edge coefficients
tp=aa(nt+ll(li+p))
if(tp.eq.0.D0)tp=eps
ep=e(p)
eq=2.D0/ep
c do i=1,m2-1
c aa(nu+i)=0.D0
c enddo
c do i=m2,n
do i=1,n
aa(nu+i)=eq*aa(ns+i)
enddo
call aqsol(n,a,la,-1,a,aa(nu1),aa(nx1),aa,aa(np1),
* ll,ll(lc1),ll(li1),ll(lp1),ll(lq1))
c write(nout,*)'row perm',(ll(ij),ij=1,n)
c write(nout,*)'column perm',(ll(lc+ij),ij=m2+1,n)
c write(nout,*)'s =',(aa(ns+ij),ij=1,n)
c write(nout,*)'t =',(aa(nt+ij),ij=1,n)
c write(nout,*)'u =',(aa(nu+ij),ij=1,n)
e(p)=0.D0
eq=ep/tp
do i=1,nm
if(e(i).gt.0.D0)then
j=ll(li+i)
ei=e(i)
wi=aa(nt+j)*eq
awi=abs(wi)
if(ei.ge.awi)then
wi=wi/ei
e(i)=max(emin,ei*sqrt(max(0.D0,1.D0+wi*(wi-aa(nu+j)/ei))))
else
wi=ei/wi
e(i)=max(emin,awi*sqrt(max(0.D0,1.D0+wi*(wi-aa(nu+j)/ei))))
endif
endif
enddo
e(q)=max(emin,abs(eq))
info(1)=info(1)+1
if(nup.ge.nfreq)then
c if(nup.ge.30)then
c refactorize L
ip=ll(li+p)
if(p.gt.n)then
m2=m2+1
qq=ll(lc+m2)
ll(lc+ip)=qq
ll(li+qq)=ip
ll(li+p)=0
else
ll(ip)=ll(m2)
ll(li+ll(ip))=ip
ll(m2)=p
ll(li+p)=m2
endif
if(q.gt.n)then
ll(lc+m2)=q
ll(li+q)=m2
m2=m2-1
else
iq=ll(li+q)
ll(iq)=ll(m2)
ll(li+ll(iq))=iq
ll(m2)=q
ll(li+q)=m2
endif
m1=n-m2
call re_order(n,nm,a,la(1),la(la(0)),ll,ll(lc1),ll(li1),
* ll(lm1),ll(lp1),ll(lq1),ll(lr1),ll(ls1),ll(lt1),aa(np1),
* nprof,ifail)
if(ifail.ge.1)then
c write(nout,*)'failure in re_order (3)'
return
endif
call re_factor(n,nm,a,la,ll,ll(lc1),ll(li1),
* ll(lm1),ll(lp1),ll(lq1),ll(lr1),ll(ls1),ll(lt1),aa(np1),
* nprof,aa,ifail)
else
c update L
call update_L(p,q,n,nm,a,la,ll,ll(lc1),ll(li1),ll(lm1),ll(lp1),
* ll(lq1),ll(lr1),ll(ls1),aa(np1),nprof,aa,aa(ns1),ifail)
endif
if(ifail.eq.7)return
mp=-1
mq=-1
call check_L(n,aa,ll(lp1),ifail)
c write(nout,*)'steepest edge coefficients',(e(ij),ij=1,nm)
c emax=0.D0
c do i=1,nm
c if(e(i).gt.0.D0)then
c call eptsol(n,a,la,i,a,aa(ns1),aa(nt1),aa,aa(np1),
c * ll,ll(lc1),ll(li1),ll(lp1),ll(lq1))
c ei=xlen(0.D0,aa(ns1),n)
c ei=sqrt(scpr(0.D0,aa(ns1),aa(ns1),n))
c emax=max(emax,abs(ei-e(i)))
c endif
c enddo
c if(emax.ge.tol)
c * write(nout,*)'error in steepest edge coefficients =',emax
return
end
subroutine fbsub(n,jmin,jmax,a,la,q,b,x,ls,aa,ll,save)
implicit double precision (a-h,r-z), integer (i-q)
logical save
dimension a(*),la(*),b(*),x(*),ls(*),aa(*),ll(*)
c solves a system B.x=b
c Parameter list
c **************
c n number of variables (as for bqpd)
c jmin,jmax (see description of ls below)
c a,la specification of QP problem data (as for bqpd)
c q an integer which, if in the range 1:n+m, specifies that the rhs vector
c b is to be column q of the matrix A of general constraint normals.
c In this case the parameter b is not referenced by fbsub.
c If q=0 then b is taken as the vector given in the parameter b.
c b(n) must be set to the r.h.s. vector b (but only if q=0)
c x(n+m) contains the required part of the solution x, set according to the
c index number of that component (in the range 1:n for a simple bound and
c n+1:n+m for a general constraint)
c ls(*) an index vector, listing the components of x that are required.
c Only the absolute value of the elements of ls are used (this allows
c the possibility of using of the contents of the ls parameter of bqpd).
c Elements of x in the range abs(ls(j)), j=jmin:jmax are set by fbsub.
c These contortions allow bqpd to be independent of the basis matrix code.
c aa(*) real storage used by the basis matrix code (supply the vector
c ws(lu1) with ws as in the call of bqpd and lu1 as in common/bqpdc/...)
c ll(*) integer storage used by the basis matrix code (supply the vector
c lws(ll1) with lws as in the call of bqpd and ll1 as in common/bqpdc/...)
c save indicates if fbsub is to save its copy of the solution for possible
c future use. We suggest that the user only sets save = .false.
common/noutc/nout
common/sparsec/ns,ns1,nt,nt1,nu,nu1,nx,nx1,np,np1,nprof,
* lc,lc1,li,li1,lm,lm1,lp,lp1,lq,lq1,lr,lr1,ls_,ls1,lt,lt1
common/factorc/m1,m2,mp,mq,lastr,irow
c write(nout,*)'fbsub q =',q
if(save)then
if(q.ne.mq)then
call aqsol(n,a,la,q,b,aa(nt1),aa(nx1),aa,aa(np1),
* ll,ll(lc1),ll(li1),ll(lp1),ll(lq1))
mq=q
endif
do j=jmin,jmax
i=abs(ls(j))
x(i)=aa(nt+ll(li+i))
enddo
else
call aqsol(n,a,la,q,b,aa(nu1),aa(nx1),aa,aa(np1),
* ll,ll(lc1),ll(li1),ll(lp1),ll(lq1))
do j=jmin,jmax
i=abs(ls(j))
x(i)=aa(nu+ll(li+i))
enddo
endif
return
end
subroutine ztg(n,k,rg,lv,aa,ll)
implicit double precision (a-h,r-z), integer (i-q)
dimension rg(*),lv(*),aa(*),ll(*)
common/sparsec/ns,ns1,nt,nt1,nu,nu1,nx,nx1,np,np1,nprof,
* lc,lc1,li,li1,lm,lm1,lp,lp1,lq,lq1,lr,lr1,ls_,ls1,lt,lt1
c print *,'aa =',(aa(nu+i),i=1,18)
do j=1,k
rg(j)=aa(nu+ll(li+lv(j)))
enddo
return
end
subroutine tfbsub(n,a,la,p,b,x,aa,ll,ep,save)
implicit double precision (a-h,r-z), integer (i-q)
logical save
dimension a(*),la(*),b(*),x(*),aa(*),ll(*)
c solves a system Bt.x=b
c Parameter list
c **************
c n number of variables (as for bqpd)
c a,la specification of QP problem data (as for bqpd)
c p an integer which, if in the range 1:n+m, specifies that the rhs vector
c b is a unit vector appropriate to the position of p in the current
c ordering. In this case b is not referenced by tfbsub.
c b(n+m) If p=0, this must be set to the r.h.s. vector b. Only the components
c of b need be set, according to the index number of each component (in
c the range 1:n for a simple bound and n+1:n+m for a general constraint)
c x(n) contains the solution x (in natural ordering)
c aa(*) real storage used by the basis matrix code (supply the vector
c ws(lu1) with ws as in the call of bqpd and lu1 as in common/bqpdc/...)
c ll(*) integer storage used by the basis matrix code (supply the vector
c lws(ll1) with lws as in the call of bqpd and ll1 as in common/bqpdc/...)
c ep if p.ne.0 and save is true, ep contains the l_2 length of x on exit
c save indicates if tfbsub is to save its copy of the solution for possible
c future use. We suggest that the user only sets save = .false.
common/noutc/nout
common/sparsec/ns,ns1,nt,nt1,nu,nu1,nx,nx1,np,np1,nprof,
* lc,lc1,li,li1,lm,lm1,lp,lp1,lq,lq1,lr,lr1,ls,ls1,lt,lt1
common/factorc/m1,m2,mp,mq,lastr,irow
c write(nout,*)'tfbsub p =',p
if(save)then
if(p.ne.mp)then
call eptsol(n,a,la,p,b,aa(ns1),aa(nt1),aa,aa(np1),
* ll,ll(lc1),ll(li1),ll(lp1),ll(lq1))
mp=p
endif
do i=1,n
x(ll(i))=aa(ns+i)
enddo
if(p.gt.n)then
ep=xlen(0.D0,aa(ns1+m2),m1)
elseif(p.gt.0)then
ep=xlen(1.D0,aa(ns1+m2),m1)
endif
else
call eptsol(n,a,la,p,b,aa(nu1),aa(nt1),aa,aa(np1),
* ll,ll(lc1),ll(li1),ll(lp1),ll(lq1))
do i=1,n
x(ll(i))=aa(nu+i)
enddo
endif
c write(nout,*)'x =',(x(i),i=1,n)
return
end
subroutine newg
common/factorc/m1,m2,mp,mq,lastr,irow
mq=-1
return
end
c******** The following routines are internal to sparseL.f **************
subroutine check_L(n,d,p,ifail)
implicit double precision (a-h,r-z), integer (i-q)
dimension d(*),p(*)
common/noutc/nout
common/factorc/m1,nu,mp,mq,lastr,irow
common/epsc/eps,tol,emin
c write(nout,*)'check_L'
ifail=1
c dmin=1.D37
do k=nu+1,n
c dmin=min(dmin,abs(d(k)))
if(abs(d(k)).le.tol)return
enddo
c write(nout,*)'dmin =',dmin
c len=0
c do i=1,n
c len=len+p(i)
c enddo
c write(nout,*)m1*(m1+1)/2,len+m1
c write(nout,*)'m1 =',m1,' file length =',len,' total =',len+m1
ifail=0
return
end
subroutine aqsol(n,a,la,q,b,tn,xn,d,ws,lr,lc,li,pp,qq)
implicit double precision (a-h,r-z), integer (i-q)
dimension a(*),la(*),b(*),tn(*),xn(*),d(*),ws(*),
* lr(*),lc(*),li(*),pp(*),qq(*)
common/noutc/nout
common/factorc/m1,m2,mp,mq,lastr,irow
c write(nout,*)'aqsol q =',q
if(q.gt.0)then
do i=1,n
tn(i)=0.D0
enddo
if(q.le.n)then
tn(li(q))=1.D0
else
call iscatter(a,la,q-n,li,tn,n)
endif
elseif(q.eq.0)then
do i=1,n
tn(li(i))=b(i)
enddo
endif
c write(nout,*)'tn =',(tn(i),i=1,n)
do i=n,m2+1,-1
ir=lr(i)
pri=pp(ir)
if(pri.eq.0)then
xn(i)=tn(i)/d(i)
else
xn(i)=(scpr(tn(i),ws(qq(ir)+1),tn(i-pri),pri))/d(i)
endif
call isaipy(-xn(i),a,la,lc(i)-n,tn,n,lr,li)
enddo
do i=m2+1,n
tn(i)=xn(i)
enddo
c write(nout,*)'tn =',(tn(i),i=1,n)
return
end
subroutine eptsol(n,a,la,p,b,sn,tn,d,ws,lr,lc,li,pp,qq)
implicit double precision (a-h,r-z), integer (i-q)
dimension a(*),la(*),b(*),sn(*),tn(*),d(*),ws(*),
* lr(*),lc(*),li(*),pp(*),qq(*)
common/noutc/nout
common/iprintc/iprint
common/epsc/eps,tol,emin
common/factorc/m1,m2,mp,mq,lastr,irow
c write(nout,*)'eptsol p =',p
if(p.eq.0)then
do i=1,m2
sn(i)=b(lr(i))
enddo
do i=m2+1,n
sn(i)=0.D0
enddo
do i=m2+1,n
j=lc(i)
sn(i)=-aiscpri(n,a,la,j-n,sn,-b(j),lr,li)/d(i)
ir=lr(i)
pri=pp(ir)
if(pri.gt.0)call mysaxpy(sn(i),ws(qq(ir)+1),sn(i-pri),pri)
enddo
else
do i=1,n
sn(i)=0.D0
enddo
pr=li(p)
if(p.le.n)then
if(pr.gt.m2)goto1
sn(pr)=1.D0
do i=m2+1,n
sn(i)=-aiscpri(n,a,la,lc(i)-n,sn,0.D0,lr,li)/d(i)
ir=lr(i)
pri=pp(ir)
if(pri.gt.0)call mysaxpy(sn(i),ws(qq(ir)+1),sn(i-pri),pri)
enddo
else
if(pr.le.m2)goto1
do i=m2+1,n
bi=0.D0
if(i.eq.pr)bi=-1.D0
sn(i)=-aiscpri(n,a,la,lc(i)-n,sn,bi,lr,li)/d(i)
ir=lr(i)
pri=pp(ir)
if(pri.gt.0)call mysaxpy(sn(i),ws(qq(ir)+1),sn(i-pri),pri)
enddo
endif
endif
c write(nout,*)'sn =',(sn(i),i=1,n)
return
1 continue
write(nout,*)'malfunction detected in eptsol: p =',p
stop
end
subroutine order(n,nu,nc,la,lr,ls,li,p,q,r,ws,mxws,ifail)
implicit integer (c-t)
double precision ws
dimension la(0:*),lr(*),ls(*),li(*),p(*),q(*),r(*),ws(*)
common/noutc/nout
c character star(1000,80)
c write(nout,*)'order'
c spk1 ordering on full matrix
ifail=0
if(nu.eq.n)return
c set row and column counts and row-wise data structure
nn=n-nu
ii=mxws/nn
do j=1,nn
rowj=lr(j)
p(rowj)=(j-1)*ii
r(rowj)=0
enddo
do j=nn+1,n
r(lr(j))=0
enddo
1 continue
do i=nu+1,nc
coli=abs(ls(i))
li(coli)=0
jp=la(0)+coli-n
do j=la(jp),la(jp+1)-1
rowj=la(j)
if(li(rowj).le.nn)then
li(coli)=li(coli)+1
r(rowj)=r(rowj)+1
ij=p(rowj)+r(rowj)
if(ij.gt.mxws)then
ij=mxws
ifail=1
endif
ws(ij)=dble(coli)
endif
enddo
enddo
c check for no overlaps
qrj=0
do j=1,nn
rowj=lr(j)
if(p(rowj).lt.qrj)ifail=1
qrj=p(rowj)+r(rowj)
q(rowj)=qrj
p(rowj)=p(rowj)+1
enddo
if(ifail.eq.1.or.qrj.gt.mxws)then
qrj=0
do j=1,nn
rowj=lr(j)
p(rowj)=qrj
qrj=qrj+r(rowj)
r(rowj)=0
enddo
if(qrj.gt.mxws)then
write(nout,*)'not enough space for ws in order: mxws =',mxws
ifail=7
return
endif
ifail=0
goto1
endif
ifirstc=nu+1
ifirstr=1
2 continue
c move zero-column-count columns to lhs and find minimum column count
mcc=n
do i=ifirstc,nc
coli=abs(ls(i))
if(li(coli).eq.0)then
call iexch(ls(i),ls(ifirstc))
li(coli)=ifirstr-1
ifirstc=ifirstc+1
else
mcc=min(mcc,li(coli))
endif
enddo
c write(nout,*)'ifirstc,ifirstr,mcc',ifirstc,ifirstr,mcc
c write(nout,*)'lr =',(lr(j),j=1,n)
c write(nout,*)'ls =',(ls(i),i=nu+1,nc)
c write(nout,*)'row counts =',(r(lr(j)),j=1,n)
c write(nout,*)'column counts =',(li(abs(ls(i))),i=nu+1,nc)
if(ifirstc.gt.nc)goto4
c apply tie-break rule
tie=0
do i=ifirstc,nc
coli=abs(ls(i))
if(li(coli).eq.mcc)then
ti=0
jp=la(0)+coli-n
do j=la(jp),la(jp+1)-1
rowj=la(j)
if(li(rowj).ge.ifirstr)ti=ti+r(rowj)
enddo
if(ti.gt.tie)then
tie=ti
mccc=coli
endif
endif
enddo
c write(nout,*)'tie,mccc',tie,mccc
c permute rows of m-c-c column to top and update column counts
jp=la(0)+mccc-n
do j=la(jp),la(jp+1)-1
rowj=la(j)
jr=li(rowj)
if(jr.lt.ifirstr)goto3
if(jr.gt.nn)goto3
lr(jr)=lr(ifirstr)
li(lr(jr))=jr
lr(ifirstr)=rowj
li(rowj)=ifirstr
ifirstr=ifirstr+1
do i=p(rowj),q(rowj)
coli=int(ws(i))
li(coli)=li(coli)-1
enddo
3 continue
enddo
goto2
4 continue
c print star diagram
c if(nc-nu.gt.80.or.n.gt.1000)stop
c write(nout,*)'spk1 ordering'
c ij=li(abs(ls(nc)))
c do i=1,ij
c do j=1,nc-nu
c star(i,j)=' '
c enddo
c enddo
c do j=1,nc-nu
c jp=la(0)+abs(ls(nu+j))-n
c do i=la(jp),la(jp+1)-1
c star(li(la(i)),j)='*'
c enddo
c enddo
c do i=1,ij
c write(nout,*)(star(i,j),j=1,nc-nu)
c enddo
c write(nout,*)'lr =',(lr(i),i=1,n)
c write(nout,*)'ls =',(ls(i),i=nu+1,nc)
c write(nout,*)'lower profile =',(li(abs(ls(i))),i=nu+1,nc)
return
end
subroutine factor(n,nm,nu,nc,a,la,e,ls,sn,tn,un,xn,lr,lc,li,
* mao,p,q,r,s,ws,mxws,d,ifail)
implicit double precision (a-h,r-z), integer (i-q)
integer coli,r,s,rowi,rowp,tl,tu
dimension a(*),la(0:*),e(*),ls(*),sn(*),tn(*),un(*),xn(*),
* lr(*),lc(*),li(*),mao(*),p(*),q(*),r(*),s(*),ws(*),d(*)
c character star(1000,80)
common/factorc/m1,m2,mp,mq,lastr,irow
common/iprintc/iprint
common/refactorc/nup,nfreq
common/epsc/eps,tol,emin
common/noutc/nout
parameter (thresh=1.D-1)
c factorize LPA=U when A is rectangular
c p(row) stores the number of stored elements of a natural row
c q(row) stores the base address in ws of a natural row
c r(row) stores the previous row stored in ws (or 0 if the first row in ws)
c s(row) stores the next row stored in ws (or 0 if the last row in ws)
c li(n+*) stores the lower profile of the sparse matrix
c irow stores the natural row number of the initial row stored in ws
c lastr stores the natural row number of the previous row put into ws
c write(nout,*)'factor'
nup=0
lastr=0
irow=0
do i=1,n
p(i)=0
enddo
m1=0
tl=1
do ii=nu+1,nc
coli=abs(ls(ii))
c write(nout,*)'coli =',coli
tu=li(coli)
do i=1,n
tn(i)=0.D0
enddo
call iscatter(a,la,coli-n,li,tn,n)
do i=m1,1,-1
rowi=lr(i)
pri=p(rowi)
if(pri.eq.0)then
xn(i)=tn(i)/d(i)
else
xn(i)=(scpr(tn(i),ws(q(rowi)+1),tn(i-pri),pri))/d(i)
endif
call isaipy(-xn(i),a,la,lc(i)-n,tn,n,lr,li)
enddo
do i=1,m1
tn(i)=xn(i)
enddo
m1p=m1+1
c write(nout,*)'lr =',(lr(i),i=1,n)
c write(nout,*)'tn =',(tn(i),i=1,tu)
c threshold pivot selection
call linf(tu-m1,tn(m1p),z,iz)
if(z.le.tol)then
li(coli)=0
goto2
endif
zz=max(tol,z*thresh)
do i=tl,tu
q(lr(i))=m1p
enddo
c write(nout,*)'q =',(q(lr(i)),i=m1p,tu)
iz=iz+m1
if(iz.lt.tl)then
z=0.D0
qri=m1p
do j=m1p,tu
tnj=abs(tn(j))
if(tnj.ge.zz)then
qrj=q(lr(j))
if(qrj.eq.qri)then
if(tnj.gt.z)then
z=tnj
iz=j
endif
elseif(qrj.gt.qri)then
z=tnj
iz=j
qri=qrj
endif
endif
enddo
endif
tl=tu+1
c write(nout,*)'zz,z,iz,m1,qri',zz,z,iz,m1,qri
if(iz.gt.m1p)then
call rexch(tn(m1p),tn(iz))
call iexch(lr(m1p),lr(iz))
li(lr(m1p))=m1p
li(lr(iz))=iz
endif
rowp=lr(m1p)
c reset q values
qrp=q(rowp)
do i=m1p+1,tu
if(abs(tn(i)).gt.tol)then
rowi=lr(i)
if(qrp.lt.q(rowi))q(rowi)=qrp
endif
enddo
tnp=tn(m1p)
do i=1,n
sn(i)=0.D0
enddo
sn(m1p)=1.D0
do i=1,m1
sn(i)=-aiscpri(n,a,la,lc(i)-n,sn,0.D0,lr,li)/d(i)
rowi=lr(i)
pri=p(rowi)
if(pri.gt.0)call mysaxpy(sn(i),ws(q(rowi)+1),sn(i-pri),pri)
enddo
c write(nout,*)'sn =',(sn(i),i=1,m1)
c update steepest edge coefficients
ep=e(rowp)
e(rowp)=0.D0
eq=2.D0/ep
do i=1,n
un(i)=eq*sn(i)
enddo
do i=m1,1,-1
rowi=lr(i)
pri=p(rowi)
if(pri.eq.0)then
xn(i)=un(i)/d(i)
else
xn(i)=(scpr(un(i),ws(q(rowi)+1),un(i-pri),pri))/d(i)
endif
call isaipy(-xn(i),a,la,lc(i)-n,un,n,lr,li)
enddo
do i=1,m1
un(i)=xn(i)
enddo
c write(nout,*)'un =',(un(i),i=1,n)
eq=ep/tnp
do i=1,nm
if(e(i).gt.0.D0)then
j=li(i)
ei=e(i)
wi=tn(j)*eq
awi=abs(wi)
if(ei.ge.awi)then
wi=wi/ei
e(i)=max(emin,ei*sqrt(max(0.D0,1.D0+wi*(wi-un(j)/ei))))
else
wi=ei/wi
e(i)=max(emin,awi*sqrt(max(0.D0,1.D0+wi*(wi-un(j)/ei))))
endif
endif
enddo
e(coli)=max(emin,abs(eq))
do j=qrp,m1
if(abs(sn(j)).gt.tol)goto1
enddo
j=m1p
1 continue
pri=m1p-j
if(pri.gt.0)then
call newslot(rowp,pri,lastr,irow,p,q,r,s,ws,mxws,i,ifail)
if(ifail.gt.0)return
p(rowp)=pri
i=q(rowp)
do j=j,m1
i=i+1
ws(i)=sn(j)
enddo
endif
m1=m1p
ls(m1)=ls(ii)
lc(m1)=coli
li(coli)=m1
d(m1)=tnp
2 continue
enddo
c complete ls and reorder lr, lc and d
do i=m1+1,n
ls(i)=lr(i)
enddo
j=n
do i=1,nm
if(e(i).eq.0.D0)then
j=j+1
ls(j)=i
endif
enddo
m2=n-m1
do i=n,m2+1,-1
lc(i)=lc(i-m2)
li(lc(i))=i
lr(i)=lr(i-m2)
li(lr(i))=i
d(i)=d(i-m2)
enddo
do i=1,m2
lr(i)=ls(m1+i)
li(lr(i))=i
enddo
c reset mao
ilast=n
ii=ilast
do i=ilast,m2+1,-1
mao(i)=ilast
ii=min(ii,i-p(lr(i)))
if(ii.eq.i)ilast=i-1
enddo
c write(nout,*)'PAQ factors: m1 =',m1
c write(nout,*)'d =',(d(ij),ij=m2+1,n)
c do j=m2+1,n