forked from Trovemaster/PDSYEV
-
Notifications
You must be signed in to change notification settings - Fork 0
/
diag_pdsyev_write_vec.f90
980 lines (913 loc) · 30 KB
/
diag_pdsyev_write_vec.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
module d_module
!dec$ define blacs_ = 1
!dec$ define mpi_ = 0
use accuracy
use timer
implicit none
public FLReadInput
!
integer(ik),parameter:: verbose = 4
integer, parameter :: trk = selected_real_kind(12)
character(len=cl) :: matrix_file='matrix'
!
integer(ik),parameter :: maxnprocs=1024
integer(ik) :: iterout = 100
!
logical :: print_vectors = .false.
!
real(rk) :: walltime=1e7,time_factor = 0.95
!
real(trk):: rtime
!
contains
!
subroutine FLReadInput(Jrot,gamma,factor,nroots,tol,sparse,eigensolver,chkpoint,zpe,memory,energy_thresh,coef_thresh,cheap)
!
use input
!
integer(ik),intent(out) :: Jrot,gamma,nroots,chkpoint,eigensolver
logical,intent(out) :: sparse,cheap
!
integer :: sparse_
!
real(rk),intent(out) :: factor,tol,memory,zpe,energy_thresh,coef_thresh
character(len=cl) :: diagonalizer
!
character(len=cl) :: w
!
logical :: eof
!
write(out,"('Read the input')")
!
sparse = 0
!
jrot = -1
gamma = -1
nroots = 1e6
energy_thresh = 1.0d+05
coef_thresh = 1.0d-16
diagonalizer = "PDSYEVD"
factor = 1.0_rk
tol = small_
sparse = .false.
cheap = .false.
walltime = safe_max
zpe = -small_
memory = 256.0_rk
!
call input_options(echo_lines=.true.,error_flag=1)
!
! read the general input
!
do
call read_line(eof) ; if (eof) exit
call readu(w)
select case(w)
case("STOP","FINISH","END")
exit
case("")
print "(1x)" ! Echo blank lines
!
case ("J","JROT")
!
call readi(jrot)
!
case ("GAMMA","SYM","SYMMETRY")
!
call readi(gamma)
!
case ("ZPE")
!
call readf(zpe)
!
case ("ENERGY_THRESH")
!
call readf(energy_thresh)
!
case ("COEF_THRESH")
!
call readf(coef_thresh)
!
case ("FACTOR")
!
call readf(factor)
!
case ("CHECKPOINT")
!
! chkpoint : 0 - none, 1 - save, 2 - read
!
call readi(chkpoint)
!
if (chkpoint<0.or.chkpoint>2) then
!
write (out,"(' Illegal checkpoint value = ',i)") chkpoint
stop 'Illegal checkpoint value '
!
endif
!
case ("WALLCLOCK","MAXTIME","WALLTIME")
!
call readf(walltime)
!
! convert to seconds
!
walltime = walltime*3600.0_rk
!
case ("MEMORY","MEM")
!
call readf(memory)
!
case ("NROOTS")
!
call readi(nroots)
!
case ("ITEROUT")
!
call readi(iterout)
!
case ("TOL","TOLARENCE")
!
call readf(tol)
!
case ("SPARSE")
!
!call readi(sparse_)
!
sparse = .true.
!
case ("SPARSE_CHEAP")
!
!call readi(sparse_)
!
sparse = .true.
cheap = .true.
!
case ("DIAGONALIZER")
!
call readu(diagonalizer)
!
select case ( trim(diagonalizer) )
!
case ('PDSYEVD')
!
eigensolver = 1
!
case ('PDSYEVX')
!
eigensolver = 2
!
case default
!
write(out,'("Uknown eigensolver = ",a)'), diagonalizer
stop "Uknown eigensolver = "
!
end select
!
case default
call report ("Principal keyword "//trim(w)//" not recognized",.true.)
end select
!
end do
!
write(out,"('...done!')")
!
end subroutine FLReadInput
end module d_module
program diag_pdsyev
use accuracy
use d_module
use timer
implicit none
!integer(ik) :: verbose=6
!include 'mpif.h'
! Related to matrix reading
integer(ik) :: jrot, gamma, chkptIO,e_chkptIO, info, i, j, i_loc, j_loc, iroot, idimen, jdimen
character(cl) :: jchar, symchar, filename, buf,bterm_filename,current_filename
integer(hik) matsize
integer(ik) dimen_s, nelem, max_nelem
integer(ik), allocatable :: bterm(:,:)
real(rk), allocatable :: a_temp(:), a_loc(:,:)
real(rk) :: thresh=30000.0_rk, zpe, energy_thresh, coef_thresh
! Related to diagonalization
integer(ik) :: nroots
! Parameters
integer(ik) lwork, liwork
double precision zero, t1, t2, work_(10)
parameter ( zero = 0.0d0 )
integer(ik) loc_r, loc_c, lda
double precision mone
integer(ik) maxprocs
parameter ( mone = -1.0d0, maxprocs = 512 )
! Local Scalars
integer(ik) context, iam, m, mycol, myrow, nb, npcol, nprocs, nprow, nz, trilwmin, proc_row, proc_col,iwork_(10),l_nrows, l_ncols, l_eigvec, iprow, ipcol,maxterm
double precision maxcontrib
! Local Arrays
integer(ik) desca(50), descz(50), irecl
integer(ik), allocatable :: iwork(:)
double precision, allocatable :: work(:), w(:), z_loc(:,:), eigvec(:), local_vecs(:)
!
double precision :: vl,vu
integer(ik) :: il,iu,nvals,nvects,nvalsmax,nvals_,nvects_,chkpoint,eigensolver
!
real(rk) :: gfactor,tol,memory_now,memory_max,memory
!
logical :: sparse = .false.
logical :: cheap = .false.
!
integer(ik), external :: numroc, iceil
real(rk), external :: MPI_Wtime, pdlamch
!real(rk), external :: pdlamch
!
character(len=1) :: range
!
real(rk) :: abstol,orfac
integer(ik),allocatable :: iclustr(:),ifail(:)
real(rk),allocatable :: gap(:)
!
character(len=cl) :: unitfname
character(len=4) :: str_row,str_col
!
!call setrteopts("ufmt_littleendian=10") ! on-the-fly Intel -> IBM binaries conversion
!
! -------------------- !
! setup processor grid !
! -------------------- !
!
call blacs_pinfo(iam, nprocs)
!
if ( verbose>=4 ) write(out,"('iam = ',i4)") iam
!
do i=1,int( sqrt( dble(nprocs) ) + 1 )
if(mod(nprocs,i) .eq. 0) nprow = i
end do
npcol = nprocs/nprow
!
call blacs_get( -1, 0, context )
call blacs_gridinit( context, 'r', nprow, npcol )
call blacs_gridinfo( context, nprow, npcol, myrow, mycol )
!
if (verbose>=4) then
!
do i=0,nprocs-1
call blacs_barrier(context, 'a')
if (iam .eq. i) then
write(out,"(/'PE = ',i4,':',i4,' Grid-coord (',i4,',',i4,') PROW = ',i4,':',i4,' PCOL = ',i4,':',i4)") iam,nprocs,myrow,mycol,myrow,nprow,mycol,npcol
endif
enddo
endif
!
call blacs_barrier(context, 'a')
!
! --------------- !
! read input file !
! --------------- !
!
if (iam==0) then
!
call FLReadInput(Jrot,gamma,gfactor,nroots,tol,sparse,eigensolver,chkpoint,zpe,memory,energy_thresh,coef_thresh,cheap)
!
if (verbose>=4) write (out,"(' iam = ',i8,' gfactor = ',f20.8)") iam,gfactor
!
if (verbose>=4) write(out,"(' Only for iam = ',i,' jrot,gamma,nroots,chkpoint,cheap ',6i8)"), iam,jrot,gamma,nroots,chkpoint,cheap
!
endif
!
!dec$ if (blacs_ > 0)
!
call blacs_barrier(context,'A')
!
if (iam==0.and.verbose>=5) write(out,"(' destributing parameters...')")
!
if (verbose>=6) write(out,"(' iam = ',i4)") iam
!
if ( (myrow.eq.0) .and. (mycol.eq.0) ) then
call igebs2d(context, 'all', 'i-ring', 1, 1, eigensolver, 1 )
call igebs2d(context, 'all', 'i-ring', 1, 1, nroots, 1 )
call igebs2d(context, 'all', 'i-ring', 1, 1, sparse, 1 )
call igebs2d(context, 'all', 'i-ring', 1, 1, cheap, 1 )
call igebs2d(context, 'all', 'i-ring', 1, 1, jrot , 1 )
call igebs2d(context, 'all', 'i-ring', 1, 1, gamma, 1 )
call dgebs2d(context, 'all', 'i-ring', 1, 1, walltime, 1 )
call dgebs2d(context, 'all', 'i-ring', 1, 1, zpe, 1 )
call dgebs2d(context, 'all', 'i-ring', 1, 1, energy_thresh, 1 )
call dgebs2d(context, 'all', 'i-ring', 1, 1, coef_thresh, 1 )
call dgebs2d(context, 'all', 'i-ring', 1, 1, tol, 1 )
call dgebs2d(context, 'all', 'i-ring', 1, 1, gfactor, 1 )
call dgebs2d(context, 'all', 'i-ring', 1, 1, memory, 1 )
call igebs2d(context, 'all', 'i-ring', 1, 1, chkpoint, 1 )
else
call igebr2d(context, 'all', 'i-ring', 1, 1, eigensolver, 1, 0, 0 )
call igebr2d(context, 'all', 'i-ring', 1, 1, nroots, 1, 0, 0 )
call igebr2d(context, 'all', 'i-ring', 1, 1, sparse , 1, 0, 0 )
call igebr2d(context, 'all', 'i-ring', 1, 1, cheap , 1, 0, 0 )
call igebr2d(context, 'all', 'i-ring', 1, 1, jrot , 1, 0, 0 )
call igebr2d(context, 'all', 'i-ring', 1, 1, gamma, 1, 0, 0 )
call dgebr2d(context, 'all', 'i-ring', 1, 1, walltime, 1, 0, 0 )
call dgebr2d(context, 'all', 'i-ring', 1, 1, zpe, 1, 0, 0 )
call dgebr2d(context, 'all', 'i-ring', 1, 1, energy_thresh, 1, 0, 0 )
call dgebr2d(context, 'all', 'i-ring', 1, 1, coef_thresh, 1, 0, 0 )
call dgebr2d(context, 'all', 'i-ring', 1, 1, tol, 1, 0, 0 )
call dgebr2d(context, 'all', 'i-ring', 1, 1, gfactor, 1, 0, 0 )
call dgebr2d(context, 'all', 'i-ring', 1, 1, memory, 1, 0, 0 )
call igebr2d(context, 'all', 'i-ring', 1, 1, chkpoint, 1, 0, 0 )
endif
!
if (iam==0.and.verbose>=5) write(out,"(' ...done!')")
!
!if (sparse==1) blacs_init = .true.
!
!dec$ end if
!
! ---------------------------------------------------- !
! read headings and matrix dimensions from matrix file !
! ---------------------------------------------------- !
if ( verbose>=4 ) write(out, '("j,gamma = ",2i4)') jrot,gamma
!
write(jchar, '(i4)') jrot
write(symchar, '(i4)') gamma
!filename = 'bterm'//trim(adjustl(jchar))//'_'//trim(adjustl(symchar))
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! STORE_CHEAP formatting patch here !!
!! Ahmed 5/7/2013 !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
filename = 'matrix'//trim(adjustl(jchar))//'_'//trim(adjustl(symchar))//'.chk'
bterm_filename = 'bterm'//trim(adjustl(jchar))//'_'//trim(adjustl(symchar))
e_chkptIO = 9
!
chkptIO = 10+iam
if(cheap) then
write(out, '(a)') 'Using cheap formatting'
current_filename = bterm_filename
else
current_filename = filename
endif
if ( verbose>=4 ) write(out, '(a)') current_filename
open(chkptIO,form='unformatted',action='read',position='rewind',file=current_filename)
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! End patch !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!
!read(chkptIO) buf(1:11)
!if (buf(1:11)/='Start bterm') then
! write(out, '(/a)') 'error: buf(1:11)/=Start bterm'
! stop
!endif
!
rewind(chkptIO)
!
if (sparse) then
!
read(chkptIO) buf(1:11)
!if ( verbose>=4 ) write(out, '(a)') buf(1:11)
if (buf(1:11)/='Start bterm') then
write(out, '(/a)') 'error: buf(1:11)/= Start bterm'
stop
endif
!
endif
!
read(chkptIO) dimen_s
!
allocate(bterm(dimen_s,2),w(dimen_s),a_temp(dimen_s),stat=info)
call ArrayStart(context,iam,'diag_scalapack:bterm',info,size(bterm),kind(bterm))
call ArrayStart(context,iam,'diag_scalapack:w',info,size(w),kind(w))
call ArrayStart(context,iam,'diag_scalapack:a_temp',info,size(a_temp),kind(a_temp))
!
if (verbose>=3) call MemoryReport(context,iam,memory_now,memory_max)
!
!dec$ if (blacs_ > 0)
call dgsum2d( context,'A', 'i-ring',1,1,memory_now,1,0,0)
call dgsum2d( context,'A', 'i-ring',1,1,memory_max,1,0,0)
!
if (verbose>=3.and.iam==0) write (out,"(t2,'Total memory = ',t47,f18.8,' Gb')") memory_now
if (verbose>=3.and.iam==0) write (out,"(t2,'Maximal memory = ',t47,f18.8,' Gb (',f16.1,')')") memory_max,memory_limit
!
!dec$ end if
!
if (sparse) then
!
read(chkptIO) bterm(1:dimen_s,1:2)
!
!close(chkptIO)
!
!call blacs_barrier(context, 'a')
!
max_nelem = 0
!
do i=1,dimen_s
nelem = bterm(i,2) - bterm(i,1) + 1
!if (iam == 0) then
! write(out,'(/a,i4,a,i4,a,i4)') 'row: ', i, ' bterm(1): ', bterm(i,1), ' bterm(2): ', bterm(i,2)
!endif
if (nelem .gt. max_nelem) then
max_nelem = nelem
endif
enddo
!
else
!
max_nelem = dimen_s
!
endif
!
if (iam == 0.and.verbose>=4) then
write(out,"(/'The matrix of the size ', i16, ' will be read. The maximum number of non-zero elements in a row is ', i16)") dimen_s, max_nelem
endif
!
! --------------------- !
! define the block size !
! --------------------- !
!
nb = min ( dimen_s/nprow, dimen_s/npcol )
nb = min ( nb, 64 )
nb = max(nb,1)
!
! -------------------------------------------------- !
! define local array size and initialize descriptors !
! -------------------------------------------------- !
!
loc_r = numroc(dimen_s,nb,myrow,0,nprow)
loc_c = numroc(dimen_s,nb,mycol,0,npcol)
lda = max (1,loc_r)
!
allocate(a_loc(loc_r,loc_c),z_loc(loc_r,loc_c),stat=info)
matsize = int(loc_r,kind=hik)*int(loc_c,kind=hik)
call ArrayStart(context,iam,'diag_scalapack:a_loc',info,size(a_loc),kind(a_loc),matsize)
call ArrayStart(context,iam,'diag_scalapack:z_loc',info,size(z_loc),kind(z_loc),matsize)
!
!
call descinit( desca, dimen_s, dimen_s, nb, nb, 0, 0, context, lda, info)
call descinit( descz, dimen_s, dimen_s, nb, nb, 0, 0, context, lda, info)
call blacs_barrier(context, 'a')
!
! ---------------------------------------------- !
! read the input matrix in a distributed fassion !
! ---------------------------------------------- !
!
!filename = 'hmat'//trim(adjustl(jchar))//'_'//trim(adjustl(symchar))
!
!open(chkptIO,form='unformatted',action='read',position='rewind',file=filename)
!
!call blacs_barrier(context, 'a')
t1 = MPI_Wtime()
!
!nroots = 0
!
!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! STORE_CHEAP formatting patch here !!
!! Ahmed 5/7/2013 !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!If we're using the cheap mode then we switch back to the matrix file
if(cheap) then
close(chkptIO) !Close the file
open(chkptIO,form='unformatted',action='read',position='rewind',file=filename) !open the matrix file
rewind(chkptIO)
endif
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! End patch !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
read(chkptIO) buf(1:12)
if (buf(1:12)/='Start matrix') then
write(out, '(/a)') 'error: buf(1:12)/= Start matrix'
stop
endif
!
do i=1,dimen_s
!
if (sparse) then
!
read(chkptIO) a_temp(bterm(i,1):bterm(i,2))
!
if (bterm(i,1) > 1) then
!
do j=1,bterm(i,1)-1
!
call infog2l(i, j, desca, nprow, npcol, myrow, mycol, i_loc, j_loc, proc_row, proc_col)
!
if (myrow == proc_row .and. mycol == proc_col) a_loc(i_loc,j_loc) = 0.0d0
!
enddo
!
endif
!
do j=bterm(i,1),bterm(i,2)
!
call infog2l(i, j, desca, nprow, npcol, myrow, mycol, i_loc, j_loc, proc_row, proc_col)
!
if (j <= i) then
!
if (myrow == proc_row .and. mycol == proc_col) a_loc(i_loc,j_loc) = a_temp(j)
!
endif
!
!if (j == i .and. a_temp(j) <= thresh) nroots = nroots + 1
!
enddo
!
else
!
read(chkptIO) a_temp
!
do j=1,dimen_s
!
call infog2l(i, j, desca, nprow, npcol, myrow, mycol, i_loc, j_loc, proc_row, proc_col)
!
if (j <= i) then
!
if (myrow == proc_row .and. mycol == proc_col) a_loc(i_loc,j_loc) = a_temp(j)
!
endif
!
!if (j == i .and. a_temp(j) <= thresh) nroots = nroots + 1
!
enddo
!
endif
!
enddo
!
read(chkptIO) buf(1:10)
if (buf(1:10)/='End matrix') then
write(out, '(/a)') 'error: buf(1:10)/= End matrix'
stop
endif
!
call blacs_barrier(context, 'a')
t2 = MPI_Wtime()
!
if (iam == 0.and.verbose>=4) then
write(out,'(/a,f12.6,a)') 'Time to read and distribute matrix is ',t2-t1,' sec'
endif
!
close(chkptIO)
!
deallocate(a_temp, bterm)
call ArrayStop(context,'diag_scalapack:a_temp')
call ArrayStop(context,'diag_scalapack:bterm')
!
! -------------------------- !
! define remaining workspace !
! -------------------------- !
!
select case (eigensolver)
!
case (1)
!
trilwmin = 3*dimen_s + max( nb*( loc_r+1 ), 3*nb)
!
lwork = max( 1 + 6*dimen_s + 2*loc_r*loc_c, trilwmin) + 2*dimen_s
liwork = 7*dimen_s + 8*npcol + 2
!
allocate(work(lwork), iwork(liwork), stat=info)
call ArrayStart(context,iam,'diag_scalapack:work',info,size(work),kind(work))
call ArrayStart(context,iam,'diag_scalapack:iwork',info,size(iwork),kind(iwork))
!
if (iam == 0.and.verbose>=4) then
write(out,"(/'lwork = ', i16, ' liwork = ', i16, ' lda = ', i16, ' loc_r = ', i16, ' loc_c = ', i16)") lwork, liwork, lda, loc_r, loc_c
endif
!
if (verbose>=4) call MemoryReport(context,iam,memory_now,memory_max)
!
! -------------------------------------------------------------------------------------- !
! do any tests or evaluations here, before calling diagonalization subroutine, if needed !
! -------------------------------------------------------------------------------------- !
!
!lwork = -1
!liwork = -1
!call pdsyevd('V', 'U', dimen_s, a_loc, 1, 1, desca, w, z_loc, 1, 1, descz, work, lwork, iwork, liwork, info)
!write(out,*) 'computed optimal lwork = ', work(1), 'liwork = ', iwork(1)
!call blacs_gridexit(context)
!call blacs_exit(0)
!stop
!
! ---------------------------------------------- !
! call pdsyevd to compute the eigendecomposition !
! ---------------------------------------------- !
!
call blacs_barrier(context, 'a')
if(iam==0) call TimerStart('Diagonalisation')
t1 = MPI_Wtime()
!
!lwork = 10 ; liwork = 10
!
call pdsyevd('V', 'L', dimen_s, a_loc, 1, 1, desca, w, z_loc, 1, 1, descz, work, lwork, iwork, liwork, info)
!
nvals = dimen_s
!
case (2)
!
range = 'I'
!
VL = 0
VU = 1e6
!
IL = 1
IU = nroots
!
nvals = dimen_s
nvects = dimen_s
lwork = -1 ; liwork = -1
!
abstol = 2.0*PDLAMCH(context,'U')
orfac = -1e-4
!
allocate(iclustr(2*nprow*npcol),gap(nprow*npcol),ifail(dimen_s), stat=info)
call ArrayStart(context,iam,'diag_scalapack:iclustr',info,size(iclustr),kind(iclustr))
call ArrayStart(context,iam,'diag_scalapack:gap',info,size(gap),kind(gap))
call ArrayStart(context,iam,'diag_scalapack:ifail',info,size(ifail),kind(ifail))
!
call pdsyevx('V', range, 'L', dimen_s, a_loc, 1, 1, desca, vl, vu, il,iu, abstol, nvals, nvects, w, orfac, z_loc, 1, 1, descz, work_, &
lwork, iwork_, liwork, ifail, iclustr, gap, info)
!
lwork = work_(1)*1.3
liwork = iwork_(1)*1.3
!
if (verbose>=4 ) write(out,"(/'iam = ',i4,' lwork = ', i16, ' liwork = ', i16, ' lda = ', i16)") iam,lwork, liwork, lda
!
allocate(work(lwork), iwork(liwork), stat=info)
call ArrayStart(context,iam,'diag_scalapack:work',info,size(work),kind(work))
call ArrayStart(context,iam,'diag_scalapack:iwork',info,size(iwork),kind(iwork))
!
!if (iam == 0) then
! write(out,"(/'lwork = ', i16, 'liwork = ', i16, 'lda = ', i16, 'loc_r = ', i16, 'loc_c = ', i16)") lwork, liwork, lda, loc_r, loc_c
!endif
!
call pdsyevx('V', range, 'L', dimen_s, a_loc, 1, 1, desca, vl, vu, il,iu, abstol, nvals, nvects, w, orfac, z_loc, 1, 1, descz, &
work, lwork, iwork, liwork, ifail, iclustr, gap, info)
!
if (iam == 0.and.verbose>=4) then
write(out,"(/'nvals = ', i16, 'nvetcs = ', i16)") nvals,nvects
endif
!
case default
!
write(out,'("Uknown eigensolver = ",i)'), eigensolver
stop "Uknown eigensolver = "
!
end select
!
call blacs_barrier(context, 'a')
t2 = MPI_Wtime()
!
! ------------------------------ !
! do tests on convergence if any !
! ------------------------------ !
!
if (iam == 0.and.verbose>=3) then
write(out,"(/'info = ', i8)") info
if (info .eq. 0) then
write(out,"(/'Diagonalization finished successfully!')")
write(out,'(/a,f12.6,a)') 'Time to diagonalize matrix is ',t2-t1,' sec'
else if (info .lt. 0) then
write(out,"(/'Info is less than zero. Info is equal to ', i8)") info
else
write(out,"(/'Info is larger than zero. Info is equal to ', i8)") info
endif
endif
!
! ------------------------------------------- !
! Print or store eigenvalues and eigenvectors !
! ------------------------------------------- !
!
if (iam == 0 .and. info == 0) then
!
write(out,"(/'Computed eigenvalues:')")
!
do i=1,nvals
!
!nroots = nroots + 1
!
write(out,'(f18.8)') w(i)-zpe
!
enddo
!
endif
!
! -------------------------------- !
! Print eigenvectors with PDLAPRNT !
! -------------------------------- !
!
call blacs_barrier(context, 'a')
t1 = MPI_Wtime()
!
!
!open(12,form='unformatted',action='write',file='eigenvectors')
!
write(unitfname,"('eigensolution for j = ',i6,' sym = ',i4)") jrot,gamma
!
call IOStart(trim(unitfname),chkptIO)
!
!
write(str_row,'(i4)') myrow
write(str_col,'(i4)') mycol
!
!
write(jchar, '(i4)') jrot
write(symchar, '(i4)') gamma
!filename = 'solution_'//trim(adjustl(jchar))//'_'//trim(adjustl(symchar))//'_'//trim(adjustl(str_row))//'_'//trim(adjustl(str_col))//'.chk'
!----------------------------------------------------------------------------------------------------------------
! PRINT SOLUTION
!
!----------------------------------------------------------------------------------------------------------------
!------------------New print solution patch that directly exports vectors----------------------------------------
!---------------------------by Ahmed Al-Refaie-------------------------------------------------------------------
!----------------------------------------------------------------------------------------------------------------
call blacs_barrier(context, 'a')
!
filename = 'energies'//trim(adjustl(jchar))//'_'//trim(adjustl(symchar))//'.chk'
!Allocate space for vectors
allocate(local_vecs(dimen_s), stat=info)
call ArrayStart(context,iam,'diag_scalapack:local_vecs',info,size(local_vecs),kind(local_vecs))
!call ArrayStart(context,iam,'diag_scalapack:global_vecs',info,size(global_vecs),kind(global_vecs));
!
if(myrow==0 .and. mycol==0) then
write(out, '(/1x,a,1x,a,1x,a,1x,i3)') 'write eigenvectors into file=', trim(filename), 'iounit=', chkptIO
!
open(e_chkptIO, form='unformatted', action='write', status='unknown', position='rewind', file=filename, buffered='yes')
!
if (info/=0) then
write(out, '(/a,1x,a)') 'error while opening file=', trim(filename)
stop
endif
!
nvals = 0
do idimen=1, dimen_s
if (abs(w(idimen)-zpe)<=energy_thresh) then
nvals = nvals + 1
else
exit
endif
enddo
!
!write(chkptIO) nprow, npcol
write(e_chkptIO) 'Start energies'
write(e_chkptIO) dimen_s, nvals
write(e_chkptIO) w(1:nvals)
write(e_chkptIO) 'Start contrib'
!close(chkptIO)
filename = 'j0eigen_vectors'//trim(adjustl(jchar))//'_'//trim(adjustl(symchar))//'.chk'
if(iam==0) open(chkptIO, form='unformatted',access='STREAM',action='write',position='rewind',status='unknown', file=filename)
endif
!
if ( (myrow.eq.0) .and. (mycol.eq.0) ) then
call igebs2d(context, 'all', 'i-ring', 1, 1, nvals, 1 )
else
call igebr2d(context, 'all', 'i-ring', 1, 1, nvals, 1, 0, 0 )
endif
!
do jdimen=1, nvals
!Clear the local_vector
local_vecs=0
!
do idimen=1, dimen_s
!
call infog2l(idimen, jdimen, descz, nprow, npcol, myrow, mycol, i, j, iprow, ipcol)
!
if (myrow==iprow .and. mycol==ipcol) then
!
!if (abs(z_loc(i,j))>=coef_thresh)
!if (abs(z_loc(i,j))>=coef_thresh)
local_vecs(idimen) = z_loc(i,j)
!write(chkptIO) idimen, jdimen, z_loc(i,j)
!
endif
!
enddo
!Gather all vectors
if(iam==0) write(out,'(/a,i)') 'writing column ',jdimen
call dgsum2d(context, 'all', ' ', dimen_s, 1, local_vecs, -1, -1, 0 )
!CALL DGAMX2D( context, 'All', ' ', size(local_vecs), 1, local_vecs, 1, 0, 0 )
if(iam==0) then
write(chkptIO) local_vecs
maxcontrib=0
do i=1,dimen_s
if (abs(local_vecs(i))>=maxcontrib) then
maxcontrib = abs(local_vecs(i))
maxterm = i
endif
enddo
write(e_chkptIO) maxterm,maxcontrib
endif
!
enddo
!
! write(chkptIO) 'End vectors'
!
call blacs_barrier(context, 'a')
!
t2 = MPI_Wtime()
!
if (iam == 0.and.verbose>=4) then
write(out,'(/a,f12.6,a)') 'Time to write vectors: ',t2-t1,' sec'
endif
!
if(iam==0) close(chkptIO)
if(iam==0) close(e_chkptIO)
!
write(out, '(1x,a,1x,i3)') 'done for iounit=', chkptIO
!
call blacs_barrier(context, 'a')
!
!--------------------------------------------------------------------------
!
!write(chkptIO,*) dimen_s, nprow, npcol, myrow, mycol, loc_r, loc_c
!
!write(chkptIO,*) myrow, mycol, loc_r, loc_r,nroots
!
!write(chkptIO,*) 'Start vectors'
!write(chkptIO,*) z_loc
!write(chkptIO,*) 'End vectors'
!
!
call blacs_barrier(context, 'A')
!
!filename = 'solution_'//trim(adjustl(jchar))//'_'//trim(adjustl(symchar))//'_'//trim(adjustl(str_row))//'_'//trim(adjustl(str_col))//'.tmp'
!write(out, '(/1x,a,1x,a,1x,a,1x,i3)') 'write eigenvectors into file=', trim(filename), 'iounit=', chkptIO
!!
!open(chkptIO, action='write', status='unknown', position='rewind', file=filename, iostat=info)
!write(chkptIO,*) myrow, mycol, loc_r, loc_r,nroots
!write(chkptIO,*) 'Start vectors'
!write(chkptIO,*) z_loc(:,1:nroots)
!write(chkptIO,*) 'End vectors'
!
!if (myrow==0.and.mycol==0) then
! !
! !open(chkptIO,form='unformatted',action='write',position='rewind',status='replace',file=filename)
! !
! write(chkptIO,*) 'Start energies'
! write(chkptIO,*) dimen_s,nvals
! write(chkptIO,*) w(1:nvals)
! write(chkptIO,*) 'End energies'
! !
! !write(chkptIO) 'Start vectors'
! !
!endif
!
!close(chkptIO)
!call blacs_barrier(context, 'a')
!
!do j=1,nvals
! !
! do i=1,dimen_s
! !
! call infog2l(i, j, descz, nprow, npcol, myrow, mycol, i_loc, j_loc, proc_row, proc_col)
! !
! if (myrow == proc_row .and. mycol == proc_col) write(2000,"(2i8,2x,g26.18)") i,j,z_loc(i_loc,j_loc)
! !
! enddo
! !
! !
!enddo
!
!call pdlaprnt(dimen_s, dimen_s, z_loc, 1, 1, descz, 0, 0, 'A', chkptIO, work)
!
!call pdlaprnt_local(dimen_s, dimen_s, z_loc, 1, 1, descz, 0, 0, 'A', 12, work)
!
!close(12)
!
!nvals,nvects
!dec$ if (blacs_ > 0)
if ( iam==0 ) then
write(out,"('Distrubuting nvals = ',i8,' and nvects = ',i4)") nvals,nvects
call igebs2d(context, 'all', 'i-ring', 1, 1,nvals, 1 )
call igebs2d(context, 'all', 'i-ring', 1, 1,nvects, 1 )
else
call igebr2d(context, 'all', 'i-ring', 1, 1,nvals_, 1, 0, 0 )
call igebr2d(context, 'all', 'i-ring', 1, 1,nvects_, 1, 0, 0 )
!
if (nvals/=nvals_.or.nvects/=nvects_) then
!
write(out,"('nvals = ',i8,' or nvects from ',i4,' do not agree with values from iam = 0: ',i8)") nvals_,nvects_,iam,nvals,nvects
!
stop 'nvals do not agree'
!
endif
!
endif
!dec$ endif
!
call blacs_barrier(context, 'a')
t2 = MPI_Wtime()
!
!if (iam == 0.and.verbose>=4) then
! write(out,'(/a,f12.6,a)') 'Time to print vectors with PDLAPRNT is ',t2-t1,' sec'
!endif
!
deallocate(a_loc, z_loc, work, iwork, w)
call ArrayStop(context,'diag_scalapack:work')
call ArrayStop(context,'diag_scalapack:iwork')
call ArrayStop(context,'diag_scalapack:a_loc')
call ArrayStop(context,'diag_scalapack:z_loc')
call ArrayStop(context,'diag_scalapack:w')
!
! Exit BLACS
!
if (verbose>=3) call MemoryReport(context,iam,memory_now,memory_max)
if (verbose>=3) write(out,"('Cleaning up BLACS')")
!
call blacs_gridexit(context)
call blacs_exit(0)
!
end program diag_pdsyev