forked from HLRA-JHPCN/HACApK-MAGMA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
m_HACApK_solve.f90
executable file
·998 lines (963 loc) · 37.2 KB
/
m_HACApK_solve.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
!=====================================================================*
! *
! Software Name : HACApK *
! Version : 1.0.0 *
! *
! License *
! This file is part of HACApK. *
! HACApK is a free software, you can use it under the terms *
! of The MIT License (MIT). See LICENSE file and User's guide *
! for more details. *
! *
! ppOpen-HPC project: *
! Open Source Infrastructure for Development and Execution of *
! Large-Scale Scientific Applications on Post-Peta-Scale *
! Supercomputers with Automatic Tuning (AT). *
! *
! Sponsorship: *
! Japan Science and Technology Agency (JST), Basic Research *
! Programs: CREST, Development of System Software Technologies *
! for post-Peta Scale High Performance Computing. *
! *
! Copyright (c) 2015 <Akihiro Ida and Takeshi Iwashita> *
! *
!=====================================================================*
!C***********************************************************************
!C This file includes routines for utilizing H-matrices, such as solving
!C linear system with an H-matrix as the coefficient matrix and
!C multiplying an H-matrix and a vector,
!C created by Akihiro Ida at Kyoto University on May 2012,
!C last modified by Akihiro Ida on Sep 2014,
!C***********************************************************************
module m_HACApK_solve
use m_HACApK_base
implicit real*8(a-h,o-z)
implicit integer*4(i-n)
contains
!***HACApK_adot_lfmtx_p
subroutine HACApK_adot_lfmtx_p(zau,st_leafmtxp,st_ctl,zu,nd)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: zau(nd),zu(nd)
real*8,dimension(:),allocatable :: wws,wwr
integer*4 :: ISTATUS(MPI_STATUS_SIZE),isct(2),irct(2)
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
ndnr_s=lpmd(6); ndnr_e=lpmd(7); ndnr=lpmd(5)
allocate(wws(maxval(lnp(0:nrank-1))),wwr(maxval(lnp(0:nrank-1))))
zau(:)=0.0d0
call HACApK_adot_body_lfmtx(zau,st_leafmtxp,st_ctl,zu,nd)
if(nrank==1) return
wws(1:lnp(mpinr))=zau(lsp(mpinr):lsp(mpinr)+lnp(mpinr)-1)
ncdp=mod(mpinr+1,nrank)
ncsp=mod(mpinr+nrank-1,nrank)
! write(mpilog,1000) 'destination process=',ncdp,'; source process=',ncsp
isct(1)=lnp(mpinr);isct(2)=lsp(mpinr);
! irct=lnp(ncsp)
do ic=1,nrank-1
! idp=mod(mpinr+ic,nrank) ! rank of destination process
! isp=mod(mpinr+nrank+ic-2,nrank) ! rank of source process
call MPI_SENDRECV(isct,2,MPI_INTEGER,ncdp,1, &
irct,2,MPI_INTEGER,ncsp,1,icomm,ISTATUS,ierr)
! write(mpilog,1000) 'ISTATUS=',ISTATUS,'; ierr=',ierr
! write(mpilog,1000) 'ic=',ic,'; isct=',isct(1),'; irct=',irct(1),'; ivsps=',isct(2),'; ivspr=',irct(2)
call MPI_SENDRECV(wws,isct,MPI_DOUBLE_PRECISION,ncdp,1, &
wwr,irct,MPI_DOUBLE_PRECISION,ncsp,1,icomm,ISTATUS,ierr)
! write(mpilog,1000) 'ISTATUS=',ISTATUS,'; ierr=',ierr
zau(irct(2):irct(2)+irct(1)-1)=zau(irct(2):irct(2)+irct(1)-1)+wwr(:irct(1))
wws(:irct(1))=wwr(:irct(1))
isct=irct
! write(mpilog,1000) 'ic=',ic,'; isct=',isct
enddo
deallocate(wws,wwr)
end subroutine HACApK_adot_lfmtx_p
!***HACApK_adot_cax_lfmtx_hyp
subroutine HACApK_adot_cax_lfmtx_hyp(zau,st_leafmtxp,st_ctl,zu,wws,wwr,isct,irct,nd, &
time_batch, time_set, time_copy, time_spmv, time_mpi)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: zau(*),zu(*),wws(*),wwr(*)
real*8 time_spmv, time_mpi, time_batch, time_set, time_copy, tic
integer*4 :: isct(*),irct(*)
integer*4 :: ISTATUS(MPI_STATUS_SIZE)
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
zau(:nd)=0.0d0
tic = MPI_Wtime()
#if defined(BICG_MAGMA_BATCH)
call c_HACApK_adot_body_lfmtx_batch(zau,st_leafmtxp,zu,wws, time_batch,time_set,time_copy)
#elif defined(BICG_MAGMA)
call c_HACApK_adot_body_lfmtx_gpu(zau,st_leafmtxp,zu,wws)
#else
call c_HACApK_adot_body_lfmtx(zau,st_leafmtxp,zu,wws)
#endif
time_spmv = time_spmv + (MPI_Wtime()-tic)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;
mpinr=lpmd(3); nrank=lpmd(2); icomm=lpmd(1)
if(nrank>1)then
wws(1:lnp(mpinr))=zau(lsp(mpinr):lsp(mpinr)+lnp(mpinr)-1)
ncdp=mod(mpinr+1,nrank)
ncsp=mod(mpinr+nrank-1,nrank)
isct(1)=lnp(mpinr);isct(2)=lsp(mpinr);
do ic=1,nrank-1
tic = MPI_Wtime()
call MPI_SENDRECV(isct,2,MPI_INTEGER,ncdp,1, &
irct,2,MPI_INTEGER,ncsp,1,icomm,ISTATUS,ierr)
call MPI_SENDRECV(wws,isct,MPI_DOUBLE_PRECISION,ncdp,1, &
wwr,irct,MPI_DOUBLE_PRECISION,ncsp,1,icomm,ISTATUS,ierr)
time_mpi = time_mpi + (MPI_Wtime()-tic)
zau(irct(2):irct(2)+irct(1)-1)=zau(irct(2):irct(2)+irct(1)-1)+wwr(:irct(1))
wws(:irct(1))=wwr(:irct(1))
isct(:2)=irct(:2)
enddo
endif
end subroutine HACApK_adot_cax_lfmtx_hyp
!***HACApK_adot_lfmtx_hyp
subroutine HACApK_adot_lfmtx_hyp(zau,st_leafmtxp,st_ctl,zu,wws,wwr,isct,irct,nd)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: zau(*),zu(*),wws(*),wwr(*)
integer*4 :: isct(*),irct(*)
integer*4 :: ISTATUS(MPI_STATUS_SIZE)
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
! integer*4,dimension(:),allocatable :: ISTATUS
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr
! allocate(ISTATUS(MPI_STATUS_SIZE))
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
ndnr_s=lpmd(6); ndnr_e=lpmd(7); ndnr=lpmd(5)
zau(:nd)=0.0d0
call HACApK_adot_body_lfmtx_hyp(zau,st_leafmtxp,st_ctl,zu,nd)
if(nrank>1)then
wws(1:lnp(mpinr))=zau(lsp(mpinr):lsp(mpinr)+lnp(mpinr)-1)
ncdp=mod(mpinr+1,nrank)
ncsp=mod(mpinr+nrank-1,nrank)
isct(1)=lnp(mpinr);isct(2)=lsp(mpinr);
do ic=1,nrank-1
call MPI_SENDRECV(isct,2,MPI_INTEGER,ncdp,1, &
irct,2,MPI_INTEGER,ncsp,1,icomm,ISTATUS,ierr)
call MPI_SENDRECV(wws,isct(1),MPI_DOUBLE_PRECISION,ncdp,1, &
wwr,irct(1),MPI_DOUBLE_PRECISION,ncsp,1,icomm,ISTATUS,ierr)
zau(irct(2):irct(2)+irct(1)-1)=zau(irct(2):irct(2)+irct(1)-1)+wwr(:irct(1))
wws(:irct(1))=wwr(:irct(1))
isct(:2)=irct(:2)
enddo
endif
! stop
end subroutine HACApK_adot_lfmtx_hyp
!***HACApK_adot_body_lfmtx
RECURSIVE subroutine HACApK_adot_body_lfmtx(zau,st_leafmtxp,st_ctl,zu,nd)
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: zau(nd),zu(nd)
real*8,dimension(:),allocatable :: zbu
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr
nlf=st_leafmtxp%nlf
do ip=1,nlf
ndl =st_leafmtxp%st_lf(ip)%ndl ; ndt =st_leafmtxp%st_lf(ip)%ndt ; ns=ndl*ndt
nstrtl=st_leafmtxp%st_lf(ip)%nstrtl; nstrtt=st_leafmtxp%st_lf(ip)%nstrtt
if(st_leafmtxp%st_lf(ip)%ltmtx==1)then
kt=st_leafmtxp%st_lf(ip)%kt
allocate(zbu(kt)); zbu(:)=0.0d0
do il=1,kt
do it=1,ndt; itt=it+nstrtt-1
zbu(il)=zbu(il)+st_leafmtxp%st_lf(ip)%a1(it,il)*zu(itt)
enddo
enddo
do il=1,kt
do it=1,ndl; ill=it+nstrtl-1
zau(ill)=zau(ill)+st_leafmtxp%st_lf(ip)%a2(it,il)*zbu(il)
enddo
enddo
deallocate(zbu)
elseif(st_leafmtxp%st_lf(ip)%ltmtx==2)then
do il=1,ndl; ill=il+nstrtl-1
do it=1,ndt; itt=it+nstrtt-1
zau(ill)=zau(ill)+st_leafmtxp%st_lf(ip)%a1(it,il)*zu(itt)
enddo
enddo
endif
enddo
end subroutine HACApK_adot_body_lfmtx
!***HACApK_adot_body_lfmtx_hyp
subroutine HACApK_adot_body_lfmtx_hyp(zau,st_leafmtxp,st_ctl,zu,nd)
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: zau(*),zu(*)
real*8,dimension(:),allocatable :: zbut
real*8,dimension(:),allocatable :: zaut
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),ltmp(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;ltmp(0:) => st_ctl%lthr
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
nlf=st_leafmtxp%nlf; ktmax=st_leafmtxp%ktmax
! ith = omp_get_thread_num()
ith = 0
ith1 = ith+1
nths=ltmp(ith); nthe=ltmp(ith1)-1
allocate(zaut(nd)); zaut(:)=0.0d0
allocate(zbut(ktmax))
ls=nd; le=1
do ip=nths,nthe
ndl =st_leafmtxp%st_lf(ip)%ndl ; ndt =st_leafmtxp%st_lf(ip)%ndt ; ns=ndl*ndt
nstrtl=st_leafmtxp%st_lf(ip)%nstrtl; nstrtt=st_leafmtxp%st_lf(ip)%nstrtt
if(nstrtl<ls) ls=nstrtl; if(nstrtl+ndl-1>le) le=nstrtl+ndl-1
if(st_leafmtxp%st_lf(ip)%ltmtx==1)then
kt=st_leafmtxp%st_lf(ip)%kt
zbut(1:kt)=0.0d0
do il=1,kt
do it=1,ndt; itt=it+nstrtt-1
zbut(il)=zbut(il)+st_leafmtxp%st_lf(ip)%a1(it,il)*zu(itt)
enddo
enddo
do il=1,kt
do it=1,ndl; ill=it+nstrtl-1
zaut(ill)=zaut(ill)+st_leafmtxp%st_lf(ip)%a2(it,il)*zbut(il)
enddo
enddo
elseif(st_leafmtxp%st_lf(ip)%ltmtx==2)then
do il=1,ndl; ill=il+nstrtl-1
do it=1,ndt; itt=it+nstrtt-1
zaut(ill)=zaut(ill)+st_leafmtxp%st_lf(ip)%a1(it,il)*zu(itt)
enddo
enddo
endif
enddo
deallocate(zbut)
do il=ls,le
zau(il)=zau(il)+zaut(il)
enddo
end subroutine HACApK_adot_body_lfmtx_hyp
!***HACApK_adotsub_lfmtx_p
subroutine HACApK_adotsub_lfmtx_p(zr,st_leafmtxp,st_ctl,zu,nd)
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: zu(nd),zr(nd)
real*8,dimension(:),allocatable :: zau
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr;
allocate(zau(nd))
call HACApK_adot_lfmtx_p(zau,st_leafmtxp,st_ctl,zu,nd)
zr(1:nd)=zr(1:nd)-zau(1:nd)
deallocate(zau)
end subroutine HACApK_adotsub_lfmtx_p
!***HACApK_adotsub_lfmtx_hyp
subroutine HACApK_adotsub_lfmtx_hyp(zr,zau,st_leafmtxp,st_ctl,zu,wws,wwr,isct,irct,nd)
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: zr(*),zau(*),zu(*),wws(*),wwr(*)
integer*4 :: isct(*),irct(*)
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr
call HACApK_adot_lfmtx_hyp(zau,st_leafmtxp,st_ctl,zu,wws,wwr,isct,irct,nd)
zr(1:nd)=zr(1:nd)-zau(1:nd)
end subroutine HACApK_adotsub_lfmtx_hyp
!***HACApK_bicgstab_lfmtx
subroutine HACApK_bicgstab_lfmtx(st_leafmtxp,st_ctl,u,b,param,nd,nstp,lrtrn)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: u(nd),b(nd)
real*8 :: param(*)
real*8,dimension(:),allocatable :: zr,zshdw,zp,zt,zkp,zakp,zkt,zakt
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
call MPI_Barrier( icomm, ierr )
st_measure_time=MPI_Wtime()
if(st_ctl%param(1)>0 .and. mpinr==0) print*,'HACApK_bicgstab_lfmtx start'
mstep=param(83)
eps=param(91)
allocate(zr(nd),zshdw(nd),zp(nd),zt(nd),zkp(nd),zakp(nd),zkt(nd),zakt(nd))
zp(1:nd)=0.0d0; zakp(1:nd)=0.0d0
alpha = 0.0; beta = 0.0; zeta = 0.0;
zz=HACApK_dotp_d(nd, b, b); bnorm=dsqrt(zz);
zr(:nd)=b(:nd)
call HACApK_adotsub_lfmtx_p(zr,st_leafmtxp,st_ctl,u,nd)
zshdw(:nd)=zr(:nd)
zrnorm=HACApK_dotp_d(nd,zr,zr); zrnorm=dsqrt(zrnorm)
if(st_ctl%param(1)>0 .and. mpinr==0) print*,'Original relative residual norm =',zrnorm/bnorm
if(zrnorm/bnorm<eps) return
! mstep=1
do in=1,mstep
zp(:nd) =zr(:nd)+beta*(zp(:nd)-zeta*zakp(:nd))
zkp(:nd)=zp(:nd)
call HACApK_adot_lfmtx_p(zakp,st_leafmtxp,st_ctl,zkp,nd)
! exit
znom=HACApK_dotp_d(nd,zshdw,zr); zden=HACApK_dotp_d(nd,zshdw,zakp);
alpha=znom/zden; znomold=znom;
zt(:nd)=zr(:nd)-alpha*zakp(:nd)
zkt(:nd)=zt(:nd)
call HACApK_adot_lfmtx_p(zakt,st_leafmtxp,st_ctl,zkt,nd)
znom=HACApK_dotp_d(nd,zakt,zt); zden=HACApK_dotp_d(nd,zakt,zakt);
zeta=znom/zden;
u(:nd)=u(:nd)+alpha*zkp(:nd)+zeta*zkt(:nd)
zr(:nd)=zt(:nd)-zeta*zakt(:nd)
beta=alpha/zeta*HACApK_dotp_d(nd,zshdw,zr)/znomold;
zrnorm=HACApK_dotp_d(nd,zr,zr); zrnorm=dsqrt(zrnorm)
call MPI_Barrier( icomm, ierr )
en_measure_time=MPI_Wtime()
time = en_measure_time - st_measure_time
if(st_ctl%param(1)>0 .and. mpinr==0) print*,in,time,log10(zrnorm/bnorm)
if(zrnorm/bnorm<eps) exit
enddo
end subroutine HACApK_bicgstab_lfmtx
!***HACApK_bicgstab_cax_lfmtx_hyp
subroutine HACApK_bicgstab_cax_lfmtx_hyp(st_leafmtxp,st_ctl,u,b,param,nd,nstp,lrtrn)
use iso_fortran_env
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: u(nd),b(nd)
real*8 :: param(*)
real*8,dimension(:),allocatable :: zr,zshdw,zp,zt,zkp,zakp,zkt,zakt
real*8,dimension(:),allocatable :: wws,wwr
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
integer*4 :: isct(2),irct(2)
real*8 time_tot, time_spmv, time_mpi, time_batch, time_set, time_copy, tic
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
call MPI_Barrier( icomm, ierr )
mstep=param(83)
eps=param(91)
allocate(wws(maxval(lnp(0:nrank-1))),wwr(maxval(lnp(0:nrank-1))))
allocate(zr(nd),zshdw(nd),zp(nd),zt(nd),zkp(nd),zakp(nd),zkt(nd),zakt(nd))
alpha = 0.0; beta = 0.0; zeta = 0.0;
zz=HACApK_dotp_d(nd, b, b); bnorm=dsqrt(zz);
zp(1:nd)=0.0d0; zakp(1:nd)=0.0d0
zr(:nd)=b(:nd)
call HACApK_adotsub_lfmtx_hyp(zr,zshdw,st_leafmtxp,st_ctl,u,wws,wwr,isct,irct,nd)
zshdw(:nd)=zr(:nd)
zrnorm=HACApK_dotp_d(nd,zr,zr); zrnorm=dsqrt(zrnorm)
if(mpinr==0) flush(output_unit)
if(mpinr==0) print*,' '
#if defined(BICG_MAGMA_BATCH)
if(mpinr==0) print*,' ** BICG with MAGMA batched (Fortran)**'
#if defined(REALLOCATE_MAGMA_BATCH)
call c_HACApK_adot_body_lfcpy_batch_sorted(nd,st_leafmtxp)
#endif
#elif defined(BICG_MAGMA)
if(mpinr==0) print*,' ** BICG with BLAS (MAGMA or MKL) **'
call c_HACApK_adot_body_lfcpy_gpu(nd,st_leafmtxp)
#else
if(mpinr==0) print*,' ** BICG, original **'
#endif
if(mpinr==0) print*,' '
if(mpinr==0) print*,'Original relative residual norm =',zrnorm/bnorm
if(mpinr==0) flush(output_unit)
time_tot = 0.0
time_spmv = 0.0
time_mpi = 0.0
time_batch = 0.0
time_set = 0.0
time_copy = 0.0
call MPI_Barrier( icomm, ierr )
st_measure_time=MPI_Wtime()
if(st_ctl%param(1)>0 .and. mpinr==0) print*,'HACApK_bicgstab_lfmtx_hyp start'
do in=1,mstep
if(zrnorm/bnorm<eps) exit
zp(:nd) = zr(:nd) + beta*(zp(:nd) - zeta*zakp(:nd))
zkp(:nd) = zp(:nd)
! .. SpMV ..
tic = MPI_Wtime()
call HACApK_adot_cax_lfmtx_hyp(zakp,st_leafmtxp,st_ctl,zkp,wws,wwr,isct,irct,nd, &
time_batch,time_set,time_copy,time_spmv,time_mpi)
time_tot = time_tot + (MPI_Wtime()-tic)
znom = HACApK_dotp_d(nd,zshdw,zr); zden=HACApK_dotp_d(nd,zshdw,zakp);
alpha = znom/zden;
znomold = znom;
zt(:nd) = zr(:nd) - alpha*zakp(:nd)
zkt(:nd) = zt(:nd)
tic = MPI_Wtime()
!call HACApK_adot_lfmtx_hyp (zakt,st_leafmtxp,st_ctl,zkt,wws,wwr,isct,irct,nd)
call HACApK_adot_cax_lfmtx_hyp(zakt,st_leafmtxp,st_ctl,zkt,wws,wwr,isct,irct,nd, &
time_batch,time_set,time_copy,time_spmv,time_mpi)
time_tot = time_tot + (MPI_Wtime()-tic)
znom = HACApK_dotp_d(nd,zakt,zt); zden=HACApK_dotp_d(nd,zakt,zakt);
zeta = znom/zden;
u(:nd) = u(:nd) + alpha*zkp(:nd) + zeta*zkt(:nd)
zr(:nd) = zt(:nd) - zeta*zakt(:nd)
beta = alpha/zeta * HACApK_dotp_d(nd,zshdw,zr)/znomold;
zrnorm = HACApK_dotp_d(nd,zr,zr);
zrnorm = dsqrt(zrnorm)
nstp = in
call MPI_Barrier( icomm, ierr )
en_measure_time = MPI_Wtime()
time = en_measure_time - st_measure_time
2002 format(i,a,1pe8.1,a,1pe8.1)
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2002) in,': time=',time,', log10(zrnorm/bnorm)=',log10(zrnorm/bnorm)
enddo
call MPI_Barrier( icomm, ierr )
en_measure_time = MPI_Wtime()
time = en_measure_time - st_measure_time
#if defined(BICG_MAGMA_BATCH)
call c_HACApK_adot_body_lfdel_batch(st_leafmtxp)
#elif defined(BICG_MAGMA)
call c_HACApK_adot_body_lfdel_gpu(st_leafmtxp)
#endif
2001 format(5(a,1pe15.8)/)
2003 format(5(a,i,a,1pe9.2)/)
!if(st_ctl%param(1) > 0) write(6,2003) ' End: ',mpinr,' ',time
call MPI_Barrier( icomm, ierr )
en_measure_time = MPI_Wtime()
time = en_measure_time - st_measure_time
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' BiCG =',time
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' time_tot =',time_tot
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' time_mpi =',time_mpi
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' time_spmv =',time_spmv
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' > time_copy =',time_copy
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' > time_set =',time_set
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' > time_batch =',time_batch
end subroutine HACApK_bicgstab_cax_lfmtx_hyp
!***HACApK_bicgstab_lfmtx_hyp
subroutine HACApK_bicgstab_lfmtx_hyp(st_leafmtxp,st_ctl,u,b,param,nd,nstp,lrtrn)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: u(nd),b(nd)
real*8 :: param(*)
real*8,dimension(:),allocatable :: zr,zshdw,zp,zt,zkp,zakp,zkt,zakt
real*8,dimension(:),allocatable :: wws,wwr
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
integer*4 :: isct(2),irct(2)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
call MPI_Barrier( icomm, ierr )
st_measure_time=MPI_Wtime()
if(st_ctl%param(1)>0 .and. st_ctl%lpmd(30)==0) print*,'HACApK_bicgstab_lfmtx_hyp start'
mstep=param(83)
eps=param(91)
allocate(wws(maxval(lnp(0:nrank-1))),wwr(maxval(lnp(0:nrank-1))))
allocate(zr(nd),zshdw(nd),zp(nd),zt(nd),zkp(nd),zakp(nd),zkt(nd),zakt(nd))
alpha = 0.0; beta = 0.0; zeta = 0.0;
zz=HACApK_dotp_d(nd, b, b); bnorm=dsqrt(zz);
zp(1:nd)=0.0d0; zakp(1:nd)=0.0d0
zr(:nd)=b(:nd)
call HACApK_adotsub_lfmtx_hyp(zr,zshdw,st_leafmtxp,st_ctl,u,wws,wwr,isct,irct,nd)
zshdw(:nd)=zr(:nd)
zrnorm=HACApK_dotp_d(nd,zr,zr); zrnorm=dsqrt(zrnorm)
if(st_ctl%lpmd(30)==0) print*,'Original relative residual norm =',zrnorm/bnorm
do in=1,mstep
if(zrnorm/bnorm<eps) exit
zp(:nd) =zr(:nd)+beta*(zp(:nd)-zeta*zakp(:nd))
zkp(:nd)=zp(:nd)
call HACApK_adot_lfmtx_hyp(zakp,st_leafmtxp,st_ctl,zkp,wws,wwr,isct,irct,nd)
znom=HACApK_dotp_d(nd,zshdw,zr); zden=HACApK_dotp_d(nd,zshdw,zakp);
alpha=znom/zden; znomold=znom;
zt(:nd)=zr(:nd)-alpha*zakp(:nd)
zkt(:nd)=zt(:nd)
call HACApK_adot_lfmtx_hyp(zakt,st_leafmtxp,st_ctl,zkt,wws,wwr,isct,irct,nd)
znom=HACApK_dotp_d(nd,zakt,zt); zden=HACApK_dotp_d(nd,zakt,zakt);
zeta=znom/zden;
u(:nd)=u(:nd)+alpha*zkp(:nd)+zeta*zkt(:nd)
zr(:nd)=zt(:nd)-zeta*zakt(:nd)
beta=alpha/zeta*HACApK_dotp_d(nd,zshdw,zr)/znomold;
zrnorm=HACApK_dotp_d(nd,zr,zr); zrnorm=dsqrt(zrnorm)
nstp=in
call MPI_Barrier( icomm, ierr )
en_measure_time=MPI_Wtime()
time = en_measure_time - st_measure_time
if(st_ctl%param(1)>0 .and. st_ctl%lpmd(30)==0) print*,in,time,log10(zrnorm/bnorm)
enddo
end subroutine HACApK_bicgstab_lfmtx_hyp
!***HACApK_gcrm_lfmtx
subroutine HACApK_gcrm_lfmtx(st_leafmtxp,st_ctl,st_bemv,u,b,param,nd,nstp,lrtrn)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
type(st_HACApK_calc_entry) :: st_bemv
real*8 :: u(nd),b(nd)
real*8 :: param(*)
real*8,dimension(:),allocatable :: zr,zar,capap
real*8,dimension(:,:),allocatable,target :: zp,zap
real*8,pointer :: zq(:)
real*8,dimension(:),allocatable :: wws,wwr
integer*4 :: isct(2),irct(2)
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
call MPI_Barrier( icomm, ierr )
st_measure_time=MPI_Wtime()
if(st_ctl%param(1)>0 .and. mpinr==0) print*,'gcr_lfmtx_hyp start'
mstep=param(83)
mreset=param(87)
eps=param(91)
allocate(wws(maxval(lnp(0:nrank-1))),wwr(maxval(lnp(0:nrank-1))))
allocate(zr(nd),zar(nd),zp(nd,mreset),zap(nd,mreset),capap(mreset))
alpha = 0.0
zz=HACApK_dotp_d(nd, b, b); bnorm=dsqrt(zz);
call HACApK_adot_lfmtx_hyp(zar,st_leafmtxp,st_ctl,u,wws,wwr,isct,irct,nd)
zr(:nd)=b(:nd)-zar(:nd)
zp(:nd,1)=zr(:nd)
zrnorm2=HACApK_dotp_d(nd,zr,zr); zrnorm=dsqrt(zrnorm2)
call MPI_Barrier( icomm, ierr )
en_measure_time=MPI_Wtime()
time = en_measure_time - st_measure_time
if(st_ctl%param(1)>0 .and. mpinr==0) print*,0,time,log10(zrnorm/bnorm)
if(zrnorm/bnorm<eps) return
call HACApK_adot_lfmtx_hyp(zap(:nd,1),st_leafmtxp,st_ctl,zp(:nd,1),wws,wwr,isct,irct,nd)
do in=1,mstep
ik=mod(in-1,mreset)+1
zq=>zap(:nd,ik)
znom=HACApK_dotp_d(nd,zq,zr); capap(ik)=HACApK_dotp_d(nd,zq,zq)
alpha=znom/capap(ik)
u(:nd)=u(:nd)+alpha*zp(:nd,ik)
zr(:nd)=zr(:nd)-alpha*zq(:nd)
zrnomold=zrnorm2
zrnorm2=HACApK_dotp_d(nd,zr,zr); zrnorm=dsqrt(zrnorm2)
call MPI_Barrier( icomm, ierr )
en_measure_time=MPI_Wtime()
time = en_measure_time - st_measure_time
if(st_ctl%param(1)>0 .and. mpinr==0) print*,in,time,log10(zrnorm/bnorm)
if(zrnorm/bnorm<eps .or. in==mstep) exit
call HACApK_adot_lfmtx_hyp(zar,st_leafmtxp,st_ctl,zr,wws,wwr,isct,irct,nd)
ikn=mod(in,mreset)+1
zp(:nd,ikn)=zr(:nd)
zap(:nd,ikn)=zar(:nd)
do il=1,ik
zq=>zap(:nd,il)
znom=HACApK_dotp_d(nd,zq,zar)
beta=-znom/capap(il)
zp(:nd,ikn) =zp(:nd,ikn)+beta*zp(:nd,il)
zap(:nd,ikn)=zap(:nd,ikn)+beta*zq(:nd)
enddo
enddo
nstp=in
end subroutine
!***HACApK_measurez_time_ax_lfmtx
subroutine HACApK_measurez_time_ax_lfmtx(st_leafmtxp,st_ctl,nd,nstp,lrtrn)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8,dimension(:),allocatable :: wws,wwr,u,b
integer*4 :: isct(2),irct(2)
real*8,pointer :: param(:)
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr; param=>st_ctl%param(:)
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
mstep=param(99)
allocate(u(nd),b(nd),wws(maxval(lnp(0:nrank-1))),wwr(maxval(lnp(0:nrank-1))))
do il=1,mstep
u(:)=1.0; b(:)=1.0
call HACApK_adot_lfmtx_hyp(u,st_leafmtxp,st_ctl,b,wws,wwr,isct,irct,nd)
enddo
deallocate(wws,wwr)
end subroutine HACApK_measurez_time_ax_lfmtx
!***HACApK_measurez_time_ax_FPGA_lfmtx
subroutine HACApK_measurez_time_ax_FPGA_lfmtx(st_leafmtxp,st_ctl,nd,nstp,lrtrn) bind(C)
use, intrinsic :: iso_c_binding
#ifdef HAVE_MAGMA_PINNED
use cudafor
#endif
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
#ifdef HAVE_MAGMA_PINNED
real*8,dimension(:),allocatable, pinned :: wws,wwr,u,v,b
#else
real*8,dimension(:),allocatable :: wws,wwr,u,v,b
#endif
integer*4 :: isct(2),irct(2)
real*8,pointer :: param(:)
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
!!!
type(st_HACApk_leafmtx),pointer :: tmpleafmtx(:)
type(st_HACApk_leafmtxp) :: tmpleafmtxp
pointer (stpt, tmpleafmtxp)
real*8 :: tmptmpa1
real*8 :: enorm,unorm
real*8 :: rnorm_g,enorm_g,unorm_g
character(len=50) :: ErrFormat
pointer (a1pt, tmptmpa1)
integer*8 :: stpt2, a2pt
real*8 time_copy, time_set, time_batch
!!!
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr; param=>st_ctl%param(:)
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
mstep=param(99)
!!!
tmpleafmtx => st_leafmtxp%st_lf
stpt=loc(tmpleafmtx(1))
stpt2 = stpt
stpt = loc(tmpleafmtx(2))
st_leafmtxp%st_lf_stride = stpt-stpt2
do ill=1,st_leafmtxp%nlf
if (tmpleafmtx(ill)%ltmtx == 1) then
a1pt = loc(tmpleafmtx(ill)%a2(:,:))
a2pt = a1pt
a1pt = loc(tmpleafmtx(ill)%a1(:,:))
tmpleafmtx(ill)%a1size =a2pt-a1pt
if (tmpleafmtx(ill)%a1size /= a2pt-a1pt) then
write(*,*)
write(*,*) 'warning :a1size',tmpleafmtx(ill)%a1size, a2pt,a1pt
write(*,*)
endif
endif
enddo
#if defined(HAVE_MAGMA) | defined(HAVE_MAGMA_BATCH)
!!!
call MPI_Comm_rank ( icomm, st_leafmtxp%mpi_rank, ierr )
!!!
allocate(u(nd),v(nd),b(nd),wws(nd))
do il=1,mstep
! >> C function <<
u(:)=1.0; b(:)=1.0
call MPI_Barrier( icomm, ierr )
if (mpinr==0) then
write(*,*) 'calling c_HACApK_adot_body_lfmtx'
endif
call c_HACApK_adot_body_lfmtx(u,st_leafmtxp,b,wws)
enddo
!
do il=1,mstep
#if defined(BICG_MAGMA_MGPU)
if(st_ctl%param(1)>0 .and. mpinr==0) then
write(6,*)
write(6,2000) '** skip; time_FPGA_AX_once with MAGMA for multi-GPU runs **'
write(6,*)
endif
#else
#if defined(HAVE_MAGMA)
v(:)=1.0; b(:)=1.0
call MPI_Barrier( icomm, ierr )
if (mpinr==0) then
write(*,*) 'calling c_HACApK_adot_body_lfcpy_gpu'
endif
call c_HACApK_adot_body_lfcpy_gpu(nd,st_leafmtxp)
call c_HACApK_adot_body_lfmtx_gpu(v,st_leafmtxp,b,wws)
call c_HACApK_adot_body_lfdel_gpu(st_leafmtxp)
unorm = 0.0
do ii=1,st_leafmtxp%m
unorm = unorm + u(ii)*u(ii)
enddo
v = u - v
enorm = 0.0
do ii=1,st_leafmtxp%m
enorm = enorm + v(ii)*v(ii)
enddo
call MPI_Allreduce( enorm, enorm_g, 1, MPI_DOUBLE_PRECISION, MPI_SUM, icomm, ierr )
call MPI_Allreduce( unorm, unorm_g, 1, MPI_DOUBLE_PRECISION, MPI_SUM, icomm, ierr )
enorm_g = dsqrt(enorm_g)
unorm_g = dsqrt(unorm_g)
rnorm_g = enorm_g / unorm_g
if (st_leafmtxp%mpi_rank == 0) then
ErrFormat = "(A16, ES10.3, A3, ES10.3, A3, ES10.3)"
write(*,ErrFormat) ' error(CPU-GPU):' ,enorm_g ,' / ' ,unorm_g ,' = ',rnorm_g
write(*,*)
endif
#endif
!
#ifdef HAVE_MAGMA_BATCH
v(:)=1.0; b(:)=1.0
time_batch = 0.0
time_set = 0.0
time_copy = 0.0
! call c_HACApK_adot_body_lfcpy_batch(st_leafmtxp)
call c_HACApK_adot_body_lfcpy_batch_sorted(nd,st_leafmtxp)
call c_HACApK_adot_body_lfmtx_batch(v,st_leafmtxp,b,wws,time_batch,time_set,time_copy)
#if defined(REALLOCATE_MAGMA_BATCH)
! don't delete it if needed to call BICG
call c_HACApK_adot_body_lfdel_batch(st_leafmtxp)
#endif
unorm = 0.0
do ii=1,st_leafmtxp%m
unorm = unorm + u(ii)*u(ii)
enddo
v = u - v
enorm = 0.0
do ii=1,st_leafmtxp%m
enorm = enorm + v(ii)*v(ii)
enddo
call MPI_Allreduce( enorm, enorm_g, 1, MPI_DOUBLE_PRECISION, MPI_SUM, icomm, ierr )
call MPI_Allreduce( unorm, unorm_g, 1, MPI_DOUBLE_PRECISION, MPI_SUM, icomm, ierr )
enorm_g = dsqrt(enorm_g)
unorm_g = dsqrt(unorm_g)
rnorm_g = enorm_g / unorm_g
if (st_leafmtxp%mpi_rank == 0) then
ErrFormat = "(A16, ES10.3, A3, ES10.3, A3, ES10.3)"
write(*,ErrFormat) ' error(CPU-GPU):' ,enorm_g ,' / ' ,unorm_g ,' = ',rnorm_g
write(*,*)
endif
#endif
#endif
enddo
if (st_leafmtxp%mpi_rank == 0) print*,'c_HACApK_adot_body_lfmtx end'
deallocate(wws)
#endif // #if defined(HAVE_MAGMA | HAVE_MAGMA_BATCH)
!
#ifdef HAVE_PaRSEC
allocate(u(nd),b(nd),wws(nd))
u(:)=1.0; b(:)=1.0
call c_HACApK_PaRSEC(1,1,u,st_leafmtxp,b,wws)
#endif
end subroutine HACApK_measurez_time_ax_FPGA_lfmtx
!
!
!***HACApK_measurez_time_ax_FPGA_lfmtx
subroutine HACApK_measurez_time_check(st_leafmtxp,st_ctl,nd,nstp,lrtrn) bind(C)
use, intrinsic :: iso_c_binding
#ifdef HAVE_MAGMA_PINNED
use cudafor
#endif
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
#ifdef HAVE_MAGMA_PINNED
real*8,dimension(:),allocatable, pinned :: wws,wwr,u,v,b
#else
real*8,dimension(:),allocatable :: wws,wwr,u,v,b
#endif
integer*4 :: isct(2),irct(2)
real*8,pointer :: param(:)
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:)
!!!
type(st_HACApk_leafmtx),pointer :: tmpleafmtx(:)
real*8 :: tmptmpa1
real*8 :: enorm,unorm
real*8 :: rnorm_g,enorm_g,unorm_g
character(len=50) :: ErrFormat
pointer (a1pt, tmptmpa1)
integer*8 :: stpt2, a2pt
real*8 time_copy, time_set, time_batch
!!!
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr; param=>st_ctl%param(:)
mpinr=lpmd(3); mpilog=lpmd(4); nrank=lpmd(2); icomm=lpmd(1)
mstep=param(99)
!!!
allocate(u(nd),v(nd),b(nd),wws(nd))
#ifdef HAVE_MAGMA_BATCH
v(:)=1.0; b(:)=1.0
time_batch = 0.0
time_set = 0.0
time_copy = 0.0
! call c_HACApK_adot_body_lfcpy_batch_sorted(nd,st_leafmtxp)
call c_HACApK_adot_body_lfmtx_batch(v,st_leafmtxp,b,wws,time_batch,time_set,time_copy)
#if !defined(BICG_MAGMA_BATCH)
! don't delete it if needed to call BICG
call c_HACApK_adot_body_lfdel_batch(st_leafmtxp)
#endif
#endif
deallocate(u,v,b,wws)
end subroutine HACApK_measurez_time_check
!***HACApK_adot_pmt_lfmtx_p
integer function HACApK_adot_pmt_lfmtx_p(st_leafmtxp,st_bemv,st_ctl,aww,ww)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
type(st_HACApK_calc_entry) :: st_bemv
real*8 :: ww(st_bemv%nd),aww(st_bemv%nd)
real*8,dimension(:),allocatable :: u,au
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:),lod(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lrtrn=0
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr;lod => st_ctl%lod(:)
mpinr=st_ctl%lpmd(3); icomm=st_ctl%lpmd(1); nd=st_bemv%nd
allocate(u(nd),au(nd)); u(:nd)=ww(st_ctl%lod(:nd))
call MPI_Barrier( icomm, ierr )
call HACApK_adot_lfmtx_p(au,st_leafmtxp,st_ctl,u,nd)
aww(st_ctl%lod(:nd))=au(:nd)
HACApK_adot_pmt_lfmtx_p=lrtrn
end function HACApK_adot_pmt_lfmtx_p
!***HACApK_adot_pmt_lfmtx_hyp
integer function HACApK_adot_pmt_lfmtx_hyp(st_leafmtxp,st_bemv,st_ctl,aww,ww)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
type(st_HACApK_calc_entry) :: st_bemv
real*8 :: ww(*),aww(*)
real*8,dimension(:),allocatable :: u,au,wws,wwr
integer*4,dimension(:),allocatable :: isct,irct
integer*4,pointer :: lpmd(:),lnp(:),lsp(:),lthr(:),lod(:)
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
lrtrn=0
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;lthr(0:) => st_ctl%lthr;lod => st_ctl%lod(:)
mpinr=st_ctl%lpmd(3); icomm=st_ctl%lpmd(1); nd=st_bemv%nd; nrank=st_ctl%lpmd(2)
allocate(u(nd),au(nd),isct(2),irct(2)); u(:nd)=ww(st_ctl%lod(:nd))
allocate(wws(maxval(st_ctl%lnp(:nrank))),wwr(maxval(st_ctl%lnp(:nrank))))
call MPI_Barrier( icomm, ierr )
call HACApK_adot_lfmtx_hyp(au,st_leafmtxp,st_ctl,u,wws,wwr,isct,irct,nd)
call MPI_Barrier( icomm, ierr )
aww(st_ctl%lod(:nd))=au(:nd)
HACApK_adot_pmt_lfmtx_hyp=lrtrn
end function HACApK_adot_pmt_lfmtx_hyp
!
!
#if defined(HAVE_MAGMA) | defined(HAVE_MAGMA_BATCH)
!***HACApK_bicgstab_cax_lfmtx_flat
subroutine HACApK_bicgstab_cax_lfmtx_flat(st_leafmtxp,st_ctl,u,b,param,nd,nstp,lrtrn) bind(C)
use, intrinsic :: iso_c_binding
include 'mpif.h'
! input arguments
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: u(nd),b(nd)
real*8 :: param(*)
integer nstp, nd, lrtrn
! local arrays
real*8,dimension(:),allocatable :: zr,zshdw,zp,zt,zkp,zakp,zkt,zakt
real*8,dimension(:),allocatable :: wws,wwr
integer*4,pointer :: lpmd(:)
integer*4 :: isct(2),irct(2)
! local variables
real*8 eps, alpha, beta, zeta, zz, zden, znorm, znormold, bnorm, zrnorm
real*8 en_measure_time, st_measure_time, time
integer step, mstep
integer mpinr, nrank, icomm, ierr
real*8 time_spmv, time_mpi, time_batch, time_set, time_copy, tic
1000 format(5(a,i10)/)
2000 format(5(a,f10.4)/)
!
lpmd => st_ctl%lpmd(:);
mpinr=lpmd(3); nrank=lpmd(2); icomm=lpmd(1)
call MPI_Barrier( icomm, ierr )
mstep=param(83)
eps=param(91)
allocate(wws(nd),wwr(nd))
allocate(zr(nd),zshdw(nd),zp(nd),zt(nd),zkp(nd),zakp(nd),zkt(nd),zakt(nd))
! copy matrix to GPU
call c_HACApK_adot_body_lfcpy_batch_sorted(nd,st_leafmtxp)
!
time_spmv = 0.0
time_mpi = 0.0
time_batch = 0.0
time_set = 0.0
time_copy = 0.0
call MPI_Barrier( icomm, ierr )
st_measure_time=MPI_Wtime()
! initialize
alpha = 0.0; beta = 0.0; zeta = 0.0;
zz=HACApK_dotp_d(nd, b, b); bnorm=dsqrt(zz);
zp(1:nd)=0.0d0; zakp(1:nd)=0.0d0
zr(:nd)=b(:nd)
! call HACApK_adotsub_lfmtx_hyp(zr,zshdw,st_leafmtxp,st_ctl,u,wws,wwr,isct,irct,nd)
zshdw(:nd)=0.0d0
tic = MPI_Wtime()
call c_HACApK_adot_body_lfmtx_batch(zshdw,st_leafmtxp,u,wws, time_batch,time_set,time_copy)
time_spmv = time_spmv + (MPI_Wtime()-tic)
call HACApK_adot_cax_lfmtx_comm(zshdw,st_leafmtxp,st_ctl,wws,wwr,isct,irct,nd, time_mpi)
zr(:nd)=zr(:nd)-zshdw(:nd)
!
zshdw(:nd)=zr(:nd)
zrnorm=HACApK_dotp_d(nd,zr,zr); zrnorm=dsqrt(zrnorm)
if(mpinr==0) print*,' '
if(mpinr==0) print*,' ** BICG with MAGMA batched (Fortran flat) **'
if(mpinr==0) print*,' '
if(mpinr==0) print*,'Original relative residual norm =',zrnorm/bnorm
if(mpinr==0) flush(output_unit)
if(st_ctl%param(1)>0 .and. mpinr==0) print*,'HACApK_bicgstab_lfmtx_flat start'
do step=1,mstep
if(zrnorm/bnorm<eps) exit
zp(:nd) = zr(:nd) + beta*(zp(:nd) - zeta*zakp(:nd))
zkp(:nd) = zp(:nd)
! .. SpMV ..
zakp(:nd)=0.0d0
tic = MPI_Wtime()
call c_HACApK_adot_body_lfmtx_batch(zakp,st_leafmtxp,zkp,wws, time_batch,time_set,time_copy)
time_spmv = time_spmv + (MPI_Wtime()-tic)
call HACApK_adot_cax_lfmtx_comm(zakp,st_leafmtxp,st_ctl,wws,wwr,isct,irct,nd, time_mpi)
! .. ..
znorm = HACApK_dotp_d(nd,zshdw,zr); zden=HACApK_dotp_d(nd,zshdw,zakp);
alpha = znorm/zden;
znormold = znorm;
zt(:nd) = zr(:nd) - alpha*zakp(:nd)
zkt(:nd) = zt(:nd)
! .. SpMV ..
zakt(:nd)=0.0d0
tic = MPI_Wtime()
call c_HACApK_adot_body_lfmtx_batch(zakt,st_leafmtxp,zkt,wws, time_batch,time_set,time_copy)
time_spmv = time_spmv + (MPI_Wtime()-tic)
call HACApK_adot_cax_lfmtx_comm(zakt,st_leafmtxp,st_ctl,wws,wwr,isct,irct,nd, time_mpi)
! .. ..
znorm = HACApK_dotp_d(nd,zakt,zt); zden=HACApK_dotp_d(nd,zakt,zakt);
zeta = znorm/zden;
u(:nd) = u(:nd) + alpha*zkp(:nd) + zeta*zkt(:nd)
zr(:nd) = zt(:nd) - zeta*zakt(:nd)
beta = alpha/zeta * HACApK_dotp_d(nd,zshdw,zr)/znormold;
zrnorm = HACApK_dotp_d(nd,zr,zr);
zrnorm = dsqrt(zrnorm)
nstp = step
! call MPI_Barrier( icomm, ierr )
en_measure_time = MPI_Wtime()
time = en_measure_time - st_measure_time
2002 format(i,a,1pe8.1,a,1pe8.1)
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2002) step,': time=',time,', log10(zrnorm/bnorm)=',log10(zrnorm/bnorm)
! exit
enddo
call MPI_Barrier( icomm, ierr )
en_measure_time = MPI_Wtime()
time = en_measure_time - st_measure_time
! delete matrix
call c_HACApK_adot_body_lfdel_batch(st_leafmtxp)
2001 format(5(a,1pe15.8)/)
2003 format(5(a,i,a,1pe9.2)/)
!if(st_ctl%param(1)>0) write(6,2003) ' End: ',mpinr,' ',time
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' BiCG =',time
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' time_mpi =',time_mpi
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' time_spmv =',time_spmv
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' > time_copy =',time_copy
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' > time_set =',time_set
if(st_ctl%param(1)>0 .and. mpinr==0) write(6,2001) ' > time_batch =',time_batch
end subroutine HACApK_bicgstab_cax_lfmtx_flat
#endif
!
!***HACApK_adot_cax_lfmtx_comm
subroutine HACApK_adot_cax_lfmtx_comm(zau,st_leafmtxp,st_ctl,wws,wwr,isct,irct,nd, time_mpi)
include 'mpif.h'
type(st_HACApK_leafmtxp) :: st_leafmtxp
type(st_HACApK_lcontrol) :: st_ctl
real*8 :: zau(*),wws(*),wwr(*)
real*8 time_mpi, tic
integer*4 :: isct(*),irct(*)
integer*4 :: ISTATUS(MPI_STATUS_SIZE)
integer*4,pointer :: lpmd(:),lnp(:),lsp(:)
lpmd => st_ctl%lpmd(:); lnp(0:) => st_ctl%lnp; lsp(0:) => st_ctl%lsp;
mpinr=lpmd(3); nrank=lpmd(2); icomm=lpmd(1)
if(nrank>1)then
wws(1:lnp(mpinr))=zau(lsp(mpinr):lsp(mpinr)+lnp(mpinr)-1)
ncdp=mod(mpinr+1,nrank)
ncsp=mod(mpinr+nrank-1,nrank)
isct(1)=lnp(mpinr);isct(2)=lsp(mpinr);
do ic=1,nrank-1
tic = MPI_Wtime()
call MPI_SENDRECV(isct,2,MPI_INTEGER,ncdp,1, &
irct,2,MPI_INTEGER,ncsp,1,icomm,ISTATUS,ierr)
call MPI_SENDRECV(wws,isct,MPI_DOUBLE_PRECISION,ncdp,1, &
wwr,irct,MPI_DOUBLE_PRECISION,ncsp,1,icomm,ISTATUS,ierr)
time_mpi = time_mpi + (MPI_Wtime()-tic)
zau(irct(2):irct(2)+irct(1)-1)=zau(irct(2):irct(2)+irct(1)-1)+wwr(:irct(1))
wws(:irct(1))=wwr(:irct(1))
isct(:2)=irct(:2)
enddo
endif
end subroutine HACApK_adot_cax_lfmtx_comm
endmodule m_HACApK_solve