-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwwm_aux_parall.F90
1491 lines (1489 loc) · 54.1 KB
/
wwm_aux_parall.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
#include "wwm_functions.h"
!**********************************************************************
!* Determine if nodes are in the domain for the computation of *
!* energy and similar things *
!**********************************************************************
SUBROUTINE BUILD_IPSTATUS
USE DATAPOOL
IMPLICIT NONE
integer IP
allocate(IPstatus(MNP), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 1')
#ifndef MPI_PARALL_GRID
IPstatus=1
#else
IPstatus=0
DO IP=1,NP_RES
IF(ASSOCIATED(IPGL(IPLG(IP))%NEXT)) THEN !interface nodes
IF(IPGL(IPLG(ip))%NEXT%RANK .ge. MYRANK) THEN ! interface node is not in the sum already ...
IPstatus(IP)=1
ENDIF
ELSE
IPstatus(IP)=1
ENDIF
END DO
#endif
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE BUILD_TRIANGLE_CORRESPONDENCES
USE DATAPOOL
IMPLICIT NONE
integer :: ListMapped(ne_total)
integer :: ListMappedB(ne_total)
#ifdef MPI_PARALL_GRID
integer :: ListFirst(nproc)
integer :: ListCommon_recv(nproc)
integer :: ListCommon_send(nproc)
#endif
integer :: IEfound, IE2, IE, J
integer :: IPglob, I, MAXMNECCON_TOTAL, idx
integer :: iProc, MNE_loc, MNEextent_loc
integer :: nbCommon_send, nbCommon_recv
integer :: idx_send, idx_recv, iNeigh
integer :: nbCommon, IE_glob, IEloc
integer :: IP1, IP2, IP3
integer :: IPglob1, IPglob2, IPglob3
integer :: iRank, sumExtent, IEadj, eVal
integer :: I1, I2, J1, J2
integer, allocatable :: INDX_IE(:,:)
integer, allocatable :: IE_LocalGlobal(:), StatusNeed(:)
integer, allocatable :: CCON_total(:)
integer, allocatable :: eInt(:), dspl_send(:), dspl_recv(:)
integer, allocatable :: INDXextent_IE(:)
integer, allocatable :: IEneighbor_V1(:,:)
integer, allocatable :: IEmembership(:)
#ifndef SCHISM
allocate(CCON_total(np_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('BUILD_TRIANGLE error 1')
CCON_TOTAL=0
DO IE=1,NE_TOTAL
DO I=1,3
IPglob=INEtotal(I,IE)
CCON_TOTAL(IPglob)=CCON_TOTAL(IPglob) + 1
END DO
END DO
MAXMNECCON_TOTAL=maxval(CCON_TOTAL)
!
allocate(INDX_IE(MAXMNECCON_TOTAL, np_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('BUILD_TRIANGLE error 2')
CCON_TOTAL=0
DO IE=1,NE_TOTAL
DO I=1,3
IPglob=INEtotal(I,IE)
idx=CCON_TOTAL(IPglob)
CCON_TOTAL(IPglob)=idx + 1
INDX_IE(idx+1, IPglob)=IE
END DO
END DO
!
allocate(IE_LocalGlobal(MNE), stat=istat)
IF (istat/=0) CALL WWM_ABORT('BUILD_TRIANGLE error 3')
DO IE=1,MNE
IP1=INE(1,IE)
IP2=INE(2,IE)
IP3=INE(3,IE)
#ifdef MPI_PARALL_GRID
IPglob1=iplg(IP1)
IPglob2=iplg(IP2)
IPglob3=iplg(IP3)
#else
IPglob1=IP1
IPglob2=IP2
IPglob3=IP3
#endif
IEfound=-1
DO J=1,CCON_TOTAL(IPglob1)
IE2=INDX_IE(J, IPglob1)
IF ((IPglob1 .eq. INEtotal(1,IE2)).and.(IPglob2 .eq. INEtotal(2,IE2)).and.(IPglob3 .eq. INEtotal(3,IE2))) THEN
IEfound=IE2
END IF
END DO
IF (IEfound .eq. -1) THEN
write(DBG%FHNDL,*) 'IE=', IE
write(DBG%FHNDL,*) 'IP123=', IP1, IP2, IP3
write(DBG%FHNDL,*) 'IPglob123=', IPglob1, IPglob2, IPglob3
write(DBG%FHNDL,*) 'CCON_TOTAL=', CCON_TOTAL(IPglob1)
DO J=1,CCON_TOTAL(IPglob1)
IE2=INDX_IE(J, IPglob1)
write(DBG%FHNDL,*) 'J=', J, 'IE2=', IE2
write(DBG%FHNDL,*) 'INE(:,IE2)=', INEtotal(1,IE2), INEtotal(2,IE2), INEtotal(3,IE2)
END DO
CALL WWM_ABORT('Did not find the triangle')
END IF
IE_LocalGlobal(IE)=IEfound
END DO
!
allocate(IEneighbor_V1(3,MNE), stat=istat)
IF (istat/=0) CALL WWM_ABORT('BUILD_TRIANGLE error 4')
DO IE=1,MNE
DO I1=1,3
IF (I1 .eq. 3) THEN
I2=1
ELSE
I2=I1+1
END IF
IP1=INE(I1,IE)
IP2=INE(I2,IE)
#ifdef MPI_PARALL_GRID
IPglob1=iplg(IP1)
IPglob2=iplg(IP2)
#else
IPglob1=IP1
IPglob2=IP2
#endif
IEadj=-1
DO J=1,CCON_TOTAL(IPglob1)
IF (IEadj .eq. -1) THEN
IE2=INDX_IE(J, IPglob1)
DO J1=1,3
IF (J1 .eq. 3) THEN
J2=1
ELSE
J2=J1+1
END IF
IF ((INEtotal(J1,IE2) .eq. IPglob2).and.(INEtotal(J2,IE2) .eq. IPglob1)) THEN
IEadj=IE2
END IF
END DO
END IF
END DO
IEneighbor_V1(I1,IE)=IEadj
END DO
END DO
!
allocate(StatusNeed(ne_total), stat=istat)
IF (istat/=0) CALL WWM_ABORT('BUILD_TRIANGLE error 5')
StatusNeed=0
DO IE=1,MNE
IE_glob=IE_LocalGlobal(IE)
StatusNeed(IE_glob)=1
DO I=1,3
IEadj=IEneighbor_V1(I,IE)
IF (IEadj .ne. -1) THEN
StatusNeed(IEadj)=1
END IF
END DO
END DO
MNEextent=sum(StatusNeed)
! WRITE(STAT%FHNDL,*) 'MNE/MNEextent=', MNE, MNEextent
! FLUSH(STAT%FHNDL)
allocate(INDXextent_IE(MNEextent), stat=istat)
IF (istat/=0) CALL WWM_ABORT('BUILD_TRIANGLE error 6')
DO IE=1,MNE
IE_glob=IE_LocalGlobal(IE)
INDXextent_IE(IE)=IE_glob
StatusNeed(IE_glob)=0
END DO
idx=MNE
DO IE=1,NE_TOTAL
IF (StatusNeed(IE) .eq. 1) THEN
idx=idx+1
INDXextent_IE(idx)=IE
END IF
END DO
StatusNeed=0
DO IE=1,MNEextent
IE_glob=INDXextent_IE(IE)
StatusNeed(IE_glob)=IE
END DO
!
! Now building the neighbor list
!
allocate(IEneighbor(3,MNE), stat=istat)
DO IE=1,MNE
DO I=1,3
IE_glob=IEneighbor_V1(I,IE)
IF (IE_glob .eq. -1) THEN
IEloc=-1
ELSE
IEloc=StatusNeed(IE_glob)
END IF
IEneighbor(I,IE)=IEloc
END DO
END DO
#ifdef MPI_PARALL_GRID
!
! Collecting the ListMNE, ListMNEextent
!
allocate(ListMNE(nproc), ListMNEextent(nproc), stat=istat)
IF (istat/=0) CALL WWM_ABORT('BUILD_TRIANGLE error 7')
allocate(eInt(2), stat=istat)
IF (istat/=0) CALL WWM_ABORT('BUILD_TRIANGLE error 8')
IF (myrank .eq. 0) THEN
ListMNE(1)=MNE
ListMNEextent(1)=MNEextent
DO IPROC=2,nproc
iRank=IPROC-1
CALL MPI_RECV(eInt, 2, itype,iRank,2049,comm,istatus,ierr)
ListMNE(IPROC)=eInt(1)
ListMNEextent(IPROC)=eInt(2)
END DO
DO IPROC=2,nproc
iRank=IPROC-1
CALL MPI_SEND(ListMNE,nproc,itype,iRank,2050,comm,ierr)
CALL MPI_SEND(ListMNEextent,nproc,itype,iRank,2051,comm,ierr)
END DO
ELSE
eInt(1)=MNE
eInt(2)=MNEextent
CALL MPI_SEND(eInt,2,itype,0,2049,comm,ierr)
CALL MPI_RECV(ListMNE, nproc, itype,0,2050,comm,istatus,ierr)
CALL MPI_RECV(ListMNEextent, nproc, itype,0,2051,comm,istatus,ierr)
END IF
deallocate(eInt)
!
! Collecting the ListINDXextent_IE
!
sumExtent=sum(ListMNEextent)
allocate(ListINDXextent_IE(sumExtent), stat=istat)
IF (myrank .eq. 0) THEN
idx=0
DO J=1,MNEextent
idx=idx+1
ListINDXextent_IE(idx)=INDXextent_IE(J)
END DO
DO IPROC=2,nproc
iRank=IPROC-1
MNEextent_loc=ListMNEextent(IPROC)
allocate(eInt(MNEextent_loc), stat=istat)
IF (istat/=0) CALL WWM_ABORT('BUILD_TRIANGLE error 9')
CALL MPI_RECV(eInt, MNEextent_loc, itype,iRank,2051,comm,istatus,ierr)
DO J=1,MNEextent_loc
idx=idx+1
ListINDXextent_IE(idx)=eInt(J)
END DO
deallocate(eInt)
END DO
DO IPROC=2,nproc
iRank=IPROC-1
CALL MPI_SEND(ListINDXextent_IE,sumExtent,itype,iRank,2052,comm,ierr)
END DO
ELSE
CALL MPI_SEND(INDXextent_IE,MNEextent,itype,0,2051,comm,ierr)
CALL MPI_RECV(ListINDXextent_IE, sumExtent, itype,0,2052,comm,istatus,ierr)
END IF
!
! Now building ListFirst
!
ListFirst=0
DO iProc=2,nproc
ListFirst(iProc)=ListFirst(iProc-1) + ListMNEextent(iProc-1)
END DO
#endif
!
! Determine IE membership
!
allocate(IEstatus(MNE))
#ifdef MPI_PARALL_GRID
allocate(IEmembership(ne_total), stat=istat)
IEmembership=0
DO iProc=1,nproc
MNE_loc=ListMNE(iProc)
DO IE=1,MNE_loc
IE_glob=ListINDXextent_IE(IE+ListFirst(iProc))
IF (IEmembership(IE_glob) .eq. 0) THEN
IEmembership(IE_glob)=iProc
END IF
END DO
END DO
DO IE=1,MNE
IE_glob=INDXextent_IE(IE)
eVal=0
IF (IEmembership(IE_glob) .eq. myrank+1) eVal=1
IEstatus(IE)=eVal
END DO
deallocate(IEmembership)
#else
IEstatus=1
#endif
#ifdef MPI_PARALL_GRID
!
! Now building synchronization arrays
!
ListMapped=0
DO IE=1,MNEextent
IE_glob=INDXextent_IE(IE)
ListMapped(IE_glob)=IE
END DO
ListCommon_send=0
ListCommon_recv=0
ie_nnbr_send=0
ie_nnbr_recv=0
DO iProc=1,nproc
IF (iProc .ne. myrank+1) THEN
MNE_loc=ListMNE(iProc)
MNEextent_loc=ListMNEextent(iProc)
ListMappedB=0
DO IE=1,MNEextent_loc
IE_glob=ListINDXextent_IE(IE+ListFirst(iProc))
ListMappedB(IE_glob)=IE
END DO
!
nbCommon_recv=0
DO IE=1,MNE_loc
IE_glob=ListINDXextent_IE(IE+ListFirst(iProc))
IF (ListMapped(IE_glob).gt.0) THEN
nbCommon_recv=nbCommon_recv+1
END IF
END DO
IF (nbCommon_recv .gt. 0) THEN
ie_nnbr_recv=ie_nnbr_recv+1
ListCommon_recv(iProc)=nbCommon_recv
END IF
!
nbCommon_send=0
DO IE=1,MNE
IE_glob=INDXextent_IE(IE)
IF (ListMappedB(IE_glob).gt.0) THEN
nbCommon_send=nbCommon_send+1
END IF
END DO
IF (nbCommon_send .gt. 0) THEN
ie_nnbr_send=ie_nnbr_send+1
ListCommon_send(iProc)=nbCommon_send
END IF
END IF
END DO
!
! Building list of neighbors
!
allocate(ListNeigh_ie_send(ie_nnbr_send), ListNeigh_ie_recv(ie_nnbr_recv), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 2')
idx_send=0
idx_recv=0
DO iProc=1,nproc
IF (ListCommon_send(iProc) .gt. 0) THEN
idx_send=idx_send+1
ListNeigh_ie_send(idx_send)=iProc-1
END IF
IF (ListCommon_recv(iProc) .gt. 0) THEN
idx_recv=idx_recv+1
ListNeigh_ie_recv(idx_recv)=iProc-1
END IF
END DO
!
! Building MPI arrays
!
allocate(ie_send_rqst(ie_nnbr_send), ie_recv_rqst(ie_nnbr_recv), ie_send_stat(MPI_STATUS_SIZE,ie_nnbr_send), ie_recv_stat(MPI_STATUS_SIZE,ie_nnbr_recv), ie_send_type(ie_nnbr_send), ie_recv_type(ie_nnbr_recv), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 3')
DO iNeigh=1,ie_nnbr_send
iProc=ListNeigh_ie_send(iNeigh)+1
nbCommon=ListCommon_send(iProc)
MNEextent_loc=ListMNEextent(iProc)
ListMappedB=0
DO IE=1,MNEextent_loc
IE_glob=ListINDXextent_IE(IE+ListFirst(iProc))
ListMappedB(IE_glob)=IE
END DO
allocate(dspl_send(nbCommon), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 4')
idx=0
DO IE=1,MNE
IE_glob=INDXextent_IE(IE)
IEloc=ListMappedB(IE_glob)
IF (IEloc.gt.0) THEN
idx=idx+1
dspl_send(idx)=IE-1
END IF
END DO
call mpi_type_create_indexed_block(nbCommon,1,dspl_send,rtype,ie_send_type(iNeigh), ierr)
call mpi_type_commit(ie_send_type(iNeigh), ierr)
deallocate(dspl_send)
END DO
DO iNeigh=1,ie_nnbr_recv
iProc=ListNeigh_ie_recv(iNeigh)+1
MNE_loc=ListMNE(iProc)
MNEextent_loc=ListMNEextent(iProc)
nbCommon=ListCommon_recv(iProc)
allocate(dspl_recv(nbCommon), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 5')
idx=0
DO IE=1,MNE_loc
IE_glob=ListINDXextent_IE(IE+ListFirst(iProc))
IEloc=ListMapped(IE_glob)
IF (IEloc .gt. 0) THEN
idx=idx+1
dspl_recv(idx)=IEloc-1
END IF
END DO
call mpi_type_create_indexed_block(nbCommon,1,dspl_recv,rtype,ie_recv_type(iNeigh), ierr)
call mpi_type_commit(ie_recv_type(iNeigh), ierr)
deallocate(dspl_recv)
END DO
deallocate(INDX_IE, IE_LocalGlobal, StatusNeed, CCON_total, INDXextent_IE, IEneighbor_V1)
#endif
#endif
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE TOTAL_SUMMATION_SCALAR(F, eSum)
USE DATAPOOL
IMPLICIT NONE
real(rkind), intent(in) :: F(MNP)
real(rkind), intent(out) :: eSum
real(rkind) eField(1), Lsum(1)
integer IP, iProc
eSum=ZERO
DO IP=1,MNP
IF (IPstatus(IP) .eq. 1) THEN
eSum = eSum + F(IP)
END IF
END DO
! WRITE(STAT%FHNDL,*) 'sum(AC)=', sum(AC)
! WRITE(STAT%FHNDL,*) 'After summation, sum(Lsum)=', sum(Lsum)
#ifdef MPI_PARALL_GRID
IF (myrank == 0) THEN
DO iProc=2,nproc
CALL MPI_RECV(eField,1,rtype, iProc-1, 43, comm, istatus, ierr)
eSum=eSum + eField(1)
END DO
Lsum(1)=eSum
DO iProc=2,nproc
CALL MPI_SEND(Lsum,1,rtype, iProc-1, 13, comm, ierr)
END DO
ELSE
Lsum(1)=eSum
CALL MPI_SEND(Lsum,1,rtype, 0, 43, comm, ierr)
CALL MPI_RECV(Lsum,1,rtype, 0, 13, comm, istatus, ierr)
eSum=Lsum(1)
END IF
#endif
! WRITE(STAT%FHNDL,*) 'At leaving, sum(Lsum)=', sum(Lsum)
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE TOTAL_SUMMATION_AC(AC, Lsum)
USE DATAPOOL
IMPLICIT NONE
real(rkind), intent(in) :: AC(NUMSIG, NUMDIR, MNP)
real(rkind), intent(out) :: Lsum(NUMSIG, NUMDIR)
real(rkind) eField(NUMSIG, NUMDIR)
integer IP, iProc
Lsum=ZERO
DO IP=1,MNP
IF (IPstatus(IP) .eq. 1) THEN
Lsum = Lsum + AC(:,:,IP)
END IF
END DO
! WRITE(STAT%FHNDL,*) 'sum(AC)=', sum(AC)
! WRITE(STAT%FHNDL,*) 'After summation, sum(Lsum)=', sum(Lsum)
#ifdef MPI_PARALL_GRID
IF (myrank == 0) THEN
DO iProc=2,nproc
CALL MPI_RECV(eField,NUMSIG*NUMDIR,rtype, iProc-1, 43, comm, istatus, ierr)
Lsum=Lsum + eField
END DO
DO iProc=2,nproc
CALL MPI_SEND(Lsum,NUMSIG*NUMDIR,rtype, iProc-1, 13, comm, ierr)
END DO
ELSE
CALL MPI_SEND(Lsum,NUMSIG*NUMDIR,rtype, 0, 43, comm, ierr)
CALL MPI_RECV(Lsum,NUMSIG*NUMDIR,rtype, 0, 13, comm, istatus, ierr)
END IF
#endif
! WRITE(STAT%FHNDL,*) 'At leaving, sum(Lsum)=', sum(Lsum)
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE Print_SumAC2(string)
USE DATAPOOL
implicit NONE
character(len=*), intent(in) :: string
real(rkind) :: Lsum(NUMSIG,NUMDIR)
CALL TOTAL_SUMMATION_AC(AC2, Lsum)
IF (PrintLOG) THEN
WRITE(STAT%FHNDL,*) 'sum(AC2)=', sum(Lsum),' at step:', TRIM(string)
END IF
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE Print_SumScalar(F, string)
USE DATAPOOL
implicit NONE
real(rkind), intent(in) :: F(MNP)
character(len=*), intent(in) :: string
real(rkind) :: eSum
CALL TOTAL_SUMMATION_SCALAR(F, eSum)
WRITE(STAT%FHNDL,*) 'sum(F)=', eSum,' mesg:', TRIM(string)
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE PRINT_COHERENCY_ERROR(ACw, string)
USE DATAPOOL
IMPLICIT NONE
character(*), intent(in) :: string
REAL(rkind), intent(in) :: ACw(NUMSIG, NUMDIR, MNP)
REAL(rkind) Lerror
CALL I5B_TOTAL_COHERENCY_ERROR(NUMSIG, ACw, Lerror)
WRITE(740+myrank,*) 'Coherency error=', Lerror, ' at ', string
FLUSH(740+myrank)
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE I5B_TOTAL_COHERENCY_ERROR(NUMSIGeffect, ACw, Lerror)
USE DATAPOOL
implicit none
integer, intent(in) :: NUMSIGeffect
real(rkind), intent(in) :: ACw(NUMSIGeffect, NUMDIR, MNP)
real(rkind), intent(out) :: Lerror
#ifdef MPI_PARALL_GRID
real(rkind), allocatable :: ACtotal(:,:,:)
real(rkind), allocatable :: ACloc(:,:,:)
real(rkind) :: rbuf_real(1)
integer, allocatable :: ListFirstMNP(:)
integer, allocatable :: eStatus(:)
integer IP, iProc, IPglob, IS, ID
integer MNPloc
#endif
#ifdef MPI_PARALL_GRID
IF (myrank == 0) THEN
Lerror=0
allocate(ListFirstMNP(nproc), eStatus(np_global), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 6')
ListFirstMNP=0
eStatus=0
DO iProc=2,nproc
ListFirstMNP(iProc)=ListFirstMNP(iProc-1) + ListMNP(iProc-1)
END DO
allocate(ACtotal(NUMSIGeffect, NUMDIR, np_global), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 7')
DO IP=1,MNP
IPglob=iplg(IP)
ACtotal(:,:,IPglob)=ACw(:,:,IP)
eStatus(IPglob)=1
END DO
DO iProc=2,nproc
MNPloc=ListMNP(iProc)
allocate(ACloc(NUMSIGeffect, NUMDIR, MNPloc), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 8')
CALL MPI_RECV(ACloc,MNPloc*NUMSIGeffect*NUMDIR,rtype, iProc-1, 53, comm, istatus, ierr)
DO IP=1,MNPloc
IPglob=ListIPLG(IP+ListFirstMNP(iProc))
IF (eStatus(IPglob) == 1) THEN
DO IS=1,NUMSIGeffect
DO ID=1,NUMDIR
Lerror=Lerror+abs(ACtotal(IS,ID,IPglob)-ACloc(IS,ID,IP))
END DO
END DO
ELSE
eStatus(IPglob)=1
ACtotal(:,:,IPglob)=ACloc(:,:,IP)
END IF
END DO
deallocate(ACloc)
END DO
deallocate(ListFirstMNP, ACtotal, eStatus)
rbuf_real(1)=Lerror
DO iProc=2,nproc
CALL MPI_SEND(rbuf_real,1,rtype, iProc-1, 23, comm, ierr)
END DO
ELSE
CALL MPI_SEND(ACw,MNP*NUMSIGeffect*NUMDIR,rtype, 0, 53, comm, ierr)
CALL MPI_RECV(rbuf_real,1,rtype, 0, 23, comm, istatus, ierr)
Lerror=rbuf_real(1)
END IF
#else
Lerror=0 ! in serial the coherency error is zero
#endif
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE I5B_TOTAL_COHERENCY_ERROR_NPRES(NUMSIGeffect, ACw, Lerror)
USE DATAPOOL
implicit none
integer, intent(in) :: NUMSIGeffect
real(rkind), intent(in) :: ACw(NUMSIGeffect, NUMDIR, MNP)
real(rkind), intent(out) :: Lerror
real(rkind), allocatable :: ACtotal(:,:,:)
real(rkind), allocatable :: ACloc(:,:,:)
real(rkind) :: rbuf_real(1)
integer, allocatable :: ListFirstMNP(:)
integer, allocatable :: eStatus(:)
integer IP, iProc, IPglob, IS, ID
integer NP_RESloc
#ifdef MPI_PARALL_GRID
IF (myrank == 0) THEN
Lerror=0
allocate(ListFirstMNP(nproc), eStatus(np_global), ACtotal(NUMSIGeffect, NUMDIR, np_global), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 9')
ListFirstMNP=0
eStatus=0
DO iProc=2,nproc
ListFirstMNP(iProc)=ListFirstMNP(iProc-1) + ListMNP(iProc-1)
END DO
DO IP=1,NP_RES
IPglob=iplg(IP)
ACtotal(:,:,IPglob)=ACw(:,:,IP)
eStatus(IPglob)=1
END DO
DO iProc=2,nproc
NP_RESloc=ListNP_RES(iProc)
allocate(ACloc(NUMSIGeffect, NUMDIR, NP_RESloc), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 10')
CALL MPI_RECV(ACloc,NUMSIGeffect*NUMDIR*NP_RESloc,rtype, iProc-1, 53, comm, istatus, ierr)
DO IP=1,NP_RESloc
IPglob=ListIPLG(IP+ListFirstMNP(iProc))
IF (eStatus(IPglob) == 1) THEN
DO IS=1,NUMSIGeffect
DO ID=1,NUMDIR
Lerror=Lerror+abs(ACtotal(IS,ID,IPglob)-ACloc(IS,ID,IP))
END DO
END DO
ELSE
eStatus(IPglob)=1
ACtotal(:,:,IPglob)=ACloc(:,:,IP)
END IF
END DO
deallocate(ACloc)
END DO
deallocate(ListFirstMNP, ACtotal, eStatus)
rbuf_real(1)=Lerror
DO iProc=2,nproc
CALL MPI_SEND(rbuf_real,1,rtype, iProc-1, 23, comm, ierr)
END DO
ELSE
allocate(ACloc(NUMSIGeffect, NUMDIR, NP_RES), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 11')
DO IP=1,NP_RES
ACloc(:,:,IP)=ACw(:,:,IP)
END DO
CALL MPI_SEND(ACloc,NP_RES*NUMSIGeffect*NUMDIR,rtype, 0, 53, comm, ierr)
deallocate(ACloc)
CALL MPI_RECV(rbuf_real,1,rtype, 0, 23, comm, istatus, ierr)
Lerror=rbuf_real(1)
END IF
#else
Lerror=0 ! in serial the coherency error is zero
#endif
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
#ifdef MPI_PARALL_GRID
SUBROUTINE COLLECT_ALL_IPLG
USE DATAPOOL
implicit none
integer, allocatable :: rbuf_int(:)
integer len, iProc, IP, idx, sumMNP
allocate(ListMNP(nproc), ListNP_RES(nproc), rbuf_int(2), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 12')
IF (myrank == 0) THEN
ListMNP(1)=MNP
ListNP_RES(1)=NP_RES
DO iProc=2,nproc
CALL MPI_RECV(rbuf_int,2,itype, iProc-1, 257, comm, istatus, ierr)
ListMNP(iProc)=rbuf_int(1)
ListNP_RES(iProc)=rbuf_int(2)
END DO
DO iProc=2,nproc
CALL MPI_SEND(ListMNP,nproc,itype, iProc-1, 263, comm, ierr)
END DO
DO iProc=2,nproc
CALL MPI_SEND(ListNP_RES,nproc,itype, iProc-1, 571, comm, ierr)
END DO
ELSE
rbuf_int(1)=MNP
rbuf_int(2)=NP_RES
CALL MPI_SEND(rbuf_int,2,itype, 0, 257, comm, ierr)
CALL MPI_RECV(ListMNP,nproc,itype, 0, 263, comm, istatus, ierr)
CALL MPI_RECV(ListNP_RES,nproc,itype, 0, 571, comm, istatus, ierr)
END IF
deallocate(rbuf_int)
sumMNP=sum(ListMNP)
allocate(ListIPLG(sumMNP), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 13')
IF (myrank == 0) THEN
idx=0
DO IP=1,MNP
idx=idx+1
ListIPLG(idx)=iplg(IP)
END DO
DO iProc=2,nproc
len=ListMNP(iProc)
allocate(rbuf_int(len), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 14')
CALL MPI_RECV(rbuf_int,len,itype, iProc-1, 269, comm, istatus, ierr)
DO IP=1,len
idx=idx+1
ListIPLG(idx)=rbuf_int(IP)
END DO
deallocate(rbuf_int)
END DO
DO iProc=2,nproc
CALL MPI_SEND(ListIPLG,sumMNP,itype, iProc-1, 271, comm, ierr)
END DO
ELSE
CALL MPI_SEND(iplg,MNP,itype, 0, 269, comm, ierr)
CALL MPI_RECV(ListIPLG,sumMNP,itype, 0, 271, comm, istatus, ierr)
END IF
END SUBROUTINE
#endif
!**********************************************************************
!* *
!**********************************************************************
#ifdef MPI_PARALL_GRID
SUBROUTINE COLLECT_ALL_IA_JA
USE DATAPOOL
implicit none
integer, allocatable :: rbuf_int(:)
integer len, iProc, IP, idx
integer sumIAsiz, sumNNZ
allocate(ListNNZ(nproc), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 15')
!
! Collecting NNZ
!
IF (myrank == 0) THEN
ListNNZ(1)=NNZ
allocate(rbuf_int(1), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 16')
DO iProc=2,nproc
CALL MPI_RECV(rbuf_int,1,itype, iProc-1, 257, comm, istatus, ierr)
ListNNZ(iProc)=rbuf_int(1)
END DO
deallocate(rbuf_int)
DO iProc=2,nproc
CALL MPI_SEND(ListNNZ,nproc,itype, iProc-1, 263, comm, ierr)
END DO
ELSE
allocate(rbuf_int(1), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 17')
rbuf_int(1)=NNZ
CALL MPI_SEND(rbuf_int,1,itype, 0, 257, comm, ierr)
deallocate(rbuf_int)
CALL MPI_RECV(ListNNZ,nproc,itype, 0, 263, comm, istatus, ierr)
END IF
!
! Collecting IA
!
sumIAsiz=sum(ListMNP) + nproc
allocate(ListIA(sumIAsiz), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 18')
IF (myrank == 0) THEN
idx=0
DO IP=1,MNP+1
idx=idx+1
ListIA(idx)=IA(IP)
END DO
DO iProc=2,nproc
len=ListMNP(iProc)+1
allocate(rbuf_int(len), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 19')
CALL MPI_RECV(rbuf_int,len,itype, iProc-1, 269, comm, istatus, ierr)
DO IP=1,len
idx=idx+1
ListIA(idx)=rbuf_int(IP)
END DO
deallocate(rbuf_int)
END DO
DO iProc=2,nproc
CALL MPI_SEND(ListIA,sumIAsiz,itype, iProc-1, 271, comm, ierr)
END DO
ELSE
CALL MPI_SEND(IA,MNP+1,itype, 0, 269, comm, ierr)
CALL MPI_RECV(ListIA,sumIAsiz,itype, 0, 271, comm, istatus, ierr)
END IF
!
! Collecting JA
!
sumNNZ=sum(ListNNZ)
allocate(ListJA(sumNNZ), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 20')
IF (myrank == 0) THEN
idx=0
DO IP=1,NNZ
idx=idx+1
ListJA(idx)=JA(IP)
END DO
DO iProc=2,nproc
len=ListNNZ(iProc)
allocate(rbuf_int(len), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 21')
CALL MPI_RECV(rbuf_int,len,itype, iProc-1, 569, comm, istatus, ierr)
DO IP=1,len
idx=idx+1
ListJA(idx)=rbuf_int(IP)
END DO
deallocate(rbuf_int)
END DO
DO iProc=2,nproc
CALL MPI_SEND(ListJA,sumNNZ,itype, iProc-1, 467, comm, ierr)
END DO
ELSE
CALL MPI_SEND(JA,NNZ,itype, 0, 569, comm, ierr)
CALL MPI_RECV(ListJA,sumNNZ,itype, 0, 467, comm, istatus, ierr)
END IF
END SUBROUTINE
#endif
!**********************************************************************
!* *
!**********************************************************************
#ifdef MPI_PARALL_GRID
SUBROUTINE SYMM_GRAPH_BUILD_ADJ(AdjGraph)
USE DATAPOOL
implicit none
type(Graph), intent(inout) :: AdjGraph
CALL KERNEL_GRAPH_BUILD_ADJ(AdjGraph, wwm_nnbr, wwm_ListNeigh)
END SUBROUTINE
#endif
!**********************************************************************
!* *
!**********************************************************************
#ifdef MPI_PARALL_GRID
SUBROUTINE GRAPH_BUILD_ADJ(AdjGraph)
USE datapool, only : nnbr_p, nbrrank_p, Graph
implicit none
type(Graph), intent(inout) :: AdjGraph
integer :: ListNe(nnbr_p)
integer I
DO I=1,nnbr_p
ListNe(I)=nbrrank_p(I)+1
END DO
CALL KERNEL_GRAPH_BUILD_ADJ(AdjGraph, nnbr_p, ListNe)
END SUBROUTINE
#endif
!**********************************************************************
!* *
!**********************************************************************
#ifdef MPI_PARALL_GRID
SUBROUTINE KERNEL_GRAPH_BUILD_ADJ(AdjGraph, nb, ListNe)
USE DATAPOOL
implicit none
integer, intent(in) :: nb
integer, intent(in) :: ListNe(nb)
type(Graph), intent(inout) :: AdjGraph
integer, allocatable :: rbuf_int(:)
integer I, iProc
integer idx, eDeg, nbEdge, iEdge
AdjGraph % nbVert=nproc
IF (myrank.eq.0) THEN
allocate(AdjGraph % ListDegree(nproc), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 22')
AdjGraph % ListDegree(1)=nb
allocate(rbuf_int(1), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 23')
DO iProc=2,nproc
CALL MPI_RECV(rbuf_int,1,itype, iProc-1, 19, comm, istatus, ierr)
AdjGraph % ListDegree(iProc)=rbuf_int(1)
END DO
deallocate(rbuf_int)
nbEdge=0
DO iProc=1,nproc
nbEdge=nbEdge + AdjGraph % ListDegree(iProc)
END DO
AdjGraph % nbEdge=nbEdge
allocate(AdjGraph % ListEdge(nbEdge,2), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 24')
idx=0
eDeg=AdjGraph % ListDegree(1)
DO I=1,eDeg
idx=idx+1
AdjGraph % ListEdge(idx,1)=1
AdjGraph % ListEdge(idx,2)=ListNe(I)
END DO
DO iProc=2,nproc
eDeg=AdjGraph % ListDegree(iProc)
allocate(rbuf_int(eDeg), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 25')
CALL MPI_RECV(rbuf_int,eDeg,itype, iProc-1, 24, comm, istatus, ierr)
DO I=1,eDeg
idx=idx+1
AdjGraph % ListEdge(idx,1)=iProc
AdjGraph % ListEdge(idx,2)=rbuf_int(I)
END DO
deallocate(rbuf_int)
END DO
allocate(rbuf_int(1), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 26')
rbuf_int(1)=nbEdge
DO iProc=2,nproc
CALL MPI_SEND(rbuf_int,1,itype, iProc-1, 30, comm, ierr)
END DO
deallocate(rbuf_int)
!
allocate(rbuf_int(nproc), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 27')
DO iProc=1,nproc
rbuf_int(iProc)=AdjGraph % ListDegree(iProc)
END DO
DO iProc=2,nproc
CALL MPI_SEND(rbuf_int,nproc,itype, iProc-1, 32, comm, ierr)
END DO
deallocate(rbuf_int)
!
allocate(rbuf_int(nbEdge*2), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 28')
DO iEdge=1,nbEdge
rbuf_int(2*(iEdge-1)+1)=AdjGraph % ListEdge(iEdge,1)
rbuf_int(2*(iEdge-1)+2)=AdjGraph % ListEdge(iEdge,2)
END DO
DO iProc=2,nproc
CALL MPI_SEND(rbuf_int,2*nbEdge,itype, iProc-1, 34, comm, ierr)
END DO
ELSE
allocate(rbuf_int(1), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 29')
rbuf_int(1)=nb
CALL MPI_SEND(rbuf_int,1,itype, 0, 19, comm, ierr)
deallocate(rbuf_int)
!
allocate(rbuf_int(nb), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 30')
DO I=1,nb
rbuf_int(I)=ListNe(I)
END DO
CALL MPI_SEND(rbuf_int,nb,itype, 0, 24, comm, ierr)
deallocate(rbuf_int)
!
allocate(rbuf_int(1), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 31')
CALL MPI_RECV(rbuf_int,1,itype, 0, 30, comm, istatus, ierr)
nbEdge=rbuf_int(1)
deallocate(rbuf_int)
AdjGraph % nbEdge=nbEdge
!
allocate(rbuf_int(nproc), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 32')
CALL MPI_RECV(rbuf_int,nproc,itype, 0, 32, comm, istatus, ierr)
allocate(AdjGraph % ListDegree(nproc), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 33')
AdjGraph % ListDegree=rbuf_int
deallocate(rbuf_int)
!
allocate(rbuf_int(2*nbEdge), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 34')
CALL MPI_RECV(rbuf_int,2*nbEdge,itype, 0, 34, comm, istatus, ierr)
allocate(AdjGraph % ListEdge(nbEdge,2), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_aux_parall, allocate error 35')
DO iEdge=1,nbEdge
AdjGraph % ListEdge(iEdge,1)=rbuf_int(2*(iEdge-1)+1)
AdjGraph % ListEdge(iEdge,2)=rbuf_int(2*(iEdge-1)+2)
END DO
deallocate(rbuf_int)
ENDIF
AdjGraph % MaxDeg=maxval(AdjGraph % ListDegree)
END SUBROUTINE
#endif
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE GRAPH_TEST_CONNECT(AdjGraph, result)
USE DATAPOOL
implicit none
type(Graph), intent(in) :: AdjGraph
integer, intent(out) :: result
integer :: ListStatus(AdjGraph%nbVert)
integer :: ListPosFirst(AdjGraph%nbVert)
integer idx, iVert, nbVert, eAdj
integer eDeg, sizConn, I, IsFinished
idx=0
nbVert=AdjGraph%nbVert
ListStatus=0
DO iVert=1,nbVert
ListPosFirst(iVert)=idx
idx=idx+AdjGraph % ListDegree(iVert)
END DO
ListStatus(1)=1
DO
IsFinished=1
DO iVert=1,nbVert
IF (ListStatus(iVert) == 1) THEN