-
Notifications
You must be signed in to change notification settings - Fork 0
/
sparse_mod.f90
4144 lines (3714 loc) · 152 KB
/
sparse_mod.f90
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
MODULE sparse_mod
IMPLICIT NONE
PUBLIC sparse_solve_method
INTEGER :: sparse_solve_method = 3
PUBLIC sparse_talk
!LOGICAL :: sparse_talk = .TRUE.
LOGICAL :: sparse_talk = .FALSE.
PRIVATE dp
INTEGER, PARAMETER :: dp = KIND(1.0d0)
PRIVATE long
INTEGER, PARAMETER :: long = 8
PRIVATE factorization_exists
LOGICAL :: factorization_exists = .FALSE.
!-------------------------------------------------------------------------------
!Initialization of the parameters of Super_LU c-Routines
PRIVATE factors
INTEGER(kind=long) :: factors
!-------------------------------------------------------------------------------
!!$ !ToDo: Please uncomment, when PARDISO is desired
!!$ !Initialization of the PARDISO-Solver-Routine!
!!$ !Solver's internal data adress pointer
!!$ INTEGER(kind=long), PRIVATE :: pt(64)
!!$ !max. number of factors with identical nonzero sparsity structure to keep in menmory
!!$ INTEGER, PUBLIC :: maxfct=1
!!$ !Actual matrix for the solution phase (according to maxfct), error indicator,
!!$ !no Message level information
!!$ INTEGER, PUBLIC :: mnum=1, error_pardiso, msglvl=0
!!$ !Matrix type - e.g. 11=real and nonsymmetric, 13 =complex and nonsymmetric,
!!$ !1=real and structurally symmetric,....
!!$ INTEGER, PUBLIC :: mtype=11
!!$ !controls the execution of the solver (like iopt and iopt_in)
!!$ !(e.g. 12=Analysis/numerical factorization, 33=solve,iterative refinement,
!!$ !-1=release all internal memory )
!!$ INTEGER, PRIVATE :: phase
!!$ !user sparse direct solver (solver=1 multi-recursive iterative solver)
!!$ INTEGER, PUBLIC :: pardiso_solver=0
!!$ !optional settings of the solver, default values set by subroutine pardisoinit
!!$ !(exception: iparm(3)=OMP_NUM_THREADS (NO DEFAULT VALUe) )
!!$ INTEGER, PUBLIC :: iparm(64)
!!$ !iparm(12)=1 ==> solution of the transposed system has to be performed
!!$ !( (A^T)*X=B ) - PARDISO uses the "compressed-sparse-row" (CSR) format to store matrices
!!$ !and SuperLU uses "compressed-sparse-column" (CSC) format to store matrices
!!$ !(relationship between CSR and CSC: CSR(A)=CSC(transposed(A)) with matrix A)
!!$ !instead of converting the storage format, the transposed system is solved
!!$ INTEGER, PUBLIC :: omp_num_threads=4
!!$ INTEGER, PRIVATE :: idummy
!!$ REAL(kind=dp), PRIVATE :: ddummy
!!$ !optional settings for the multi-recursive solver
!!$ REAL(kind=dp), PUBLIC :: dparm(64)
!-------------------------------------------------------------------------------
!Initialization of the SuiteSparse-Solver-Routine!
!Solver's internal data adress pointer
INTEGER(kind=long), PRIVATE :: symbolic, numeric
!Solves A*x=b (e.g. sys=2 -> solves (A^T)*x=b; further options manual pg. 26)
INTEGER(kind=long), PRIVATE :: sys=0
!default values for control pg. 22
REAL(kind=dp), PRIVATE :: control(20), info_suitesparse(90)
!-------------------------------------------------------------------------------
PUBLIC load_mini_example
PRIVATE load_mini_ex
INTERFACE load_mini_example
MODULE PROCEDURE load_mini_ex
END INTERFACE load_mini_example
PUBLIC load_compressed_example
PRIVATE load_compressed_ex
INTERFACE load_compressed_example
MODULE PROCEDURE load_compressed_ex
END INTERFACE load_compressed_example
PUBLIC load_standard_example
PRIVATE load_standard_ex
INTERFACE load_standard_example
MODULE PROCEDURE load_standard_ex
END INTERFACE load_standard_example
PUBLIC load_octave_matrices
PRIVATE load_octave_mat
INTERFACE load_octave_matrices
MODULE PROCEDURE load_octave_mat, load_octave_matComplex
END INTERFACE load_octave_matrices
PUBLIC column_pointer2full
PRIVATE col_pointer2full
INTERFACE column_pointer2full
MODULE PROCEDURE col_pointer2full
END INTERFACE column_pointer2full
PUBLIC column_full2pointer
PRIVATE col_full2pointer
INTERFACE column_full2pointer
MODULE PROCEDURE col_full2pointer
END INTERFACE column_full2pointer
PUBLIC sparse2full
PRIVATE sp2full
INTERFACE sparse2full
MODULE PROCEDURE sp2full, sp2fullComplex
END INTERFACE sparse2full
PUBLIC full2sparse
PRIVATE full2sp
INTERFACE full2sparse
MODULE PROCEDURE full2sp,full2spComplex
END INTERFACE full2sparse
PUBLIC sparse_solve
INTERFACE sparse_solve
MODULE PROCEDURE sparse_solveReal_b1,sparse_solveReal_b2,sparse_solveReal_A_b1,sparse_solveReal_A_b2, &
sparse_solveComplex_b1,sparse_solveComplex_b2,sparse_solveComplex_A_b1,sparse_solveComplex_A_b2
END INTERFACE sparse_solve
PUBLIC sparse_solve_superlu
INTERFACE sparse_solve_superlu
!MODULE PROCEDURE sparse_solve_superlu_b1,sparse_solve_superlu_b2
MODULE PROCEDURE sparse_solve_superlu_b1,sparse_solve_superlu_b2_loop, &
sparse_solve_superluComplex_b1, sparse_solve_superluComplex_b2_loop
END INTERFACE sparse_solve_superlu
!!$ !ToDo: Please uncomment, when PARDISO is desired
!!$ PUBLIC sparse_solve_pardiso
!!$ INTERFACE sparse_solve_pardiso
!!$ MODULE PROCEDURE sparse_solve_pardiso_b1, sparse_solve_pardiso_b2_loop, &
!!$ sparse_solve_pardisoComplex_b1, sparse_solve_pardisoComplex_b2_loop
!!$ END INTERFACE sparse_solve_pardiso
PUBLIC sparse_solve_suitesparse
INTERFACE sparse_solve_suitesparse
MODULE PROCEDURE sparse_solve_suitesparse_b1, sparse_solve_suitesparse_b2_loop, &
sparse_solve_suitesparseComplex_b1, sparse_solve_suitesparseComplex_b2_loop
END INTERFACE sparse_solve_suitesparse
PUBLIC sparse_matmul
INTERFACE sparse_matmul
MODULE PROCEDURE sp_matmul_A_b1,sp_matmul_b1,sp_matmul_A_b2,sp_matmul_b2, &
sp_matmulComplex_A_b1, sp_matmulComplex_b1, sp_matmulComplex_A_b2, sp_matmulComplex_b2
END INTERFACE sparse_matmul
PUBLIC sparse_solver_test
INTERFACE sparse_solver_test
MODULE PROCEDURE sp_test_A_b1,sp_test_b1,sp_test_A_b2,sp_test_b2, &
sp_testComplex_A_b1, sp_testComplex_b1, sp_testComplex_A_b2, sp_testComplex_b2
END INTERFACE sparse_solver_test
PUBLIC sparse_example
PUBLIC remap_rc
INTERFACE remap_rc
MODULE PROCEDURE remap_rc_real, remap_rc_cmplx
END INTERFACE remap_rc
! helper
PRIVATE find_unit
CONTAINS
!-------------------------------------------------------------------------------
! finds free unit
SUBROUTINE find_unit(unit)
INTEGER, INTENT(inout) :: unit
LOGICAL :: opened
DO
INQUIRE(unit=unit,opened=opened)
IF (.NOT. opened) EXIT
unit = unit + 1
END DO
END SUBROUTINE find_unit
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! Examples
SUBROUTINE sparse_example(example,subexample)
INTEGER, INTENT(in) :: example
INTEGER, INTENT(in), OPTIONAL :: subexample
CHARACTER(len=100) :: name
INTEGER :: nrow,ncol,nz, nrhs
INTEGER, DIMENSION(:), ALLOCATABLE :: irow,pcol,icol
REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: val,b,x
REAL(kind=dp), DIMENSION(:,:), ALLOCATABLE :: A,bb,xx
COMPLEX(kind=dp), DIMENSION(:), ALLOCATABLE :: z_val,z_b,z_x
COMPLEX(kind=dp), DIMENSION(:,:), ALLOCATABLE :: z_A,z_bb,z_xx
INTEGER :: ir,ic,icmax,subex_example6,i,unit
subex_example6=1
IF(PRESENT(subexample)) subex_example6=subexample
IF (example .EQ. 1) THEN
! load the test-matrix for the mini_example
CALL load_mini_example(A)
! construct the rhs
IF (ALLOCATED(b)) DEALLOCATE(b)
ALLOCATE(b(SIZE(A,2)))
b = 1.0_dp
! x is only needed because b should not be overwritten
IF (ALLOCATED(x)) DEALLOCATE(x)
ALLOCATE(x(SIZE(b,1)))
x = b
! solve
CALL sparse_solve(A,x)
PRINT *,x
! test
CALL sparse_solver_test(A,x,b)
ELSEIF (example .EQ. 2) THEN
! load the test-matrix for the mini_example (with multiple rhs)
CALL load_mini_example(A)
! convert to sparse
CALL full2sparse(A,irow,pcol,val,nrow,ncol,nz)
IF (sparse_talk) PRINT *, 'nrow=',nrow,' ncol=',ncol,' nz=',nz
!Check the conversion to sparse
!CALL sparse2full(irow,pcol,val,nrow,ncol,A)
!!$ !save the matrix in a sparse format for further analysis
!!$ !(e.g. calculate the condition number rcond)
!!$ CALL find_unit(unit)
!!$ OPEN(unit=unit,file='/proj/plasma/Solver_Test/TestMatrices/mini_example.dat',&
!!$ status='replace',action='write')
!!$ DO i=1,ncol+1
!!$ IF(i .EQ. ncol+1) THEN
!!$ WRITE (unit=unit,fmt='(I5)',ADVANCE='YES') pcol(i)
!!$ ELSE
!!$ WRITE (unit=unit,fmt='(I5)',ADVANCE='NO') pcol(i)
!!$ END IF
!!$ END DO
!!$ DO i=1,nz
!!$ IF(i .EQ. nz) THEN
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='YES') irow(i)
!!$ ELSE
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='NO') irow(i)
!!$ END IF
!!$ END DO
!!$ DO i=1,nz
!!$ IF(i .EQ. nz) THEN
!!$ WRITE (unit=unit,fmt='(F16.8)',ADVANCE='YES') val(i)
!!$ ELSE
!!$ WRITE (unit=unit,fmt='(F16.8)',ADVANCE='NO') val(i)
!!$ END IF
!!$ END DO
!!$ CLOSE(unit=unit)
!construct an array of rhs
IF (ALLOCATED(bb)) DEALLOCATE(bb)
icmax = ncol
ALLOCATE(bb(nrow,icmax))
DO ic = 1, icmax
DO ir = 1, nrow
bb(ir,ic) = ir-1 + 10*ic
END DO
END DO
IF(ALLOCATED(xx)) DEALLOCATE(xx)
ALLOCATE(xx(SIZE(bb,1),SIZE(bb,2)))
xx = bb
! solve the system for multiple rhs
!CALL sparse_solve(nrow,ncol,nz,irow,pcol,val,xx)
! would also work with a full column index vector
CALL column_pointer2full(pcol,icol)
CALL sparse_solve(nrow,ncol,nz,irow,icol,val,xx)
! test
CALL sparse_solver_test(nrow,ncol,irow,pcol,val,xx,bb)
ELSEIF (example .EQ. 3) THEN
! load the test-matrix g10
!name = 'data/g10'
name = '/proj/plasma/Libs/SuperLU/SuperLU_3.0/DATA/g10'
CALL load_standard_example(name,nrow,ncol,nz,irow,pcol,val)
IF (sparse_talk) PRINT *, 'nrow=',nrow,' ncol=',ncol,' nz=',nz
!!$ !save the matrix in a sparse format for further analysis
!!$ !(e.g. calculate the condition number rcond)
!!$ CALL find_unit(unit)
!!$ OPEN(unit=unit,file='/proj/plasma/Solver_Test/TestMatrices/g10.dat',&
!!$ status='replace',action='write')
!!$ DO i=1,ncol+1
!!$ IF(i .EQ. ncol+1) THEN
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='YES') pcol(i)
!!$ ELSE
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='NO') pcol(i)
!!$ END IF
!!$ END DO
!!$ DO i=1,nz
!!$ IF(i .EQ. nz) THEN
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='YES') irow(i)
!!$ ELSE
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='NO') irow(i)
!!$ END IF
!!$ END DO
!!$ DO i=1,nz
!!$ IF(i .EQ. nz) THEN
!!$ WRITE (unit=unit,fmt='(F16.8)',ADVANCE='YES') val(i)
!!$ ELSE
!!$ WRITE (unit=unit,fmt='(F16.8)',ADVANCE='NO') val(i)
!!$ END IF
!!$ END DO
!!$ CLOSE(unit=unit)
! construct the rhs
IF (ALLOCATED(b)) DEALLOCATE(b)
ALLOCATE(b(nrow))
b = 1.0_dp
IF (ALLOCATED(x)) DEALLOCATE(x)
ALLOCATE(x(SIZE(b,1)))
x = b
! solve
CALL sparse_solve(nrow,ncol,nz,irow,pcol,val,x)
PRINT *,x
! test
CALL sparse_solver_test(nrow,ncol,irow,pcol,val,x,b)
ELSEIF (example .EQ. 4) THEN
! load the test-matrix of the compressed_example
!name = 'data/sparse_compressed_e100_s100_D0d001.dat'
name = '/proj/plasma/Libs/SuperLU/SuperLU_3.0/DATA/sparse_compressed_e100_s100_D0d001.dat'
CALL load_compressed_example(name,nrow,ncol,nz,irow,pcol,val)
IF (sparse_talk) PRINT *, 'nrow=',nrow,' ncol=',ncol,' nz=',nz
!!$ !save the matrix in a sparse format for further analysis
!!$ !(e.g. calculate the condition number rcond)
!!$ CALL find_unit(unit)
!!$ OPEN(unit=unit,file='/proj/plasma/Solver_Test/TestMatrices/sparse_compressed_e100_s100_D0d001.dat' &
!!$ ,status='replace',action='write')
!!$ DO i=1,ncol+1
!!$ IF(i .EQ. ncol+1) THEN
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='YES') pcol(i)
!!$ ELSE
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='NO') pcol(i)
!!$ END IF
!!$ END DO
!!$ DO i=1,nz
!!$ IF(i .EQ. nz) THEN
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='YES') irow(i)
!!$ ELSE
!!$ WRITE (unit=unit,fmt='(I8)',ADVANCE='NO') irow(i)
!!$ END IF
!!$ END DO
!!$ DO i=1,nz
!!$ IF(i .EQ. nz) THEN
!!$ WRITE (unit=unit,fmt='(F16.8)',ADVANCE='YES') val(i)
!!$ ELSE
!!$ WRITE (unit=unit,fmt='(F16.8)',ADVANCE='NO') val(i)
!!$ END IF
!!$ END DO
!!$ CLOSE(unit=unit)
! construct a rhs
IF (ALLOCATED(b)) DEALLOCATE(b)
ALLOCATE(b(nrow))
b = 0.0_dp
b(1) = 1.0_dp
IF(ALLOCATED(x)) DEALLOCATE(x)
ALLOCATE(x(SIZE(b,1)))
x = b
! solve
CALL sparse_solve(nrow,ncol,nz,irow,pcol,val,x)
PRINT *,x
! test
CALL sparse_solver_test(nrow,ncol,irow,pcol,val,x,b)
ELSEIF (example .EQ. 5) THEN
! load the test-matrix of the compressed_example
!name = 'data/sparse_compressed_e100_s100_D0d001.dat'
name = "/proj/plasma/Libs/SuperLU/SuperLU_3.0/DATA/&
&sparse_compressed_e100_s100_D0d001.dat"
CALL load_compressed_example(name,nrow,ncol,nz,irow,pcol,val)
IF (sparse_talk) PRINT *, 'nrow=',nrow,' ncol=',ncol,' nz=',nz
! construct a rhs
IF (ALLOCATED(bb)) DEALLOCATE(bb)
ALLOCATE(bb(nrow,ncol))
DO ir = 1, nrow
bb(ir,ir) = 1.0_dp
END DO
IF(ALLOCATED(xx)) DEALLOCATE(xx)
ALLOCATE(xx(SIZE(bb,1),SIZE(bb,2)))
xx = bb
! solve
CALL sparse_solve(nrow,ncol,nz,irow,pcol,val,xx)
!PRINT *,xx
! test
CALL sparse_solver_test(nrow,ncol,irow,pcol,val,xx,bb)
ELSEIF (example .EQ. 6) THEN
! load the different test-matrices generated by octave
! for the different test-cases
SELECT CASE (subex_example6)
CASE (1)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix1.dat'
CASE (2)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix2.dat'
CASE (3)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix3.dat'
CASE (4)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix4.dat'
CASE (5)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix5.dat'
CASE (6)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix6.dat'
CASE (7)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix7.dat'
CASE (8)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix8.dat'
CASE (9)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix9.dat'
CASE (10)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix10.dat'
CASE (11)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix11.dat'
CASE (12)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix12.dat'
CASE (13)
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix13.dat'
CASE DEFAULT
PRINT *, 'unknown file name -> select a subexample between 1 and 13'
END SELECT
CALL load_octave_matrices(name,nrow,ncol,nz,irow,pcol,val)
IF (sparse_talk) PRINT *, 'nrow=',nrow,' ncol=',ncol,' nz=',nz
! construct a rhs
IF (ALLOCATED(b)) DEALLOCATE(b)
ALLOCATE(b(nrow))
b = 0.0_dp
b(1) = 1.0_dp
IF(ALLOCATED(x)) DEALLOCATE(x)
ALLOCATE(x(SIZE(b,1)))
x = b
! solve
CALL sparse_solve(nrow,ncol,nz,irow,pcol,val,x)
!PRINT *,x
! test
CALL sparse_solver_test(nrow,ncol,irow,pcol,val,x,b)
ELSEIF (example .EQ. 7) THEN
nrow=8
ncol=8
nz=20
IF (ALLOCATED(pcol)) DEALLOCATE(pcol)
ALLOCATE(pcol(nrow+1))
IF (ALLOCATED(irow)) DEALLOCATE(irow)
ALLOCATE(irow(nz))
IF (ALLOCATED(z_val)) DEALLOCATE(z_val)
ALLOCATE(z_val(nz))
pcol= (/1,5,8,10,12,13,16,18,21/)
irow =(/ 1,3,6,7,2,3,5,3,8,4,7,2,3,6,8,2,7,3,7,8 /)
z_val=(/ (7.d0, 1.d0), (1.d0,1.d0), (2.d0,1.d0), (7.d0,1.d0), (-4.d0,0.d0),&
(8.d0,1.d0), (2.d0,1.d0),(1.d0,1.d0),(5.d0,1.d0),(7.d0,0.d0), (9.d0,1.d0),&
(-4d0,1.d0),(7.d0,1.d0), (3.d0,1.d0), (8.d0,0.d0),(1.d0,1.d0),&
(11.d0,1.d0),(-3.d0,1.d0), (2.d0,1.d0), (5.d0,0.d0)/)
IF (ALLOCATED(z_b)) DEALLOCATE(z_b)
ALLOCATE(z_b(nrow))
DO ir = 1, nrow
z_b(ir) = (1.d0,1.d0)
END DO
IF (ALLOCATED(z_x)) DEALLOCATE(z_x)
ALLOCATE(z_x(nrow))
z_x=z_b
CALL sparse_solve(nrow,ncol,nz,irow,pcol,z_val,z_x)
PRINT *,z_x
CALL sparse_solver_test(nrow,ncol,irow,pcol,z_val,z_x,z_b)
ELSEIF (example .EQ. 8) THEN
! load the different complex test-matrices generated by octave
! for the different test-cases
SELECT CASE (subex_example6)
CASE (1)
name = '/proj/plasma/Solver_Test/TestMatrices/test_ComplexMatrix1.dat'
CASE (2)
name = '/proj/plasma/Solver_Test/TestMatrices/test_ComplexMatrix2.dat'
CASE (3)
name= '/proj/plasma/Solver_Test/TestMatrices/test_ComplexMatrix3.dat'
CASE (4)
name = '/proj/plasma/Solver_Test/TestMatrices/test_ComplexMatrix4.dat'
CASE (5)
name = '/proj/plasma/Solver_Test/TestMatrices/test_ComplexMatrix5.dat'
CASE (6)
name = '/proj/plasma/Solver_Test/TestMatrices/test_ComplexMatrix6.dat'
CASE (7)
name = '/proj/plasma/Solver_Test/TestMatrices/test_ComplexMatrix7.dat'
CASE DEFAULT
PRINT *, 'unknown file name -> select a subexample between 1 and 7'
END SELECT
CALL load_octave_matrices(name,nrow,ncol,nz,irow,pcol,z_val)
IF (sparse_talk) PRINT *, 'nrow=',nrow,' ncol=',ncol,' nz=',nz
! construct a rhs
IF (ALLOCATED(z_b)) DEALLOCATE(z_b)
ALLOCATE(z_b(nrow))
z_b = (0.0_dp,0.0_dp)
z_b(1) = (1.0_dp,1.0_dp)
IF(ALLOCATED(z_x)) DEALLOCATE(z_x)
ALLOCATE(z_x(SIZE(z_b,1)))
z_x = z_b
! solve
CALL sparse_solve(nrow,ncol,nz,irow,pcol,z_val,z_x)
! test
CALL sparse_solver_test(nrow,ncol,irow,pcol,z_val,z_x,z_b)
ELSEIF (example .EQ. 9) THEN
!load test_matrix13.dat and solve the system for different numbers
!of right-hand sides
name = '/proj/plasma/Solver_Test/TestMatrices/test_matrix13.dat'
CALL load_octave_matrices(name,nrow,ncol,nz,irow,pcol,val)
IF (sparse_talk) PRINT *, 'nrow=',nrow,' ncol=',ncol,' nz=',nz
SELECT CASE (subex_example6)
CASE (1)
nrhs=10
CASE (2)
nrhs=25
CASE (3)
nrhs=50
CASE (4)
nrhs=75
CASE (5)
nrhs=100
CASE (6)
nrhs=250
CASE (7)
nrhs=500
CASE (8)
nrhs=750
CASE (9)
nrhs=1000
CASE DEFAULT
PRINT *, 'unknown number of rhs -> select a subexample between 1 and 9'
END SELECT
! construct a rhs
IF (ALLOCATED(bb)) DEALLOCATE(bb)
ALLOCATE(bb(nrow,nrhs))
DO ir = 1, nrhs
bb(ir,ir) = 1.0_dp
END DO
IF(ALLOCATED(xx)) DEALLOCATE(xx)
ALLOCATE(xx(SIZE(bb,1),SIZE(bb,2)))
xx = bb
! solve
CALL sparse_solve(nrow,ncol,nz,irow,pcol,val,xx)
!PRINT *,xx
! test
CALL sparse_solver_test(nrow,ncol,irow,pcol,val,xx,bb)
END IF
IF (ALLOCATED(irow)) DEALLOCATE(irow)
IF (ALLOCATED(icol)) DEALLOCATE(icol)
IF (ALLOCATED(pcol)) DEALLOCATE(pcol)
IF (ALLOCATED(val)) DEALLOCATE(val)
IF (ALLOCATED(A)) DEALLOCATE(A)
IF (ALLOCATED(b)) DEALLOCATE(b)
IF (ALLOCATED(x)) DEALLOCATE(x)
IF (ALLOCATED(bb)) DEALLOCATE(bb)
IF (ALLOCATED(xx)) DEALLOCATE(xx)
IF (ALLOCATED(z_val)) DEALLOCATE(z_val)
IF (ALLOCATED(z_A)) DEALLOCATE(z_A)
IF (ALLOCATED(z_b)) DEALLOCATE(z_b)
IF (ALLOCATED(z_x)) DEALLOCATE(z_x)
IF (ALLOCATED(z_bb)) DEALLOCATE(z_bb)
IF (ALLOCATED(z_xx)) DEALLOCATE(z_xx)
RETURN
END SUBROUTINE sparse_example
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! loads a mini example
SUBROUTINE load_mini_ex(A)
REAL(kind=dp), DIMENSION(:,:), ALLOCATABLE, INTENT(out) :: A
ALLOCATE(A(5,5))
A(:,1) = (/1.0_dp,2.0_dp,3.0_dp,4.0_dp,5.0_dp/)
A(:,2) = A(:,1)*5 + 2
A(:,3) = A(:,2)*7 + 2
A(:,4) = A(:,3)*2 + 2
A(:,5) = A(:,4)*9 + 2
!A(1,5) = 0.0_dp
A(2,4) = 0.0_dp
A(3,3) = 0.0_dp
A(4,2) = 0.0_dp
!A(5,1) = 0.0_dp
RETURN
END SUBROUTINE load_mini_ex
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! loads own compressed example
SUBROUTINE load_compressed_ex(name,nrow,ncol,nz,irow,pcol,val)
CHARACTER(LEN=*), INTENT(in) :: name
INTEGER, INTENT(out) :: nrow,ncol,nz
INTEGER, DIMENSION(:), ALLOCATABLE, INTENT(out) :: irow,pcol
REAL(kind=dp), DIMENSION(:), ALLOCATABLE, INTENT(out) :: val
INTEGER :: unit,i
unit = 10;
CALL find_unit(unit)
OPEN(unit=unit,file=TRIM(ADJUSTL(name)),action='read')
READ(unit,*) nrow,ncol,nz
ALLOCATE(irow(nz),pcol(ncol+1),val(nz))
READ(unit,*) (irow(i), i = 1, nz)
READ(unit,*) (pcol(i), i = 1, ncol+1)
READ(unit,*) (val(i), i = 1, nz)
CLOSE(unit=unit)
RETURN
END SUBROUTINE load_compressed_ex
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! loads standard example from SuperLU distribution
SUBROUTINE load_standard_ex(name,nrow,ncol,nz,irow,pcol,val)
CHARACTER(LEN=*), INTENT(in) :: name
INTEGER, INTENT(out) :: nrow,ncol,nz
INTEGER, DIMENSION(:), ALLOCATABLE, INTENT(out) :: irow,pcol
REAL(kind=dp), DIMENSION(:), ALLOCATABLE, INTENT(out) :: val
INTEGER :: unit,i
CHARACTER(len=72) :: fmt1
CHARACTER(len=72) :: title
CHARACTER(len=8) :: key
CHARACTER(len=3) :: mxtype
CHARACTER(len=16) :: ptrfmt,indfmt
CHARACTER(len=20) :: valfmt,rhsfmt
INTEGER :: totcrd,ptrcrd,indcrd,valcrd,rhscrd,neltvl
fmt1 = '( A72, A8 / 5I14 / A3, 11X, 4I14 / 2A16, 2A20 )'
unit = 10;
CALL find_unit(unit)
OPEN(unit=unit,file=TRIM(ADJUSTL(name)),action='read')
READ (unit=unit,fmt=fmt1 ) &
title, key, totcrd, ptrcrd, indcrd, valcrd, rhscrd, &
mxtype, nrow, ncol, nz, neltvl, &
ptrfmt, indfmt, valfmt, rhsfmt
ALLOCATE(irow(nz),pcol(ncol+1),val(nz))
READ (unit=unit,fmt=ptrfmt) ( pcol(i), i = 1, ncol+1 )
READ (unit=unit,fmt=indfmt) ( irow(i), i = 1, nz )
READ (unit=unit,fmt=valfmt) ( val(i), i = 1, nz )
CLOSE(unit=unit)
RETURN
END SUBROUTINE load_standard_ex
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
SUBROUTINE load_octave_mat(name,nrow,ncol,nz,irow,pcol,val)
CHARACTER(LEN=*), INTENT(in) :: name
INTEGER, INTENT(out) :: nrow,ncol,nz
INTEGER, DIMENSION(:), ALLOCATABLE, INTENT(out) :: irow,pcol
REAL(kind=dp), DIMENSION(:), ALLOCATABLE, INTENT(out) :: val
INTEGER :: unit,i,k
INTEGER, DIMENSION(:), ALLOCATABLE :: octave_pcol
!open the input-file ("name")
unit = 10;
CALL find_unit(unit)
OPEN(unit=unit,file=TRIM(ADJUSTL(name)),action='read')
!read nrow, ncol, nz and allocate the arrays for
!irow, pcol val
READ(unit,*) nrow,ncol,nz
ALLOCATE(irow(nz),pcol(ncol+1),octave_pcol(nz),val(nz))
!read the sparse matrix (Octave-format)
!storage-format for sparse matrices in ocatave
!uses the coordinates (irow, octave_pcol) of entries (val)
!in matrix
DO i=1,nz
READ(unit,*) irow(i),octave_pcol(i),val(i)
END DO
CLOSE(unit=unit)
!now calculate the index of the first entry (linear index)
!of each row (pcol)
!first step: calculate the number of entries in each row
pcol(1)=octave_pcol(1)
k=1
DO i=1,ncol
IF (k .GT. nz) EXIT
IF (octave_pcol(k) .EQ. i) THEN
DO WHILE (octave_pcol(k) .EQ. i)
pcol(i+1)=pcol(i+1)+1
k=k+1
IF (k .GT. nz) EXIT
END DO
k=k-1
ELSE
CYCLE
END IF
k=k+1
END DO
!second step: sum over the number of entries in each row
!to get desired the linear index
DO i=1,ncol
pcol(i+1)=pcol(i)+pcol(i+1)
END DO
RETURN
END SUBROUTINE load_octave_mat
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
SUBROUTINE load_octave_matComplex(name,nrow,ncol,nz,irow,pcol,val)
CHARACTER(LEN=*), INTENT(in) :: name
INTEGER, INTENT(out) :: nrow,ncol,nz
INTEGER, DIMENSION(:), ALLOCATABLE, INTENT(out) :: irow,pcol
COMPLEX(kind=dp), DIMENSION(:), ALLOCATABLE, INTENT(out) :: val
INTEGER :: unit,i,k
INTEGER, DIMENSION(:), ALLOCATABLE :: octave_pcol
!open the input-file ("name")
unit = 10;
CALL find_unit(unit)
OPEN(unit=unit,file=TRIM(ADJUSTL(name)),action='read')
!read nrow, ncol, nz and allocate the arrays for
!irow, pcol val
READ(unit,*) nrow,ncol,nz
ALLOCATE(irow(nz),pcol(ncol+1),octave_pcol(nz),val(nz))
!read the sparse matrix (Octave-format)
!storage-format for sparse matrices in ocatave
!uses the coordinates (irow, octave_pcol) of entries (val)
!in matrix
DO i=1,nz
READ(unit,*) irow(i),octave_pcol(i),val(i)
END DO
CLOSE(unit=unit)
!now calculate the index of the first entry (linear index)
!of each row (pcol)
!first step: calculate the number of entries in each row
pcol(1)=octave_pcol(1)
k=1
DO i=1,ncol
IF (k .GT. nz) EXIT
IF (octave_pcol(k) .EQ. i) THEN
DO WHILE (octave_pcol(k) .EQ. i)
pcol(i+1)=pcol(i+1)+1
k=k+1
IF (k .GT. nz) EXIT
END DO
k=k-1
ELSE
CYCLE
END IF
k=k+1
END DO
!second step: sum over the number of entries in each row
!to get desired the linear index
DO i=1,ncol
pcol(i+1)=pcol(i)+pcol(i+1)
END DO
RETURN
END SUBROUTINE load_octave_matComplex
!-------------------------------------------------------------------------------
!!$ !-------------------------------------------------------------------------------
!!$ ! solves the standard example from the SuperLU-Distribution
!!$ SUBROUTINE solve_standard_ex(nrow,ncol,nz,irow,pcol,val,b)
!!$ INTEGER, INTENT(in) :: nrow,ncol,nz
!!$ INTEGER, DIMENSION(:), ALLOCATABLE, INTENT(in) :: irow,pcol
!!$ REAL(kind=dp), DIMENSION(:), ALLOCATABLE, INTENT(in) :: val
!!$ REAL(kind=dp), DIMENSION(:), ALLOCATABLE, INTENT(inout) :: b
!!$
!!$ INTEGER(kind=long) :: factors
!!$ INTEGER :: nrhs,ldb,n,i,info,iopt
!!$
!!$ n = nrow
!!$ nrhs = 1
!!$ ldb = n
!!$
!!$ IF (ALLOCATED(b)) DEALLOCATE(b)
!!$ ALLOCATE(b(ldb))
!!$ DO i = 1, ldb
!!$ b(i) = 1.0d0
!!$ ENDDO
!!$
!!$ ! First, factorize the matrix. The factors are stored in *factors* handle.
!!$ iopt = 1
!!$ CALL c_fortran_dgssv( iopt, n, nz, nrhs, val, irow, pcol, &
!!$ b, ldb, factors, info )
!!$
!!$ IF (sparse_talk) THEN
!!$ IF (info .EQ. 0) THEN
!!$ PRINT *, 'Factorization succeeded'
!!$ ELSE
!!$ PRINT *, 'INFO from factorization = ', info
!!$ ENDIF
!!$ END IF
!!$
!!$ ! Second, solve the system using the existing factors.
!!$ iopt = 2
!!$ CALL c_fortran_dgssv( iopt, n, nz, nrhs, val, irow, pcol, &
!!$ b, ldb, factors, info )
!!$
!!$ IF (sparse_talk) THEN
!!$ IF (info .EQ. 0) THEN
!!$ PRINT *, 'Solve succeeded'
!!$ WRITE(*,*) (b(i), i=1, n)
!!$ ELSE
!!$ PRINT *, 'INFO from triangular solve = ', info
!!$ ENDIF
!!$ END IF
!!$ ! Last, free the storage allocated inside SuperLU
!!$ iopt = 3
!!$ CALL c_fortran_dgssv( iopt, n, nz, nrhs, val, irow, pcol, &
!!$ b, ldb, factors, info )
!!$
!!$ RETURN
!!$ END SUBROUTINE solve_standard_ex
!!$ !-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! solves A*x = b for sparse A and 1-D vector b
! A is specified through nrow,ncol,nz,irow,pcol,val
! results are returned in b
SUBROUTINE sparse_solveReal_b1(nrow,ncol,nz,irow,pcol,val,b,iopt_in)
INTEGER, INTENT(in) :: nrow,ncol,nz
INTEGER, DIMENSION(:), INTENT(in) :: irow,pcol
REAL(kind=dp), DIMENSION(:), INTENT(in) :: val
REAL(kind=dp), DIMENSION(:), INTENT(inout) :: b
INTEGER, INTENT(in), OPTIONAL :: iopt_in
INTEGER :: iopt = 0
INTEGER, DIMENSION(:), ALLOCATABLE :: pcoln
LOGICAL :: pcol_modified = .FALSE.
!optional input
IF (PRESENT(iopt_in)) iopt = iopt_in
! make sure that pcol is a pointer, otherwise create pcoln
IF (SIZE(pcol,1) .EQ. SIZE(irow,1)) THEN
CALL column_full2pointer(pcol,pcoln)
pcol_modified = .TRUE.
END IF
!!$ !ToDo: Please uncomment, when PARDISO is desired
!!$ CALL pardisoinit(pt, mtype, pardiso_solver, iparm, dparm, error_pardiso)
!!$ IF (error_pardiso .NE. 0) THEN
!!$ IF (error_pardiso.EQ.-10 ) WRITE(*,*) 'No license file found'
!!$ IF (error_pardiso.EQ.-11 ) WRITE(*,*) 'License is expired'
!!$ IF (error_pardiso.EQ.-12 ) WRITE(*,*) 'Wrong username or hostname'
!!$ STOP
!!$ ELSE
!!$ WRITE(*,*) 'PARDISO license check was successful ... '
!!$ END IF
! check about existing factorization
IF (factorization_exists .AND. iopt .EQ. 1) THEN ! free memory first
IF (sparse_solve_method .EQ. 1) THEN ! SuperLU
IF (pcol_modified) THEN
CALL sparse_solve_superlu(nrow,ncol,nz,irow,pcoln,val,b,3)
ELSE
CALL sparse_solve_superlu(nrow,ncol,nz,irow,pcol,val,b,3)
END IF
! SuiteSparse (with (=2) or without (=3)) iterative refinement
ELSE IF ( (sparse_solve_method .EQ. 2) .OR. (sparse_solve_method .EQ. 3) ) THEN
IF (pcol_modified) THEN
CALL sparse_solve_suitesparse(nrow,ncol,nz,irow,pcoln,val,b,3)
ELSE
CALL sparse_solve_suitesparse(nrow,ncol,nz,irow,pcol,val,b,3)
END IF
!!$ !ToDo: Please uncomment, when PARDISO is desired
!!$ ELSE IF (sparse_solve_method .EQ. 4) THEN ! PARDISO
!!$ IF (pcol_modified) THEN
!!$ CALL sparse_solve_pardiso(nrow,ncol,nz,irow,pcoln,val,b,3,omp_num_threads)
!!$ ELSE
!!$ CALL sparse_solve_pardiso(nrow,ncol,nz,irow,pcol,val,b,3,omp_num_threads)
!!$ END IF
END IF
END IF
IF (.NOT. factorization_exists .AND. iopt .EQ. 2) THEN ! factorize first
IF (sparse_solve_method .EQ. 1) THEN ! SuperLU
IF (pcol_modified) THEN
CALL sparse_solve_superlu(nrow,ncol,nz,irow,pcoln,val,b,1)
ELSE
CALL sparse_solve_superlu(nrow,ncol,nz,irow,pcol,val,b,1)
END IF
! SuiteSparse (with (=2) or without (=3)) iterative refinement
ELSE IF ( (sparse_solve_method .EQ. 2) .OR. (sparse_solve_method .EQ. 3) ) THEN
IF (pcol_modified) THEN
CALL sparse_solve_suitesparse(nrow,ncol,nz,irow,pcoln,val,b,1)
ELSE
CALL sparse_solve_suitesparse(nrow,ncol,nz,irow,pcol,val,b,1)
END IF
!!$ !ToDo: Please uncomment, when PARDISO is desired
!!$ ELSE IF (sparse_solve_method .EQ. 4) THEN ! PARDISO
!!$ IF (pcol_modified) THEN
!!$ CALL sparse_solve_pardiso(nrow,ncol,nz,irow,pcoln,val,b,1,omp_num_threads)
!!$ ELSE
!!$ CALL sparse_solve_pardiso(nrow,ncol,nz,irow,pcol,val,b,1,omp_num_threads)
!!$ END IF
END IF
factorization_exists = .TRUE.
END IF
IF (iopt .EQ. 1) factorization_exists = .TRUE.
IF (iopt .EQ. 3) factorization_exists = .FALSE.
IF (sparse_solve_method .EQ. 1) THEN ! SuperLU
IF (pcol_modified) THEN
CALL sparse_solve_superlu(nrow,ncol,nz,irow,pcoln,val,b,iopt)
ELSE
CALL sparse_solve_superlu(nrow,ncol,nz,irow,pcol,val,b,iopt)
END IF
! SuiteSparse (with (=2) or without (=3)) iterative refinement
ELSE IF ( (sparse_solve_method .EQ. 2) .OR. (sparse_solve_method .EQ. 3) ) THEN
IF (pcol_modified) THEN
CALL sparse_solve_suitesparse(nrow,ncol,nz,irow,pcoln,val,b,iopt)
ELSE
CALL sparse_solve_suitesparse(nrow,ncol,nz,irow,pcol,val,b,iopt)
END IF
!!$ !ToDo: Please uncomment, when PARDISO is desired
!!$ ELSE IF (sparse_solve_method .EQ. 4) THEN ! PARDISO
!!$ IF (pcol_modified) THEN
!!$ CALL sparse_solve_pardiso(nrow,ncol,nz,irow,pcoln,val,b,iopt,omp_num_threads)
!!$ ELSE
!!$ CALL sparse_solve_pardiso(nrow,ncol,nz,irow,pcol,val,b,iopt,omp_num_threads)
!!$ END IF
ELSE
PRINT *, 'sparse_solve_method ',sparse_solve_method,'not implemented'
STOP
END IF
IF (ALLOCATED(pcoln)) DEALLOCATE(pcoln)
RETURN
END SUBROUTINE sparse_solveReal_b1
!-------------------------------------------------------------------------------
!-------------------------------------------------------------------------------
! solves A*x = b for sparse A and 1-D vector b
! A is specified through nrow,ncol,nz,irow,pcol,val
! results are returned in b
SUBROUTINE sparse_solveComplex_b1(nrow,ncol,nz,irow,pcol,val,b,iopt_in)
INTEGER, INTENT(in) :: nrow,ncol,nz
INTEGER, DIMENSION(:), INTENT(in) :: irow,pcol
COMPLEX(kind=dp), DIMENSION(:), INTENT(in) :: val
COMPLEX(kind=dp), DIMENSION(:), INTENT(inout) :: b
INTEGER, INTENT(in), OPTIONAL :: iopt_in
INTEGER :: iopt = 0
INTEGER, DIMENSION(:), ALLOCATABLE :: pcoln
LOGICAL :: pcol_modified = .FALSE.
!optional input
IF (PRESENT(iopt_in)) iopt = iopt_in
! make sure that pcol is a pointer, otherwise create pcoln
IF (SIZE(pcol,1) .EQ. SIZE(irow,1)) THEN
CALL column_full2pointer(pcol,pcoln)
pcol_modified = .TRUE.
END IF
!!$ !ToDo: Please uncomment, when PARDISO is desired
!!$ mtype=13 ! complex unsymmetric
!!$ CALL pardisoinit(pt, mtype, pardiso_solver, iparm, dparm, error_pardiso)
!!$ IF (error_pardiso .NE. 0) THEN
!!$ IF (error_pardiso.EQ.-10 ) WRITE(*,*) 'No license file found'
!!$ IF (error_pardiso.EQ.-11 ) WRITE(*,*) 'License is expired'
!!$ IF (error_pardiso.EQ.-12 ) WRITE(*,*) 'Wrong username or hostname'
!!$ STOP
!!$ ELSE
!!$ WRITE(*,*) 'PARDISO license check was successful ... '
!!$ END IF
! check about existing factorization
IF (factorization_exists .AND. iopt .EQ. 1) THEN ! free memory first
IF (sparse_solve_method .EQ. 1) THEN ! SuperLU