-
Notifications
You must be signed in to change notification settings - Fork 1
/
wwm_parall_solver.F90
3348 lines (3302 loc) · 130 KB
/
wwm_parall_solver.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"
! I5 is under the assumptions that we have a lot of memory
! and tries to minimize the number of MPI exchanges and
! to have the processors be as busy as possible
! We use memory ordered as AC(MNP,MSC,MDC)
! I5B is the same as I5. We use memory ordered as AC(MSC,MDC,MNP)
! so reordering at the beginning but less operations later on.
#undef DEBUG
!#define DEBUG
! This is for the reordering of ASPAR_pc and hopefully higher speed
! in the application of the preconditioner.
#undef REORDER_ASPAR_PC
#define REORDER_ASPAR_PC
! This is for the computation of ASPAR_block by a block algorithm
! with hopefully higher speed.
#undef ASPAR_B_COMPUTE_BLOCK
#define ASPAR_B_COMPUTE_BLOCK
! Either we use the SCHISM exchange routine or ours that exchanges only
! the ghost nodes and not the interface nodes.
#undef NO_SELFE_EXCH
#define NO_SELFE_EXCH
! Repeated CX/CY computations but less memory used.
#undef NO_MEMORY_CX_CY
#define NO_MEMORY_CX_CY
! For the SOR preconditioner, we can actually compute directly
! from the matrix since it is so simple.
#undef SOR_DIRECT
#define SOR_DIRECT
!
#undef SINGLE_LOOP_AMATRIX
#define SINGLE_LOOP_AMATRIX
!
! More complexity! Some options excludes other!
!
#if defined REORDER_ASPAR_PC && defined SOR_DIRECT
# undef REORDER_ASPAR_PC
#endif
!**********************************************************************
!* We have to think on how the system is solved. Many questions are *
!* mixed: the ordering of the nodes, the ghost nodes, the aspar array *
!* Here is a repository of the conclusions that have been reached *
!* *
!* Ordering 1> should be that way: We have two global nodes i and j. *
!* -- If i and j belong to a common local grid, then we select the *
!* grid of lowest color and decide whether ipgl(i) < ipgl(j) *
!* -- If i and j belong to two different grid then *
!* ---If Color(i) < Color(j) or reverse we decide by that *
!* ---If Color(i) = Color(j) we decide by i<j or not (but it *
!* does not matter to the solution) *
!* The functions WRITE_EXPLICIT_ORDERING does exactly that and *
!* provides an ordering that can be used. That is we start with the *
!* nodes of lowest color and index until we arrive at highest color *
!* *
!* The ASPAR is computed correctly only on 1:NP_RES but this can be *
!* extended by exchange routines. *
!* We Compute on the resident nodes only. This means loops over *
!* IP=1,NP_RES and backwards. This means that we do not have to do *
!* exchanges of ASPAR values. Only the resident nodes are sent. *
!* This is smaller and this is all that we ever need. *
!* *
!* WRONG APPROACHES: *
!* to use all nodes 1:MNP may look simpler but it forces to have the *
!* following property of the NNZ, IA, JA arrays. If two vertices *
!* i and j are adjacent in a grid G, then they are adjacent in ANY *
!* of the grid in which they are both contained. *
!* This property is actually not satisfied in general. *
!* We could extend the IA, JA arrays by *
!* adding some vertices but that looks quite hazardous idea and it *
!* it is actually not needed by the ILU0 preconditioner and other *
!* *
!* PROBLEM: *
!* There is an asymmetry in the construction of the ordering. *
!* We start from low colors and upwards. If we had started with *
!* high colors and gone downwards, then we get a different ordering *
!* (even if we take the opposite, because of the interface nodes) *
!* This requires the construction of many mappings. *
!* Our approach is actually to rebuild separate node sets. *
!* *
!* CHECKS: *
!* ---The sum of number of non-zero entries in Jstatus_L over all *
!* nodes should be equal to the sum of number of non-zero entries *
!* of Jstatus_U over all nodes. *
!* This is because number of upper diagonal entries should be *
!* equal to number of lower diagonal entries. *
!* ---We CANNOT have Jstatus_L(J)=1 and Jstatus_U(J)=1, i.e. a matrix *
!* entry cannot be both lower and upper. *
!* ---We have sum of Jstatus_L + sum J_status_U + np_global should *
!* be equal to NNZ_global *
!* *
!* So, procedure is as follows: *
!* ---compute ASPAR on 1,NP_RES nodes and no synchronization *
!* ---compute on IP=1,NP_RES for L solving *
!* ---export to grids of higher rank, the values on nodes 1,NP_RES *
!* only. The other ghost points have invalid values or are *
!* resident of other grids of lower rank. (at this stage, some *
!* ghost values are wrong but are not exported) *
!* ---export to grid of lower rank in order to correct their ghost *
!* values and get the value *
!* ---compute on IP=NP_RES,1,-1 for U solving *
!* ---export to grid of lower rank. *
!* Do everything similarly to L solve. *
!* *
!* The basic approach is that we compute at a node S if and only if *
!* it is a resident node. The twist come because some nodes are *
!* resident for TWO domains. This is why we have the CovLower *
!* We need to create disjoint domains for each node, so that *
!* we have sum sum(CovLower) = np_global *
!* *
!* At the end of the resolution of the system, we need to do the *
!* synchronization with respect to the unused nodes. *
!* Mystery?: When we apply the function, we do it on 1:NP_RES and *
!* then call synchronizer. So, this means we need to do the *
!* synchronization after the call to the preconditioner. *
!* But there may be space for improvements here. *
!* *
!* Description of specific exchange arrays: *
!* ---wwm_p2dsend_type/wwm_p2drecv_type *
!* The points of 1:NP_RES are sent to nodes that contained them *
!* length=1 *
!* ---wwmtot_p2dsend_type/wwmtot_p2drecv_type *
!* same as above but length=MSC*MDC *
!* ---blk_p2dsend_type/blk_p2drecv_type *
!* same as above but length=maxBlockLength for matrix exchanges *
!* ---wwmmat_p2dsend_type/wwmmat_p2drecv_type *
!* exchange of correct matrix elements, i.e. elements A(I,J) *
!* with I<=NP_RES *
!* length is 1. *
!* ---u2l_p2dsend_type/u2l_p2drecv_type *
!* upper 2 lower exchange arrays, depends on CovLower, so on *
!* the coloring chosen. length=maxBlockLength *
!* exchange are from upper to lower. *
!* ---sync_p2dsend_type/sync_p2drecv_type *
!* synchronize value, i.e. the CovLower=1 values are send to all *
!* nodes. Length is MSC*MDC *
!**********************************************************************
#if defined WWM_SOLVER && defined MPI_PARALL_GRID
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE I5B_EXCHANGE_P4D_WWM(LocalColor, AC)
USE DATAPOOL, only : MSC, MDC, rkind, LocalColorInfo
USE DATAPOOL, only : wwm_nnbr_send, wwm_nnbr_recv
USE DATAPOOL, only : wwm_ListNeigh_send, wwm_ListNeigh_recv
USE DATAPOOL, only : wwmtot_p2dsend_type, wwmtot_p2drecv_type
USE DATAPOOL, only : wwm_p2dsend_type, wwm_p2drecv_type
USE DATAPOOL, only : wwm_p2dsend_rqst, wwm_p2drecv_rqst
USE DATAPOOL, only : wwm_p2dsend_stat, wwm_p2drecv_stat
USE DATAPOOL, only : ZERO, NP_RES, MNP
USE datapool, only : comm, ierr, myrank
implicit none
type(LocalColorInfo), intent(in) :: LocalColor
real(rkind), intent(inout) :: AC(MSC,MDC,MNP)
integer iSync, iRank
integer IS, ID, IP
real(rkind) SumErr, Lerror
real(rkind) :: ACtest(MSC,MDC,MNP)
real(rkind) :: U1(MNP), U2(MNP)
CALL I5B_TOTAL_COHERENCY_ERROR_NPRES(MSC, AC, Lerror)
! Print *, 'NP_RES cohenrency error=', Lerror
#ifdef DEBUG
WRITE(740+myrank,*) 'I5B_EXCHANGE_P4D_WWM, begin, sum(AC)=', sum(AC)
FLUSH(740+myrank)
#endif
ACtest=AC
SumErr=ZERO
DO IS=1,MSC
DO ID=1,MDC
U1=AC(IS,ID,:)
U2=AC(IS,ID,:)
DO iSync=1,wwm_nnbr_send
iRank=wwm_ListNeigh_send(iSync)
CALL mpi_isend(U1, 1, wwm_p2dsend_type(iSync), iRank-1, 1020, comm, wwm_p2dsend_rqst(iSync), ierr)
END DO
DO iSync=1,wwm_nnbr_recv
iRank=wwm_ListNeigh_recv(iSync)
call mpi_irecv(U2,1,wwm_p2drecv_type(iSync),iRank-1,1020,comm,wwm_p2drecv_rqst(iSync),ierr)
END DO
IF (wwm_nnbr_send > 0) THEN
call mpi_waitall(wwm_nnbr_send, wwm_p2dsend_rqst, wwm_p2dsend_stat,ierr)
END IF
IF (wwm_nnbr_recv > 0) THEN
call mpi_waitall(wwm_nnbr_recv, wwm_p2drecv_rqst, wwm_p2drecv_stat,ierr)
END IF
DO IP=1,NP_RES
SumErr=SumErr + abs(U1(IP) - U2(IP))
END DO
END DO
END DO
#ifdef DEBUG
WRITE(740+myrank,*) 'Total SumErr=', SumErr
FLUSH(740+myrank)
#endif
DO iSync=1,wwm_nnbr_send
iRank=wwm_ListNeigh_send(iSync)
CALL mpi_isend(ACtest, 1, wwmtot_p2dsend_type(iSync), iRank-1, 1020, comm, wwm_p2dsend_rqst(iSync), ierr)
END DO
DO iSync=1,wwm_nnbr_recv
iRank=wwm_ListNeigh_recv(iSync)
call mpi_irecv(AC,1,wwmtot_p2drecv_type(iSync),iRank-1,1020,comm,wwm_p2drecv_rqst(iSync),ierr)
END DO
IF (wwm_nnbr_send > 0) THEN
call mpi_waitall(wwm_nnbr_send, wwm_p2dsend_rqst, wwm_p2dsend_stat,ierr)
END IF
IF (wwm_nnbr_recv > 0) THEN
call mpi_waitall(wwm_nnbr_recv, wwm_p2drecv_rqst, wwm_p2drecv_stat,ierr)
END IF
SumErr=ZERO
DO IS=1,MSC
DO ID=1,MDC
DO IP=1,NP_RES
SumErr=SumErr + abs(AC(IS,ID,IP) - ACtest(IS,ID,IP))
END DO
END DO
END DO
#ifdef DEBUG
WRITE(740+myrank,*) 'SumErr=', SumErr
FLUSH(740+myrank)
#endif
#ifdef DEBUG
WRITE(740+myrank,*) 'I5B_EXCHANGE_P4D_WWM, end, sum(AC)=', sum(AC)
FLUSH(740+myrank)
#endif
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE I5B_EXCHANGE_SL_WWM(LocalColor, AC)
USE DATAPOOL, only : MSC, MDC, rkind, LocalColorInfo
USE DATAPOOL, only : wwm_nnbr_send_sl, wwm_nnbr_recv_sl
USE DATAPOOL, only : wwm_ListNeigh_send_sl, wwm_ListNeigh_recv_sl, wwm_ListNeigh_send
USE DATAPOOL, only : wwmsl_send_type, wwmsl_recv_type
USE DATAPOOL, only : wwmsl_send_rqst, wwmsl_recv_rqst
USE DATAPOOL, only : wwmsl_send_stat, wwmsl_recv_stat
USE DATAPOOL, only : ZERO, NP_RES, MNP
USE datapool, only : comm, ierr, myrank
implicit none
type(LocalColorInfo), intent(in) :: LocalColor
real(rkind), intent(inout) :: AC(MSC,MDC,MNP)
integer iSync, iRank
DO iSync=1,wwm_nnbr_send_sl
iRank=wwm_ListNeigh_send(iSync)
CALL mpi_isend(AC, 1, wwmsl_send_type(iSync), iRank-1, 1020, comm, wwmsl_send_rqst(iSync), ierr)
END DO
DO iSync=1,wwm_nnbr_recv_sl
iRank=wwm_ListNeigh_recv_sl(iSync)
call mpi_irecv(AC,1,wwmsl_recv_type(iSync),iRank-1,1020,comm,wwmsl_recv_rqst(iSync),ierr)
END DO
IF (wwm_nnbr_send_sl > 0) THEN
call mpi_waitall(wwm_nnbr_send_sl, wwmsl_send_rqst, wwmsl_send_stat,ierr)
END IF
IF (wwm_nnbr_recv_sl > 0) THEN
call mpi_waitall(wwm_nnbr_recv_sl, wwmsl_recv_rqst, wwmsl_recv_stat,ierr)
END IF
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE I5B_EXCHANGE_ASPAR(LocalColor, ASPAR_bl)
USE DATAPOOL, only: comm, ierr, myrank, ierr, wwm_nnbr_m_send, wwm_ListNeigh_m_send
use datapool, only: wwmmat_p2dsend_type, wwmmat_p2dsend_rqst, wwm_nnbr_m_recv, wwm_ListNeigh_m_recv
use datapool, only: wwmmat_p2drecv_type, wwmmat_p2drecv_rqst, LocalColorInfo, rkind
use datapool, only: wwmmat_p2drecv_stat, wwmmat_p2dsend_stat, MSC, MDC, NNZ
implicit none
type(LocalColorInfo), intent(in) :: LocalColor
real(rkind), intent(inout) :: ASPAR_bl(MSC,MDC,NNZ)
integer I, iProc
do I=1,wwm_nnbr_m_send
iProc=wwm_ListNeigh_m_send(I)
call mpi_isend(ASPAR_bl,1,wwmmat_p2dsend_type(I),iProc,991,comm,wwmmat_p2dsend_rqst(i),ierr)
enddo
do I=1,wwm_nnbr_m_recv
iProc=wwm_ListNeigh_m_recv(I)
call mpi_irecv(ASPAR_bl,1,wwmmat_p2drecv_type(I),iProc,991,comm,wwmmat_p2drecv_rqst(i),ierr)
enddo
IF (wwm_nnbr_m_recv .gt. 0) THEN
call mpi_waitall(wwm_nnbr_m_recv,wwmmat_p2drecv_rqst,wwmmat_p2drecv_stat,ierr)
END IF
IF (wwm_nnbr_m_send .gt. 0) THEN
call mpi_waitall(wwm_nnbr_m_send,wwmmat_p2dsend_rqst,wwmmat_p2dsend_stat,ierr)
END IF
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE COLLECT_ALL_COVLOWER(LocalColor)
USE DATAPOOL
implicit none
type(LocalColorInfo), intent(inout) :: LocalColor
integer, allocatable :: rbuf_int(:)
integer len, iProc, IP, idx, sumMNP
sumMNP=sum(ListMNP)
allocate(LocalColor % ListCovLower(sumMNP), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 18')
IF (myrank == 0) THEN
idx=0
DO IP=1,MNP
idx=idx+1
LocalColor % ListCovLower(idx)=LocalColor % CovLower(IP)
END DO
DO iProc=2,nproc
len=ListMNP(iProc)
allocate(rbuf_int(len), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 19')
CALL MPI_RECV(rbuf_int,len,itype, iProc-1, 809, comm, istatus, ierr)
DO IP=1,len
idx=idx+1
LocalColor % ListCovLower(idx)=rbuf_int(IP)
END DO
deallocate(rbuf_int)
END DO
DO iProc=2,nproc
CALL MPI_SEND(LocalColor % ListCovLower,sumMNP,itype, iProc-1, 811, comm, ierr)
END DO
ELSE
CALL MPI_SEND(LocalColor % CovLower,MNP,itype, 0, 809, comm, ierr)
CALL MPI_RECV(LocalColor % ListCovLower,sumMNP,itype, 0, 811, comm, istatus, ierr)
END IF
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE CREATE_WWM_P2D_EXCH
USE DATAPOOL
implicit none
integer :: ListFirst(nproc)
integer :: ListCommon_recv(nproc)
integer :: ListCommon_send(nproc)
integer :: ListMapped(np_global)
integer :: ListMappedB(np_global)
integer, allocatable :: dspl_send(:), dspl_recv(:)
integer, allocatable :: dspl_send_tot(:), dspl_recv_tot(:)
integer IP, IP_glob, iProc, MNPloc, idx, NP_RESloc
integer iNeigh, IPmap, nbCommon
integer nbCommon_send, nbCommon_recv, idx_send, idx_recv
integer nbCommon_send_sl, nbCommon_recv_sl
integer sumNbCommon_send, sumNbCommon_recv
integer idxDspl_send, idxDspl_recv
ListFirst=0
DO iProc=2,nproc
ListFirst(iProc)=ListFirst(iProc-1) + ListMNP(iProc-1)
END DO
!
! First the arrays so that coordinates 1:NP_RES got send
! to all nodes 1:MNP of neighboring components
!
ListMapped=0
DO IP=1,MNP
IP_glob=iplg(IP)
ListMapped(IP_glob)=IP
END DO
wwm_nnbr_send=0
wwm_nnbr_recv=0
ListCommon_send=0
ListCommon_recv=0
DO iProc=1,nproc
IF (iPROC .ne. myrank+1) THEN
MNPloc=ListMNP(iProc)
NP_RESloc=ListNP_RES(iProc)
ListMappedB=0
DO IP=1,MNPloc
IP_glob=ListIPLG(IP+ListFirst(iProc))
ListMappedB(IP_glob)=IP
END DO
!
nbCommon_recv=0
DO IP=1,NP_RESloc
IP_glob=ListIPLG(IP+ListFirst(iProc))
IF (ListMapped(IP_glob).gt.0) THEN
nbCommon_recv=nbCommon_recv+1
END IF
END DO
IF (nbCommon_recv .gt. 0) THEN
wwm_nnbr_recv=wwm_nnbr_recv+1
ListCommon_recv(iProc)=nbCommon_recv
END IF
!
nbCommon_send=0
DO IP=1,NP_RES
IP_glob=iplg(IP)
IF (ListMappedB(IP_glob).gt.0) THEN
nbCommon_send=nbCommon_send+1
END IF
END DO
IF (nbCommon_send .gt. 0) THEN
wwm_nnbr_send=wwm_nnbr_send+1
ListCommon_send(iProc)=nbCommon_send
END IF
END IF
END DO
allocate(wwm_ListNbCommon_send(wwm_nnbr_send), wwm_ListNbCommon_recv(wwm_nnbr_recv), wwm_ListNeigh_send(wwm_nnbr_send), wwm_ListNeigh_recv(wwm_nnbr_recv), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 27')
idx_send=0
idx_recv=0
sumNbCommon_send=0
sumNbCommon_recv=0
DO iProc=1,nproc
IF (ListCommon_send(iProc) .gt. 0) THEN
idx_send=idx_send+1
wwm_ListNeigh_send(idx_send)=iProc
nbCommon=ListCommon_send(iProc)
wwm_ListNbCommon_send(idx_send)=nbCommon
sumNbCommon_send=sumNbCommon_send+nbCommon
END IF
IF (ListCommon_recv(iProc) .gt. 0) THEN
idx_recv=idx_recv+1
wwm_ListNeigh_recv(idx_recv)=iProc
nbCommon=ListCommon_recv(iProc)
wwm_ListNbCommon_recv(idx_recv)=nbCommon
sumNbCommon_recv=sumNbCommon_recv+nbCommon
END IF
END DO
allocate(wwm_ListDspl_send(sumNbCommon_send), wwm_ListDspl_recv(sumNbCommon_recv), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 28')
wwm_nnbr=0
DO iProc=1,nproc
IF ((ListCommon_send(iProc).gt.0).or.(ListCommon_recv(iProc).gt.0)) THEN
wwm_nnbr=wwm_nnbr+1
END IF
END DO
allocate(wwm_ListNeigh(wwm_nnbr), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 29')
idx=0
DO iProc=1,nproc
IF ((ListCommon_send(iProc).gt.0).or.(ListCommon_recv(iProc).gt.0)) THEN
idx=idx+1
wwm_ListNeigh(idx)=iProc
END IF
END DO
allocate(wwm_p2dsend_rqst(wwm_nnbr_send), wwm_p2drecv_rqst(wwm_nnbr_recv), &
&wwm_p2dsend_stat(MPI_STATUS_SIZE,wwm_nnbr_send), wwm_p2drecv_stat(MPI_STATUS_SIZE,wwm_nnbr_recv), &
&wwm_p2dsend_type(wwm_nnbr_send), wwm_p2drecv_type(wwm_nnbr_recv), &
&wwmtot_p2dsend_type(wwm_nnbr_send), wwmtot_p2drecv_type(wwm_nnbr_recv), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 30')
idxDspl_send=0
DO iNeigh=1,wwm_nnbr_send
iProc=wwm_ListNeigh_send(iNeigh)
MNPloc=ListMNP(iProc)
NP_RESloc=ListNP_RES(iProc)
ListMappedB=0
DO IP=1,MNPloc
IP_glob=ListIPLG(IP+ListFirst(iProc))
ListMappedB(IP_glob)=IP
END DO
nbCommon=wwm_ListNbCommon_send(iNeigh)
allocate(dspl_send(nbCommon), dspl_send_tot(nbCommon), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 31')
idx=0
DO IP=1,NP_RES
IP_glob=iplg(IP)
IF (ListMappedB(IP_glob).gt.0) THEN
IPmap=ListMappedB(IP_glob)
idx=idx+1
dspl_send(idx)=IP-1
dspl_send_tot(idx)=MSC*MDC*(IP-1)
idxDspl_send=idxDspl_send+1
wwm_ListDspl_send(idxDspl_send)=IP
END IF
END DO
call mpi_type_create_indexed_block(nbCommon,1,dspl_send,rtype,wwm_p2dsend_type(iNeigh), ierr)
call mpi_type_commit(wwm_p2dsend_type(iNeigh), ierr)
call mpi_type_create_indexed_block(nbCommon,MSC*MDC,dspl_send_tot,rtype,wwmtot_p2dsend_type(iNeigh), ierr)
call mpi_type_commit(wwmtot_p2dsend_type(iNeigh), ierr)
deallocate(dspl_send, dspl_send_tot)
END DO
idxDspl_recv=0
DO iNeigh=1,wwm_nnbr_recv
iProc=wwm_ListNeigh_recv(iNeigh)
MNPloc=ListMNP(iProc)
NP_RESloc=ListNP_RES(iProc)
nbCommon=wwm_ListNbCommon_recv(iNeigh)
allocate(dspl_recv(nbCommon), dspl_recv_tot(nbCommon), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 32')
idx=0
DO IP=1,NP_RESloc
IP_glob=ListIPLG(IP+ListFirst(iProc))
IF (ListMapped(IP_glob).gt.0) THEN
IPmap=ListMapped(IP_glob)
idx=idx+1
dspl_recv(idx)=IPmap-1
dspl_recv_tot(idx)=MSC*MDC*(IPmap-1)
idxDspl_recv=idxDspl_recv+1
wwm_ListDspl_recv(idxDspl_recv)=IPmap
#ifdef DEBUG
WRITE(800+myrank,*) 'Recv IP=', IPmap, 'IPglob=', IP_glob
FLUSH(800+myrank)
#endif
END IF
END DO
!
call mpi_type_create_indexed_block(nbCommon,1,dspl_recv,rtype,wwm_p2drecv_type(iNeigh),ierr)
call mpi_type_commit(wwm_p2drecv_type(iNeigh), ierr)
call mpi_type_create_indexed_block(nbCommon,MSC*MDC,dspl_recv_tot,rtype,wwmtot_p2drecv_type(iNeigh),ierr)
call mpi_type_commit(wwmtot_p2drecv_type(iNeigh), ierr)
deallocate(dspl_recv, dspl_recv_tot)
END DO
!
! First the arrays so that coordinates 1:NP_RES got send
! to all nodes NP_RES+1:MNP of neighboring components
! "sl" : "super local"
!
ListMapped=0
DO IP=NP_RES+1,MNP
IP_glob=iplg(IP)
ListMapped(IP_glob)=IP
END DO
wwm_nnbr_send_sl=0
wwm_nnbr_recv_sl=0
ListCommon_send=0
ListCommon_recv=0
DO iNeigh=1,wwm_nnbr
iProc=wwm_ListNeigh(iNeigh)
MNPloc=ListMNP(iProc)
NP_RESloc=ListNP_RES(iProc)
ListMappedB=0
DO IP=NP_RESloc+1,MNPloc
IP_glob=ListIPLG(IP+ListFirst(iProc))
ListMappedB(IP_glob)=IP
END DO
!
nbCommon_recv_sl=0
DO IP=1,NP_RESloc
IP_glob=ListIPLG(IP+ListFirst(iProc))
IF (ListMapped(IP_glob).gt.0) THEN
nbCommon_recv_sl=nbCommon_recv_sl+1
END IF
END DO
IF (nbCommon_recv_sl .gt. 0) THEN
wwm_nnbr_recv_sl=wwm_nnbr_recv_sl+1
ListCommon_recv(iProc)=nbCommon_recv_sl
END IF
!
nbCommon_send_sl=0
DO IP=1,NP_RES
IP_glob=iplg(IP)
IF (ListMappedB(IP_glob).gt.0) THEN
nbCommon_send_sl=nbCommon_send_sl+1
END IF
END DO
IF (nbCommon_send_sl .gt. 0) THEN
wwm_nnbr_send_sl=wwm_nnbr_send_sl+1
ListCommon_send(iProc)=nbCommon_send_sl
END IF
END DO
allocate(wwm_ListNbCommon_send_sl(wwm_nnbr_send_sl), wwm_ListNbCommon_recv_sl(wwm_nnbr_recv_sl), wwm_ListNeigh_send_sl(wwm_nnbr_send_sl), wwm_ListNeigh_recv_sl(wwm_nnbr_recv_sl), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 33')
idx_send=0
idx_recv=0
DO iProc=1,nproc
nbCommon=ListCommon_send(iProc)
IF (nbCommon .gt. 0) THEN
idx_send=idx_send+1
wwm_ListNeigh_send_sl(idx_send)=iProc
wwm_ListNbCommon_send_sl(idx_send)=nbCommon
END IF
nbCommon=ListCommon_recv(iProc)
IF (nbCommon .gt. 0) THEN
idx_recv=idx_recv+1
wwm_ListNeigh_recv_sl(idx_recv)=iProc
wwm_ListNbCommon_recv_sl(idx_recv)=nbCommon
END IF
END DO
allocate(wwmsl_send_rqst(wwm_nnbr_send_sl), wwmsl_recv_rqst(wwm_nnbr_recv_sl), &
&wwmsl_send_stat(MPI_STATUS_SIZE,wwm_nnbr_send_sl), wwmsl_recv_stat(MPI_STATUS_SIZE,wwm_nnbr_recv_sl), &
&wwmsl_send_type(wwm_nnbr_send_sl), wwmsl_recv_type(wwm_nnbr_recv_sl), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 35')
idxDspl_send=0
DO iNeigh=1,wwm_nnbr_send_sl
iProc=wwm_ListNeigh_send_sl(iNeigh)
MNPloc=ListMNP(iProc)
NP_RESloc=ListNP_RES(iProc)
ListMappedB=0
DO IP=NP_RESloc+1,MNPloc
IP_glob=ListIPLG(IP+ListFirst(iProc))
ListMappedB(IP_glob)=IP
END DO
nbCommon=wwm_ListNbCommon_send_sl(iNeigh)
allocate(dspl_send(nbCommon), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 36')
idx=0
DO IP=1,NP_RES
IP_glob=iplg(IP)
IF (ListMappedB(IP_glob).gt.0) THEN
IPmap=ListMappedB(IP_glob)
idx=idx+1
dspl_send(idx)=MSC*MDC*(IP-1)
END IF
END DO
call mpi_type_create_indexed_block(nbCommon,MSC*MDC,dspl_send,rtype,wwmsl_send_type(iNeigh), ierr)
call mpi_type_commit(wwmsl_send_type(iNeigh), ierr)
deallocate(dspl_send)
END DO
idxDspl_recv=0
DO iNeigh=1,wwm_nnbr_recv_sl
iProc=wwm_ListNeigh_recv_sl(iNeigh)
MNPloc=ListMNP(iProc)
NP_RESloc=ListNP_RES(iProc)
nbCommon=wwm_ListNbCommon_recv_sl(iNeigh)
allocate(dspl_recv(nbCommon), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 37')
idx=0
DO IP=1,NP_RESloc
IP_glob=ListIPLG(IP+ListFirst(iProc))
IF (ListMapped(IP_glob).gt.0) THEN
IPmap=ListMapped(IP_glob)
idx=idx+1
dspl_recv(idx)=MSC*MDC*(IPmap-1)
END IF
END DO
call mpi_type_create_indexed_block(nbCommon,MSC*MDC,dspl_recv,rtype,wwmsl_recv_type(iNeigh),ierr)
call mpi_type_commit(wwmsl_recv_type(iNeigh), ierr)
deallocate(dspl_recv)
END DO
END SUBROUTINE
!**********************************************************************
!* This subroutine creates array for exchanging matrix entries *
!* Process cannot get all the matrix entries right, and so they need *
!* to exchange data. *
!* Matrix entries A(i,j) with i <= NP_RES are correct and are *
!* exported *
!**********************************************************************
SUBROUTINE CREATE_WWM_MAT_P2D_EXCH
USE DATAPOOL
implicit none
integer :: ListFirstMNP(nproc), ListFirstNNZ(nproc)
integer :: ListCommon_send(nproc), ListCommon_recv(nproc)
integer :: ListMapped(np_global)
integer :: ListMappedB(np_global)
integer, allocatable :: dspl_send(:), dspl_recv(:)
integer nbCommon_send, nbCommon_recv
integer IAfirst
integer IP, JP, I, J, J2, IP_glob, JP_glob, iProc
integer MNPloc, NP_RESloc, JP_j
integer IPloc, JPloc, Jfound, idx
integer iNeigh, nbCommon
integer sumNbCommon_send, sumNbCommon_recv
integer idxDspl_send, idxDspl_recv
ListFirstNNZ=0
ListFirstMNP=0
DO iProc=2,nproc
ListFirstMNP(iProc)=ListFirstMNP(iProc-1) + ListMNP(iProc-1)
ListFirstNNZ(iProc)=ListFirstNNZ(iProc-1) + ListNNZ(iProc-1)
END DO
ListMapped=0
DO IP=1,MNP
IP_glob=iplg(IP)
ListMapped(IP_glob)=IP
END DO
wwm_nnbr_m_recv=0
wwm_nnbr_m_send=0
ListCommon_recv=0
DO I=1,wwm_nnbr_recv
iProc=wwm_ListNeigh_recv(I)
NP_RESloc=ListNP_RES(iProc)
MNPloc=ListMNP(iProc)
ListMappedB=0
DO IP=1,MNPloc
IP_glob=ListIPLG(IP+ListFirstMNP(iProc))
ListMappedB(IP_glob)=IP
END DO
nbCommon_recv=0
DO IP=1,NP_RESloc
IP_glob=ListIPLG(IP+ListFirstMNP(iProc))
IPloc=ListMapped(IP_glob)
IF (IPloc.gt.0) THEN
IAfirst=ListFirstMNP(iProc) + iProc-1
DO J=ListIA(IP+IAfirst),ListIA(IP+IAfirst+1)-1
JP=ListJA(J+ListFirstNNZ(iProc))
JP_glob=ListIPLG(JP+ListFirstMNP(iProc))
JPloc=ListMapped(JP_glob)
IF (JPloc.gt.0) THEN
JFOUND=-1
DO J2=IA(IPloc),IA(IPloc+1)-1
IF (JA(J2) == JPloc) THEN
JFOUND=J2
END IF
END DO
IF (JFOUND .gt. 0) THEN
nbCommon_recv=nbCommon_recv+1
END IF
END IF
END DO
END IF
END DO
IF (nbCommon_recv .gt. 0) THEN
wwm_nnbr_m_recv=wwm_nnbr_m_recv+1
ListCommon_recv(iProc)=nbCommon_recv
END IF
END DO
ListCommon_send=0
DO I=1,wwm_nnbr_send
iProc=wwm_ListNeigh_send(I)
NP_RESloc=ListNP_RES(iProc)
MNPloc=ListMNP(iProc)
ListMappedB=0
DO IP=1,MNPloc
IP_glob=ListIPLG(IP+ListFirstMNP(iProc))
ListMappedB(IP_glob)=IP
END DO
nbCommon_send=0
DO IP=1,NP_RES
IP_glob=iplg(IP)
IPloc=ListMappedB(IP_glob)
IF (IPloc.gt.0) THEN
DO J=IA(IP),IA(IP+1)-1
JP=JA(J)
JP_glob=iplg(JP)
JPloc=ListMappedB(JP_glob)
IF (JPloc.gt.0) THEN
IAfirst=ListFirstMNP(iProc) + iProc-1
JFOUND=-1
DO J2=ListIA(IPloc+IAfirst),ListIA(IPloc+IAfirst+1)-1
JP_j=ListJA(J2+ListFirstNNZ(iProc))
IF (JP_j == JPloc) THEN
JFOUND=J2
END IF
END DO
IF (JFOUND .gt. 0) THEN
nbCommon_send=nbCommon_send+1
END IF
END IF
END DO
END IF
END DO
IF (nbCommon_send .gt. 0) THEN
wwm_nnbr_m_send=wwm_nnbr_m_send+1
ListCommon_send(iProc)=nbCommon_send
END IF
END DO
allocate(wwmmat_p2dsend_rqst(wwm_nnbr_m_send), wwmmat_p2drecv_rqst(wwm_nnbr_m_recv), &
&wwmmat_p2dsend_stat(MPI_STATUS_SIZE,wwm_nnbr_m_send), &
&wwmmat_p2drecv_stat(MPI_STATUS_SIZE,wwm_nnbr_m_recv), wwmmat_p2dsend_type(wwm_nnbr_m_send), &
&wwmmat_p2drecv_type(wwm_nnbr_m_recv), wwm_ListNbCommon_m_send(wwm_nnbr_m_send), &
&wwm_ListNbCommon_m_recv(wwm_nnbr_m_recv), wwm_ListNeigh_m_recv(wwm_nnbr_m_recv), &
&wwm_ListNeigh_m_send(wwm_nnbr_m_send), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 38')
idx=0
sumNbCommon_send=0
DO iProc=1,nproc
IF (ListCommon_send(iProc) .gt. 0) THEN
idx=idx+1
wwm_ListNeigh_m_send(idx)=iProc-1
nbCommon=ListCommon_send(iProc)
wwm_ListNbCommon_m_send(idx)=nbCommon
sumNbCommon_send=sumNbCommon_send+nbCommon
END IF
END DO
idx=0
sumNbCommon_recv=0
DO iProc=1,nproc
IF (ListCommon_recv(iProc) .gt. 0) THEN
idx=idx+1
wwm_ListNeigh_m_recv(idx)=iProc-1
nbCommon=ListCommon_recv(iProc)
wwm_ListNbCommon_m_recv(idx)=nbCommon
sumNbCommon_recv=sumNbCommon_recv+nbCommon
END IF
END DO
allocate(wwm_ListDspl_m_send(sumNbCommon_send), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 39')
idxDspl_send=0
DO iNeigh=1,wwm_nnbr_m_send
iProc=wwm_ListNeigh_m_send(iNeigh)+1
MNPloc=ListMNP(iProc)
ListMappedB=0
DO IP=1,MNPloc
IP_glob=ListIPLG(IP+ListFirstMNP(iProc))
ListMappedB(IP_glob)=IP
END DO
nbCommon=wwm_ListNbCommon_m_send(iNeigh)
allocate(dspl_send(nbCommon), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 40')
idx=0
DO IP=1,NP_RES
IP_glob=iplg(IP)
IPloc=ListMappedB(IP_glob)
IF (IPloc.gt.0) THEN
DO J=IA(IP),IA(IP+1)-1
JP=JA(J)
JP_glob=iplg(JP)
JPloc=ListMappedB(JP_glob)
IF (JPloc .gt. 0) THEN
IAfirst=ListFirstMNP(iProc) + iProc-1
JFOUND=-1
DO J2=ListIA(IPloc+IAfirst),ListIA(IPloc+IAfirst+1)-1
JP_j=ListJA(J2+ListFirstNNZ(iProc))
IF (JP_j == JPloc) THEN
JFOUND=J2
END IF
END DO
IF (JFOUND .gt. 0) THEN
idxDspl_send=idxDspl_send+1
wwm_ListDspl_m_send(idxDspl_send)=J
idx=idx+1
dspl_send(idx)=(J-1)*MSC*MDC
END IF
END IF
END DO
END IF
END DO
call mpi_type_create_indexed_block(nbCommon,MSC*MDC,dspl_send,rtype,wwmmat_p2dsend_type(iNeigh), ierr)
call mpi_type_commit(wwmmat_p2dsend_type(iNeigh), ierr)
deallocate(dspl_send)
END DO
allocate(wwm_ListDspl_m_recv(sumNbCommon_recv), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 41')
idxDspl_recv=0
DO iNeigh=1,wwm_nnbr_m_recv
iProc=wwm_ListNeigh_m_recv(iNeigh)+1
nbCommon=wwm_ListNbCommon_m_recv(iNeigh)
allocate(dspl_recv(nbCommon), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 42')
NP_RESloc=ListNP_RES(iProc)
idx=0
DO IP=1,NP_RESloc
IP_glob=ListIPLG(IP+ListFirstMNP(iProc))
IPloc=ListMapped(IP_glob)
IF (IPloc.gt.0) THEN
IAfirst=ListFirstMNP(iProc) + iProc-1
DO J=ListIA(IP+IAfirst),ListIA(IP+IAfirst+1)-1
JP=ListJA(J+ListFirstNNZ(iProc))
JP_glob=ListIPLG(JP+ListFirstMNP(iProc))
JPloc=ListMapped(JP_glob)
IF (JPloc.gt.0) THEN
JFOUND=-1
DO J2=IA(IPloc),IA(IPloc+1)-1
IF (JA(J2) == JPloc) THEN
JFOUND=J2
END IF
END DO
IF (JFOUND /= -1) THEN
idxDspl_recv=idxDspl_recv+1
wwm_ListDspl_m_recv(idxDspl_recv)=Jfound
idx=idx+1
dspl_recv(idx)=(Jfound-1)*MSC*MDC
END IF
END IF
END DO
END IF
END DO
call mpi_type_create_indexed_block(nbCommon,MSC*MDC,dspl_recv,rtype,wwmmat_p2drecv_type(iNeigh), ierr)
call mpi_type_commit(wwmmat_p2drecv_type(iNeigh), ierr)
deallocate(dspl_recv)
END DO
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE BUILD_MULTICOLORING(AdjGraph, ListColor)
USE datapool, only : myrank, Graph
implicit none
type(Graph), intent(in) :: AdjGraph
integer, intent(out) :: ListColor(AdjGraph%nbVert)
integer, allocatable :: CurrColor(:)
integer MaxDeg, iVert, eVert, eColor, eDeg
integer idx, I, ChromaticNr, nbVert
integer, allocatable :: ListPosFirst(:)
integer eColorF, iVertFound, eAdjColor
integer nbUndef, MinDeg, eAdj, MinUndef, PosMin
integer istat
MaxDeg=AdjGraph % MaxDeg
nbVert=AdjGraph % nbVert
allocate(CurrColor(MaxDeg+1), ListPosFirst(nbVert), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 43')
ListColor=0
idx=0
DO iVert=1,nbVert
ListPosFirst(iVert)=idx
idx=idx+AdjGraph % ListDegree(iVert)
END DO
MinDeg=MaxDeg+3
PosMin=-1
DO iVert=1,nbVert
eDeg=AdjGraph % ListDegree(iVert)
IF (eDeg .lt. MinDeg) THEN
MinDeg=eDeg
PosMin=iVert
END IF
END DO
idx=ListPosFirst(PosMin)
DO I=0,MinDeg
IF (I.eq.0) THEN
eVert=PosMin
ELSE
eVert=AdjGraph % ListEdge(idx+I,2)
END IF
ListColor(eVert)=I+1
END DO
DO
MinUndef=nbVert
iVertFound=0
DO iVert=1,nbVert
IF (ListColor(iVert) == 0) THEN
idx=ListPosFirst(iVert)
eDeg=AdjGraph % ListDegree(iVert)
nbUndef=0
DO I=1,eDeg
eAdj=AdjGraph % ListEdge(idx+I,2)
eAdjColor=ListColor(eAdj)
IF (eAdjColor == 0) THEN
nbUndef=nbUndef+1
END IF
END DO
IF (nbUndef .lt. MinUndef) THEN
MinUndef=nbUndef
iVertFound=iVert
END IF
END IF
END DO
IF (iVertFound == 0) THEN
EXIT
END IF
eDeg=AdjGraph % ListDegree(iVertFound)
idx=ListPosFirst(iVertFound)
CurrColor=0
DO I=1,eDeg
eVert=AdjGraph % ListEdge(idx+I,2)
eColor=ListColor(eVert)
IF (eColor.gt.0) THEN
CurrColor(eColor)=1
END IF
END DO
eColorF=-1
DO I=1,MaxDeg+1
IF (eColorF == -1) THEN
IF (CurrColor(I) == 0) THEN
eColorF=I
END IF
END IF
END DO
ListColor(iVertFound)=eColorF
END DO
deallocate(ListPosFirst, CurrColor)
ChromaticNr=maxval(ListColor)
# ifdef DEBUG
WRITE(740+myrank,*) 'ChromaticNr=', ChromaticNr
DO iVert=1,nbVert
WRITE(740+myrank,*) 'iVert=', iVert, 'eColor=', ListColor(iVert)
END DO
# endif
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE DeallocateGraph(TheGraph)
USE DATAPOOL, only : Graph
implicit none
type(Graph), intent(inout) :: TheGraph
deallocate(TheGraph % ListDegree)
deallocate(TheGraph % ListEdge)
END SUBROUTINE
!**********************************************************************
!* *
!**********************************************************************
SUBROUTINE INIT_BLOCK_FREQDIR(LocalColor, Nblock)
USE DATAPOOL, only : MNP, MDC, MSC, LocalColorInfo, rkind, stat
USE DATAPOOL, only : wwm_nnbr_send, wwm_nnbr_recv
USE DATAPOOL, only : wwm_ListNbCommon_send, wwm_ListNbCommon_recv
USE DATAPOOL, only : XP, YP, rtype, ierr, myrank, iplg
implicit none
type(LocalColorInfo), intent(inout) :: LocalColor
integer, intent(in) :: Nblock
integer Ntot, Hlen, Delta, iBlock, idx, ID, IS
integer lenBlock, maxBlockLength
integer istat
WRITE(STAT%FHNDL,'("+TRACE......",A)') 'ENTERING INIT_BLOCK_FREQDIR'
FLUSH(STAT%FHNDL)
Ntot=MSC*MDC
Hlen=INT(MyREAL(Ntot)/Nblock)
Delta=Ntot - Hlen*Nblock
iBlock=1
idx=1
LocalColor % Nblock=Nblock
IF (Delta == 0) THEN
maxBlockLength=Hlen
ELSE
maxBlockLength=Hlen+1
ENDIF
allocate(LocalColor % ISindex(Nblock, maxBlockLength), LocalColor % IDindex(Nblock, maxBlockLength), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 44')
DO IS=1,MSC
DO ID=1,MDC
LocalColor % ISindex(iBlock, idx)=IS
LocalColor % IDindex(iBlock, idx)=ID
IF (iBlock <= Delta) THEN
lenBlock=Hlen+1
ELSE
lenBlock=Hlen
END IF
idx=idx+1
IF (idx > lenBlock) THEN
iBlock=iBlock+1
idx=1
ENDIF
END DO
END DO
allocate(LocalColor % BlockLength(Nblock), stat=istat)
IF (istat/=0) CALL WWM_ABORT('wwm_parall_solver, allocate error 45')
DO iBlock=1,Nblock