-
Notifications
You must be signed in to change notification settings - Fork 136
/
mpp_domains_misc.inc
2022 lines (1854 loc) · 79.8 KB
/
mpp_domains_misc.inc
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
! -*-f90-*-
!***********************************************************************
!* GNU Lesser General Public License
!*
!* This file is part of the GFDL Flexible Modeling System (FMS).
!*
!* FMS is free software: you can redistribute it and/or modify it under
!* the terms of the GNU Lesser General Public License as published by
!* the Free Software Foundation, either version 3 of the License, or (at
!* your option) any later version.
!*
!* FMS is distributed in the hope that it will be useful, but WITHOUT
!* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
!* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
!* for more details.
!*
!* You should have received a copy of the GNU Lesser General Public
!* License along with FMS. If not, see <http://www.gnu.org/licenses/>.
!***********************************************************************
!> @file
!> @brief Initialization and finalization routines for @ref mpp_domains_mod as well
!! as other utility routines.
!> @ingroup mpp_domains_mod
!> @{
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! !
! MPP_DOMAINS: initialization and termination !
! !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> @brief Initialize domain decomp package.
!!
!> Called to initialize the <TT>mpp_domains_mod</TT> package.
!! <TT>flags</TT> can be set to <TT>MPP_VERBOSE</TT> to have
!! <TT>mpp_domains_mod</TT> keep you informed of what it's up
!! to. <TT>MPP_DEBUG</TT> returns even more information for debugging.
!!
!! <TT>mpp_domains_init</TT> will call <TT>mpp_init</TT>, to make sure
!! <TT>@ref mpp_mod</TT> is initialized. (Repeated
!! calls to <TT>@ref mpp_init</TT> do no harm, so don't worry if you already
!! called it).
subroutine mpp_domains_init(flags)
integer, intent(in), optional :: flags
integer :: n
integer :: io_status, unit
if( module_is_initialized )return
call mpp_init(flags) !this is a no-op if already initialized
module_is_initialized = .TRUE.
pe = mpp_root_pe()
unit = stdlog()
if( mpp_pe() .EQ.mpp_root_pe() ) write( unit,'(/a)' )'MPP_DOMAINS module '//trim(version)
if( PRESENT(flags) )then
debug = flags.EQ.MPP_DEBUG
verbose = flags.EQ.MPP_VERBOSE .OR. debug
domain_clocks_on = flags.EQ.MPP_DOMAIN_TIME
end if
!--- namelist
read (input_nml_file, mpp_domains_nml, iostat=io_status)
if (io_status > 0) then
call mpp_error(FATAL,'=>mpp_domains_init: Error reading mpp_domains_nml')
endif
select case(lowercase(trim(debug_update_domain)))
case("none")
debug_update_level = NO_CHECK
case("fatal")
debug_update_level = FATAL
case("warning")
debug_update_level = WARNING
case("note")
debug_update_level = NOTe
case default
call mpp_error(FATAL, "mpp_domains_init: debug_update_level should be 'none', 'fatal', 'warning', or 'note'")
end select
allocate(nonblock_data(MAX_NONBLOCK_UPDATE))
do n = 1, MAX_NONBLOCK_UPDATE
call init_nonblock_type(nonblock_data(n))
enddo
call mpp_domains_set_stack_size(32768) !default, pretty arbitrary
!NULL_DOMAIN is a domaintype that can be used to initialize to undef
call mpp_define_null_domain(NULL_DOMAIN1d);
call mpp_define_null_domain(NULL_DOMAIN2d);
call mpp_define_null_UG_domain(NULL_DOMAINUG)
if( domain_clocks_on )then
pack_clock = mpp_clock_id( 'Halo pack' )
send_clock = mpp_clock_id( 'Halo send' )
recv_clock = mpp_clock_id( 'Halo recv' )
unpk_clock = mpp_clock_id( 'Halo unpk' )
wait_clock = mpp_clock_id( 'Halo wait' )
send_pack_clock_nonblock = mpp_clock_id( 'Halo pack and send nonblock' )
recv_clock_nonblock = mpp_clock_id( 'Halo recv nonblock' )
unpk_clock_nonblock = mpp_clock_id( 'Halo unpk nonblock' )
wait_clock_nonblock = mpp_clock_id( 'Halo wait nonblock' )
nest_pack_clock = mpp_clock_id( 'nest pack' )
nest_send_clock = mpp_clock_id( 'nest send' )
nest_recv_clock = mpp_clock_id( 'nest recv' )
nest_unpk_clock = mpp_clock_id( 'nest unpk' )
nest_wait_clock = mpp_clock_id( 'nest wait' )
group_pack_clock = mpp_clock_id( 'group pack' )
group_send_clock = mpp_clock_id( 'group send' )
group_recv_clock = mpp_clock_id( 'group recv' )
group_unpk_clock = mpp_clock_id( 'group unpk' )
group_wait_clock = mpp_clock_id( 'group wait' )
nonblock_group_pack_clock = mpp_clock_id( 'nonblock group pack' )
nonblock_group_send_clock = mpp_clock_id( 'nonblock group send' )
nonblock_group_recv_clock = mpp_clock_id( 'nonblock group recv' )
nonblock_group_unpk_clock = mpp_clock_id( 'nonblock group unpk' )
nonblock_group_wait_clock = mpp_clock_id( 'nonblock group wait' )
end if
return
end subroutine mpp_domains_init
!#####################################################################
subroutine init_nonblock_type( nonblock_obj )
type(nonblock_type), intent(inout) :: nonblock_obj
nonblock_obj%recv_pos = 0
nonblock_obj%send_pos = 0
nonblock_obj%recv_msgsize = 0
nonblock_obj%send_msgsize = 0
nonblock_obj%update_flags = 0
nonblock_obj%update_position = 0
nonblock_obj%update_gridtype = 0
nonblock_obj%update_whalo = 0
nonblock_obj%update_ehalo = 0
nonblock_obj%update_shalo = 0
nonblock_obj%update_nhalo = 0
nonblock_obj%request_send_count = 0
nonblock_obj%request_recv_count = 0
nonblock_obj%size_recv(:) = 0
nonblock_obj%type_recv(:) = 0
#ifdef use_libMPI
nonblock_obj%request_send(:) = MPI_REQUEST_NULL
nonblock_obj%request_recv(:) = MPI_REQUEST_NULL
#else
nonblock_obj%request_send(:) = 0
nonblock_obj%request_recv(:) = 0
#endif
nonblock_obj%buffer_pos_send(:) = 0
nonblock_obj%buffer_pos_recv(:) = 0
nonblock_obj%nfields = 0
nonblock_obj%field_addrs(:) = 0
nonblock_obj%field_addrs2(:) = 0
return
end subroutine init_nonblock_type
!#####################################################################
!> @brief Exit <TT>mpp_domains_mod</TT>.
!! Serves no particular purpose, but is provided should you require to
!! re-initialize <TT>mpp_domains_mod</TT>, for some odd reason.
subroutine mpp_domains_exit()
integer :: unit
if( .NOT.module_is_initialized )return
call mpp_max(mpp_domains_stack_hwm)
unit = stdout()
if( mpp_pe().EQ.mpp_root_pe() )write( unit,* )'MPP_DOMAINS_STACK high water mark=', mpp_domains_stack_hwm
module_is_initialized = .FALSE.
return
end subroutine mpp_domains_exit
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! !
! MPP_CHECK_FIELD: Check parallel !
! !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> This routine is used to do parallel checking for 3d data between n and m pe. The comparison is
!! is done on pelist2. When size of pelist2 is 1, we can check the halo; otherwise,
!! halo can not be checked.
subroutine mpp_check_field_3D(field_in, pelist1, pelist2, domain, mesg, &
w_halo, s_halo, e_halo, n_halo, force_abort, position )
real, dimension(:,:,:), intent(in) :: field_in !< field to be checked
integer, dimension(:), intent(in) :: pelist1, pelist2 !< pe list for the two groups
type(domain2d), intent(in) :: domain !< domain for each pe
character(len=*), intent(in) :: mesg !< message to be printed out
!! if differences found
integer, intent(in), optional :: w_halo, s_halo, e_halo, n_halo
!< halo size for west, south, east and north
logical, intent(in), optional :: force_abort !< when true, call mpp_error if any difference
!! found. default value is false.
integer, intent(in), optional :: position !< when domain is symmetry, only value = CENTER is
!! implemented.
integer :: k
character(len=256) :: temp_mesg
do k = 1, size(field_in,3)
write(temp_mesg, '(a, i3)') trim(mesg)//" at level " , k
call mpp_check_field_2d(field_in(:,:,k), pelist1, pelist2, domain, temp_mesg, &
w_halo, s_halo, e_halo, n_halo, force_abort, position )
enddo
end subroutine mpp_check_field_3D
!#####################################################################################
!> This routine is used to do parallel checking for 2d data between n and m pe. The comparison is
!! is done on pelist2. When size of pelist2 is 1, we can check the halo; otherwise,
!! halo can not be checked.
subroutine mpp_check_field_2d(field_in, pelist1, pelist2, domain, mesg, &
w_halo, s_halo, e_halo, n_halo,force_abort, position )
real, dimension(:,:), intent(in) :: field_in !< field to be checked
integer, dimension(:), intent(in) :: pelist1, pelist2 !< pe list for the two groups
type(domain2d), intent(in) :: domain !< domain for each pe
character(len=*), intent(in) :: mesg !< message to be printed out
!! if differences found
integer, intent(in), optional :: w_halo, s_halo, e_halo, n_halo !< halo size for west, south, east and north
logical, intent(in), optional :: force_abort !< when true, call mpp_error if any difference
!! found. default value is false.
integer, intent(in), optional :: position !< when domain is symmetry, only value = CENTER is
!! implemented.
if(present(position)) then
if(position .NE. CENTER .AND. domain%symmetry) call mpp_error(FATAL, &
'mpp_check_field: when domain is symmetry, only value CENTER is implemented, contact author')
endif
if(size(pelist2(:)) == 1) then
call mpp_check_field_2d_type1(field_in, pelist1, pelist2, domain, mesg, &
w_halo, s_halo, e_halo, n_halo, force_abort )
else if(size(pelist1(:)) == 1) then
call mpp_check_field_2d_type1(field_in, pelist2, pelist1, domain, mesg, &
w_halo, s_halo, e_halo, n_halo, force_abort )
else if(size(pelist1(:)) .gt. 1 .and. size(pelist2(:)) .gt. 1) then
call mpp_check_field_2d_type2(field_in, pelist1, pelist2, domain, mesg, force_abort )
else
call mpp_error(FATAL, 'mpp_check_field: size of both pelists should be greater than 0')
endif
end subroutine mpp_check_field_2D
!####################################################################################
!> This routine is used to check field between running on 1 pe (pelist2) and
!! n pe(pelist1). The need_to_be_checked data is sent to the pelist2 and All the
!! comparison is done on pelist2.
subroutine mpp_check_field_2d_type1(field_in, pelist1, pelist2, domain, mesg, &
w_halo, s_halo, e_halo, n_halo,force_abort )
real, dimension(:,:), intent(in) :: field_in !< field to be checked
integer, dimension(:), intent(in) :: pelist1, pelist2 !< pe list for the two groups
type(domain2d), intent(in) :: domain !< domain for each pe
character(len=*), intent(in) :: mesg !< message to be printed out
!! if differences found
integer, intent(in), optional :: w_halo, s_halo, e_halo, n_halo !< halo size for west, south, east and north
logical, intent(in), optional :: force_abort !< when, call mpp_error if any difference
!! found. default value is false.
! some local data
integer :: pe,npes, p
integer :: hwest, hsouth, heast, hnorth, isg, ieg, jsg, jeg, xhalo, yhalo
integer :: i,j,im,jm,l,is,ie,js,je,isc,iec,jsc,jec,isd,ied,jsd,jed
real,dimension(:,:), allocatable :: field1,field2
real,dimension(:), allocatable :: send_buffer
integer, dimension(4) :: ibounds
logical :: check_success, error_exit
check_success = .TRUE.
error_exit = .FALSE.
if(present(force_abort)) error_exit = force_abort
hwest = 0; if(present(w_halo)) hwest = w_halo
heast = 0; if(present(e_halo)) heast = e_halo
hsouth = 0; if(present(s_halo)) hsouth = s_halo
hnorth = 0; if(present(n_halo)) hnorth = n_halo
pe = mpp_pe ()
npes = mpp_npes()
call mpp_get_compute_domain(domain, isc, iec, jsc, jec)
call mpp_get_data_domain(domain, isd, ied, jsd, jed)
call mpp_get_global_domain(domain, isg, ieg, jsg, jeg)
xhalo = isc - isd
yhalo = jsc - jsd
!--- need to checked halo size should not be bigger than x_halo or y_halo
if(hwest .gt. xhalo .or. heast .gt. xhalo .or. hsouth .gt. yhalo .or. hnorth .gt. yhalo) &
call mpp_error(FATAL,'mpp_check_field: '//trim(mesg)//': The halo size is not correct')
is = isc - hwest; ie = iec + heast; js = jsc - hsouth; je = jec + hnorth
allocate(field2(is:ie,js:je))
! check if the field_in is on compute domain or data domain
if((size(field_in,1) .eq. iec-isc+1) .and. (size(field_in,2) .eq. jec-jsc+1)) then
!if field_in on compute domain, you can not check halo points
if( hwest .ne. 0 .or. heast .ne. 0 .or. hsouth .ne. 0 .or. hnorth .ne. 0 ) &
call mpp_error(FATAL,'mpp_check_field: '//trim(mesg)//': field is on compute domain, can not check halo')
field2(:,:) = field_in(:,:)
else if((size(field_in,1) .eq. ied-isd+1) .and. (size(field_in,2) .eq. jed-jsd+1)) then
field2(is:ie,js:je) = field_in(is-isd+1:ie-isd+1,js-jsd+1:je-jsd+1)
else if((size(field_in,1) .eq. ieg-isg+1) .and. (size(field_in,2) .eq. jeg-jsg+1)) then
if( hwest .ne. 0 .or. heast .ne. 0 .or. hsouth .ne. 0 .or. hnorth .ne. 0 ) &
call mpp_error(FATAL,'mpp_check_field: '//trim(mesg)//': field is on compute domain, can not check halo')
field2(is:ie,js:je) = field_in(1:ie-is+1,1:je-js+1)
else if((size(field_in,1) .eq. ieg-isg+1+2*xhalo) .and. (size(field_in,2) .eq. jeg-jsg+1+2*yhalo)) then
field2(is:ie,js:je) = field_in(is-isd+1:ie-isd+1,js-jsd+1:je-jsd+1)
else
print*, 'on pe ', pe, 'domain: ', isc, iec, jsc, jec, isd, ied, jsd, jed, 'size of field: ', size(field_in,1), &
& size(field_in,2)
call mpp_error(FATAL,'mpp_check_field: '//trim(mesg)//':field is not on compute, data or global domain')
endif
call mpp_sync_self()
if(any(pelist1 == pe)) then ! send data to root pe
im = ie-is+1; jm=je-js+1
allocate(send_buffer(im*jm))
ibounds(1) = is; ibounds(2) = ie; ibounds(3) = js; ibounds(4) = je
l = 0
do i = is,ie
do j = js,je
l = l+1
send_buffer(l) = field2(i,j)
enddo
enddo
! send the check bounds and data to the root pe
! Force use of "scalar", integer pointer mpp interface
call mpp_send(ibounds(1), plen=4, to_pe=pelist2(1), tag=COMM_TAG_1)
call mpp_send(send_buffer(1),plen=im*jm, to_pe=pelist2(1), tag=COMM_TAG_2)
deallocate(send_buffer)
else if(pelist2(1) == pe) then ! receive data and compare
do p = pelist1(1), pelist1(size(pelist1(:)))
! Force use of "scalar", integer pointer mpp interface
call mpp_recv(ibounds(1), glen=4,from_pe=p, tag=COMM_TAG_1)
is = ibounds(1); ie = ibounds(2); js=ibounds(3); je=ibounds(4)
im = ie-is+1; jm=je-js+1
if(allocated(field1)) deallocate(field1)
if(allocated(send_buffer)) deallocate(send_buffer)
allocate(field1(is:ie,js:je),send_buffer(im*jm))
! Force use of "scalar", integer pointer mpp interface
call mpp_recv(send_buffer(1),glen=im*jm,from_pe=p, tag=COMM_TAG_2)
l = 0
! compare here, the comparison criteria can be changed according to need
do i = is,ie
do j = js,je
l = l+1
field1(i,j) = send_buffer(l)
if(field1(i,j) .ne. field2(i,j)) then
! write to standard output
print*,trim(mesg)//": ", i, j, field1(i,j), field2(i,j), field1(i,j) - field2(i,j)
! write(stdout(),'(a,2i,2f)') trim(mesg), i, j, pass_field(i,j), field_check(i,j)
check_success = .FALSE.
if(error_exit) call mpp_error(FATAL,"mpp_check_field: can not reproduce at this point")
endif
enddo
enddo
enddo
if(check_success) then
print*, trim(mesg)//": ", 'comparison between 1 pe and ', npes-1, ' pes is ok'
endif
! release memery
deallocate(field1, send_buffer)
endif
deallocate(field2)
call mpp_sync()
end subroutine mpp_check_field_2d_type1
!####################################################################
!> This routine is used to check field between running on m pe (root pe) and
!! n pe. This routine can not check halo.
subroutine mpp_check_field_2d_type2(field_in, pelist1, pelist2, domain, mesg,force_abort)
real, dimension(:,:), intent(in) :: field_in
type(domain2d), intent(in) :: domain
integer, dimension(:), intent(in) :: pelist1
integer, dimension(:), intent(in) :: pelist2
character(len=*), intent(in) :: mesg
logical, intent(in), optional :: force_abort !< when, call mpp_error if any difference
!! found. default value is false.
! some local variables
logical :: check_success, error_exit
real, dimension(:,:), allocatable :: field1, field2
integer :: i, j, pe, npes, isd,ied,jsd,jed, is, ie, js, je
type(domain2d) :: domain1, domain2
check_success = .TRUE.
error_exit = .FALSE.
if(present(force_abort)) error_exit = force_abort
pe = mpp_pe()
npes = mpp_npes()
call mpp_sync_self()
if(any(pelist1 == pe)) domain1 = domain
if(any(pelist2 == pe)) domain2 = domain
! Comparison is made on pelist2.
if(any(pelist2 == pe)) then
call mpp_get_data_domain(domain2, isd, ied, jsd, jed)
call mpp_get_compute_domain(domain2, is, ie, js, je)
allocate(field1(isd:ied, jsd:jed),field2(isd:ied, jsd:jed))
if((size(field_in,1) .ne. ied-isd+1) .or. (size(field_in,2) .ne. jed-jsd+1)) &
call mpp_error(FATAL,'mpp_check_field: input field is not on the data domain')
field2(isd:ied, jsd:jed) = field_in(:,:)
endif
! broadcast domain
call mpp_broadcast_domain(domain1)
call mpp_broadcast_domain(domain2)
call mpp_redistribute(domain1,field_in,domain2,field1)
if(any(pelist2 == pe)) then
do i =is,ie
do j =js,je
if(field1(i,j) .ne. field2(i,j)) then
print*, trim(mesg)//": ", i, j, field1(i,j), field2(i,j), field1(i,j) - field2(i,j)
! write(stdout(),'(a,2i,2f)') trim(mesg), i, j, field_check(i,j), field_out(i,j)
check_success = .FALSE.
if(error_exit) call mpp_error(FATAL,"mpp_check_field: can not reproduce at this point")
endif
enddo
enddo
if(check_success) &
print*, trim(mesg)//": ", 'comparison between ', size(pelist1(:)), ' pes and ', &
size(pelist2(:)), ' pe on', pe, ' pes is ok'
endif
if(any(pelist2 == pe)) deallocate(field1, field2)
call mpp_sync()
return
end subroutine mpp_check_field_2d_type2
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! !
! MPP_BROADCAST_DOMAIN !
! !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!> broadcast domain (useful only outside the context of its own pelist)
subroutine mpp_broadcast_domain_1( domain )
type(domain2D), intent(inout) :: domain
integer, allocatable :: pes(:)
logical :: native !> true if I'm on the pelist of this domain
integer :: listsize, listpos
integer :: n
integer, dimension(12) :: msg, info !> pe and compute domain of each item in list
integer :: errunit
errunit = stderr()
if( .NOT.module_is_initialized ) &
call mpp_error( FATAL, 'MPP_BROADCAST_DOMAIN_1: You must first call mpp_domains_init.' )
!get the current pelist
allocate( pes(0:mpp_npes()-1) )
call mpp_get_current_pelist(pes)
!am I part of this domain?
native = ASSOCIATED(domain%list)
!set local list size
if( native )then
listsize = size(domain%list(:))
else
listsize = 0
end if
call mpp_max(listsize)
if( .NOT.native )then
!initialize domain%list and set null values in message
allocate( domain%list(0:listsize-1) )
domain%pe = NULL_PE
domain%pos = -1
allocate(domain%x(1), domain%y(1), domain%tile_id(1))
do n = 0, listsize-1
allocate(domain%list(n)%x(1), domain%list(n)%y(1), domain%list(n)%tile_id(1) )
end do
domain%x%compute%begin = 1
domain%x%compute%end = -1
domain%y%compute%begin = 1
domain%y%compute%end = -1
domain%x%data %begin = -1
domain%x%data %end = -1
domain%y%data %begin = -1
domain%y%data %end = -1
domain%x%global %begin = -1
domain%x%global %end = -1
domain%y%global %begin = -1
domain%y%global %end = -1
domain%tile_id = -1
domain%whalo = -1
domain%ehalo = -1
domain%shalo = -1
domain%nhalo = -1
domain%symmetry = .false.
end if
!initialize values in info
info(1) = domain%pe
call mpp_get_compute_domain( domain, info(2), info(3), info(4), info(5) )
info(6) = domain%tile_id(1)
info(7) = domain%whalo
info(8) = domain%ehalo
info(9) = domain%shalo
info(10)= domain%nhalo
if(domain%symmetry) then
info(11) = 1
else
info(11) = 0
endif
info(12) = domain%ntiles
!broadcast your info across current pelist and unpack if needed
listpos = 0
do n = 0,mpp_npes()-1
msg = info
if( mpp_pe().EQ.pes(n) .AND. debug )write( errunit,* )'PE ', mpp_pe(), 'broadcasting msg ', msg
call mpp_broadcast( msg, 12, pes(n) )
!no need to unpack message if native
!no need to unpack message from non-native PE
if( .NOT.native .AND. msg(1).NE.NULL_PE )then
domain%list(listpos)%pe = msg(1)
domain%list(listpos)%x%compute%begin = msg(2)
domain%list(listpos)%x%compute%end = msg(3)
domain%list(listpos)%y%compute%begin = msg(4)
domain%list(listpos)%y%compute%end = msg(5)
domain%list(listpos)%tile_id(1) = msg(6)
if(domain%x(1)%global%begin < 0) then
domain%x(1)%data %begin = msg(2)
domain%x(1)%data %end = msg(3)
domain%y(1)%data %begin = msg(4)
domain%y(1)%data %end = msg(5)
domain%x(1)%global%begin = msg(2)
domain%x(1)%global%end = msg(3)
domain%y(1)%global%begin = msg(4)
domain%y(1)%global%end = msg(5)
domain%whalo = msg(7)
domain%ehalo = msg(8)
domain%shalo = msg(9)
domain%nhalo = msg(10)
if(msg(11) == 1) then
domain%symmetry = .true.
else
domain%symmetry = .false.
endif
domain%ntiles = msg(12)
else
domain%x(1)%data %begin = msg(2) - msg(7)
domain%x(1)%data %end = msg(3) + msg(8)
domain%y(1)%data %begin = msg(4) - msg(9)
domain%y(1)%data %end = msg(5) + msg(10)
domain%x(1)%global%begin = min(domain%x(1)%global%begin, msg(2))
domain%x(1)%global%end = max(domain%x(1)%global%end, msg(3))
domain%y(1)%global%begin = min(domain%y(1)%global%begin, msg(4))
domain%y(1)%global%end = max(domain%y(1)%global%end, msg(5))
endif
listpos = listpos + 1
if( debug )write( errunit,* )'PE ', mpp_pe(), 'received domain from PE ', msg(1), 'is,ie,js,je=', msg(2:5)
end if
end do
end subroutine mpp_broadcast_domain_1
!##############################################################################
!> Broadcast domain (useful only outside the context of its own pelist)
subroutine mpp_broadcast_domain_2( domain_in, domain_out )
type(domain2D), intent(in) :: domain_in
type(domain2D), intent(inout) :: domain_out
integer, allocatable :: pes(:)
integer :: listpos
integer :: n
integer, dimension(12) :: msg, info !< pe and compute domain of each item in list
integer :: errunit, npes_in, npes_out, pstart, pend
errunit = stderr()
if( .NOT.module_is_initialized ) &
call mpp_error( FATAL, 'MPP_BROADCAST_DOMAIN_2: You must first call mpp_domains_init.' )
!get the current pelist
allocate( pes(0:mpp_npes()-1) )
call mpp_get_current_pelist(pes)
! domain_in must be initialized
if( .not. ASSOCIATED(domain_in%list) ) then
call mpp_error( FATAL, 'MPP_BROADCAST_DOMAIN_2: domain_in is not initialized')
endif
if( ASSOCIATED(domain_out%list) ) then
call mpp_error( FATAL, 'MPP_BROADCAST_DOMAIN_2: domain_out is already initialized')
endif
npes_in = size(domain_in%list(:))
if( npes_in == mpp_npes() ) then
call mpp_error( FATAL, 'MPP_BROADCAST_DOMAIN_2: size(domain_in%list(:)) == mpp_npes()')
endif
npes_out = mpp_npes() - npes_in
!initialize domain_out%list and set null values in message
allocate( domain_out%list(0:npes_out-1) )
domain_out%pe = NULL_PE
domain_out%pos = -1
allocate(domain_out%x(1), domain_out%y(1), domain_out%tile_id(1))
do n = 0, npes_out-1
allocate(domain_out%list(n)%x(1), domain_out%list(n)%y(1), domain_out%list(n)%tile_id(1) )
end do
domain_out%x%compute%begin = 1
domain_out%x%compute%end = -1
domain_out%y%compute%begin = 1
domain_out%y%compute%end = -1
domain_out%x%data %begin = -1
domain_out%x%data %end = -1
domain_out%y%data %begin = -1
domain_out%y%data %end = -1
domain_out%x%global %begin = -1
domain_out%x%global %end = -1
domain_out%y%global %begin = -1
domain_out%y%global %end = -1
domain_out%tile_id = -1
domain_out%whalo = -1
domain_out%ehalo = -1
domain_out%shalo = -1
domain_out%nhalo = -1
domain_out%symmetry = .false.
!initialize values in info
info(1) = domain_in%pe
call mpp_get_compute_domain( domain_in, info(2), info(3), info(4), info(5) )
info(6) = domain_in%tile_id(1)
info(7) = domain_in%whalo
info(8) = domain_in%ehalo
info(9) = domain_in%shalo
info(10)= domain_in%nhalo
if(domain_in%symmetry) then
info(11) = 1
else
info(11) = 0
endif
info(12) = domain_in%ntiles
!broadcast your info across current pelist and unpack if needed
if( domain_in%list(0)%pe == mpp_root_pe() ) then
pstart = npes_in
pend = mpp_npes()-1
else
pstart = 0
pend = npes_out-1
endif
do n = 0,mpp_npes()-1
msg = info
if( mpp_pe().EQ.pes(n) .AND. debug )write( errunit,* )'PE ', mpp_pe(), 'broadcasting msg ', msg
call mpp_broadcast( msg, 12, pes(n) )
!--- pack if from other domain
if( n .GE. pstart .AND. n .LE. pend )then
listpos = n - pstart
domain_out%list(listpos)%pe = msg(1)
domain_out%list(listpos)%x%compute%begin = msg(2)
domain_out%list(listpos)%x%compute%end = msg(3)
domain_out%list(listpos)%y%compute%begin = msg(4)
domain_out%list(listpos)%y%compute%end = msg(5)
domain_out%list(listpos)%tile_id(1) = msg(6)
if(domain_out%x(1)%global%begin < 0) then
domain_out%x(1)%data %begin = msg(2)
domain_out%x(1)%data %end = msg(3)
domain_out%y(1)%data %begin = msg(4)
domain_out%y(1)%data %end = msg(5)
domain_out%x(1)%global%begin = msg(2)
domain_out%x(1)%global%end = msg(3)
domain_out%y(1)%global%begin = msg(4)
domain_out%y(1)%global%end = msg(5)
domain_out%whalo = msg(7)
domain_out%ehalo = msg(8)
domain_out%shalo = msg(9)
domain_out%nhalo = msg(10)
if(msg(11) == 1) then
domain_out%symmetry = .true.
else
domain_out%symmetry = .false.
endif
domain_out%ntiles = msg(12)
else
domain_out%x(1)%data %begin = msg(2) - msg(7)
domain_out%x(1)%data %end = msg(3) + msg(8)
domain_out%y(1)%data %begin = msg(4) - msg(9)
domain_out%y(1)%data %end = msg(5) + msg(10)
domain_out%x(1)%global%begin = min(domain_out%x(1)%global%begin, msg(2))
domain_out%x(1)%global%end = max(domain_out%x(1)%global%end, msg(3))
domain_out%y(1)%global%begin = min(domain_out%y(1)%global%begin, msg(4))
domain_out%y(1)%global%end = max(domain_out%y(1)%global%end, msg(5))
endif
if( debug )write( errunit,* )'PE ', mpp_pe(), 'received domain from PE ', msg(1), 'is,ie,js,je=', msg(2:5)
end if
end do
end subroutine mpp_broadcast_domain_2
!> Broadcast fine nested domain (useful only outside the context of its own pelist)
subroutine mpp_broadcast_domain_nest_fine( domain, tile_nest )
type(domain2D), intent(inout) :: domain
integer, intent(in) :: tile_nest(:)
integer, allocatable :: pes(:)
logical :: native !< true if I'm on the pelist of this domain
integer :: listsize, listpos, nestsize(size(tile_nest(:)))
integer :: n, tile, ind, num_nest
integer, dimension(15) :: msg, info !< pe and compute domain of each item in list
integer :: errunit
errunit = stderr()
if( .NOT.module_is_initialized ) &
call mpp_error( FATAL, 'MPP_BROADCAST_DOMAIN_NEST_FINE: You must first call mpp_domains_init.' )
!get the current pelist
allocate( pes(0:mpp_npes()-1) )
call mpp_get_current_pelist(pes)
!am I part of this domain?
native = ASSOCIATED(domain%list)
num_nest = size(tile_nest(:))
!set local list size
nestsize = 0
if( native )then
tile = domain%tile_id(1)
ind = 0
do n = 1, num_nest
if(tile_nest(n) == tile) then
ind = n
exit
endif
enddo
if(ind == 0) call mpp_error( FATAL, &
& 'MPP_BROADCAST_DOMAIN_NEST_FINE:native is true, but tile_id is found in tile_nest')
nestsize(ind) = size(domain%list(:))
end if
call mpp_max(nestsize, num_nest)
listsize = sum(nestsize)
if( .NOT.native )then
!initialize domain%list and set null values in message
allocate( domain%list(0:listsize-1) )
domain%pe = NULL_PE
domain%pos = -1
allocate(domain%x(1), domain%y(1), domain%tile_id(1))
do n = 0, listsize-1
allocate(domain%list(n)%x(1), domain%list(n)%y(1), domain%list(n)%tile_id(1) )
end do
domain%x%compute%begin = 0
domain%x%compute%end = -1
domain%y%compute%begin = 0
domain%y%compute%end = -1
domain%x%data %begin = 0
domain%x%data %end = -1
domain%y%data %begin = 0
domain%y%data %end = -1
domain%x%global %begin = 0
domain%x%global %end = -1
domain%y%global %begin = 0
domain%y%global %end = -1
domain%tile_id = -1
domain%whalo = -1
domain%ehalo = -1
domain%shalo = -1
domain%nhalo = -1
domain%symmetry = .false.
end if
!initialize values in info
info(1) = domain%pe
call mpp_get_compute_domain( domain, info(2), info(3), info(4), info(5) )
info(6) = domain%tile_id(1)
info(7) = domain%whalo
info(8) = domain%ehalo
info(9) = domain%shalo
info(10)= domain%nhalo
if(domain%symmetry) then
info(11) = 1
else
info(11) = 0
endif
call mpp_get_global_domain( domain, info(12), info(13), info(14), info(15) )
!broadcast your info across current pelist and unpack if needed
listpos = 0
do n = 0,mpp_npes()-1
msg = info
if( mpp_pe().EQ.pes(n) .AND. debug )write( errunit,* )'PE ', mpp_pe(), 'broadcasting msg ', msg
call mpp_broadcast( msg, 15, pes(n) )
!no need to unpack message if native
!no need to unpack message from non-native PE
if( .NOT.native .AND. msg(1).NE.NULL_PE )then
domain%list(listpos)%pe = msg(1)
if(domain%x(1)%compute%begin == 0) then
domain%whalo = msg(7)
domain%ehalo = msg(8)
domain%shalo = msg(9)
domain%nhalo = msg(10)
if(msg(11) == 1) then
domain%symmetry = .true.
else
domain%symmetry = .false.
endif
endif
domain%list(listpos)%x%compute%begin = msg(2)
domain%list(listpos)%x%compute%end = msg(3)
domain%list(listpos)%y%compute%begin = msg(4)
domain%list(listpos)%y%compute%end = msg(5)
domain%list(listpos)%tile_id(1) = msg(6)
domain%list(listpos)%x%global %begin = msg(12)
domain%list(listpos)%x%global %end = msg(13)
domain%list(listpos)%y%global %begin = msg(14)
domain%list(listpos)%y%global %end = msg(15)
listpos = listpos + 1
if( debug )write( errunit,* )'PE ', mpp_pe(), 'received domain from PE ', msg(1), 'is,ie,js,je=', msg(2:5)
end if
end do
end subroutine mpp_broadcast_domain_nest_fine
!> Broadcast nested domain (useful only outside the context of its own pelist)
subroutine mpp_broadcast_domain_nest_coarse( domain, tile_coarse )
type(domain2D), intent(inout) :: domain
integer, intent(in) :: tile_coarse
integer, allocatable :: pes(:)
logical :: native !< true if I'm on the pelist of this domain
integer :: listsize, listpos
integer, allocatable :: tile_pesize(:)
integer :: n, maxtile
integer, dimension(17) :: msg, info !< pe and compute domain of each item in list
integer :: errunit
errunit = stderr()
if( .NOT.module_is_initialized ) &
call mpp_error( FATAL, 'MPP_BROADCAST_DOMAIN_NEST_COARSE: You must first call mpp_domains_init.' )
!get the current pelist
allocate( pes(0:mpp_npes()-1) )
call mpp_get_current_pelist(pes)
maxtile = tile_coarse
call mpp_max(maxtile)
allocate(tile_pesize(maxtile))
tile_pesize = 0
!am I part of this domain?
native = ASSOCIATED(domain%list)
!set local list size
if( native )then
! tile = domain%tile_id(1)
! if(tile .NE. tile_coarse) then
! print*, "tile,tile_coarse=", tile, tile_coarse, mpp_pe()
! call mpp_error( FATAL, 'MPP_BROADCAST_DOMAIN_NEST_COARSE: tile .NE. tile_coarse')
! endif
tile_pesize(tile_coarse) = size(domain%list(:))
end if
call mpp_max(tile_pesize, maxtile)
listsize = tile_pesize(tile_coarse)
if( .NOT.native )then
!initialize domain%list and set null values in message
allocate( domain%list(0:listsize-1) )
domain%pe = NULL_PE
domain%pos = -1
allocate(domain%x(1), domain%y(1), domain%tile_id(1))
do n = 0, listsize-1
allocate(domain%list(n)%x(1), domain%list(n)%y(1), domain%list(n)%tile_id(1) )
end do
domain%x%compute%begin = 0
domain%x%compute%end = -1
domain%y%compute%begin = 0
domain%y%compute%end = -1
domain%x%data %begin = 0
domain%x%data %end = -1
domain%y%data %begin = 0
domain%y%data %end = -1
domain%x%global %begin = 0
domain%x%global %end = -1
domain%y%global %begin = 0
domain%y%global %end = -1
domain%tile_id = -1
domain%whalo = -1
domain%ehalo = -1
domain%shalo = -1
domain%nhalo = -1
domain%symmetry = .false.
domain%ntiles = 0
end if
!initialize values in info
info(1) = domain%pe
call mpp_get_compute_domain( domain, info(2), info(3), info(4), info(5) )
info(6) = domain%tile_id(1)
info(7) = domain%whalo
info(8) = domain%ehalo
info(9) = domain%shalo
info(10)= domain%nhalo
if(domain%symmetry) then
info(11) = 1
else
info(11) = 0
endif
call mpp_get_global_domain( domain, info(12), info(13), info(14), info(15) )
info(16) = tile_coarse
info(17) = domain%ntiles
!broadcast your info across current pelist and unpack if needed
listpos = 0
do n = 0,mpp_npes()-1
msg = info
call mpp_broadcast( msg, 17, pes(n) )
!no need to unpack message if native
!no need to unpack message from non-native PE
if( .NOT.native .AND. msg(1).NE.NULL_PE .AND. tile_coarse==msg(16) )then
domain%list(listpos)%pe = msg(1)
if(domain%x(1)%compute%begin == 0) then
domain%x(1)%data %begin = msg(2) - msg(7)
domain%x(1)%data %end = msg(3) + msg(8)
domain%y(1)%data %begin = msg(4) - msg(9)
domain%y(1)%data %end = msg(5) + msg(10)
domain%x(1)%global%begin = msg(12)
domain%x(1)%global%end = msg(13)
domain%y(1)%global%begin = msg(14)
domain%y(1)%global%end = msg(15)
domain%whalo = msg(7)
domain%ehalo = msg(8)
domain%shalo = msg(9)
domain%nhalo = msg(10)
domain%ntiles = msg(17)
if(msg(11) == 1) then
domain%symmetry = .true.
else
domain%symmetry = .false.
endif
endif
domain%list(listpos)%x%compute%begin = msg(2)
domain%list(listpos)%x%compute%end = msg(3)
domain%list(listpos)%y%compute%begin = msg(4)
domain%list(listpos)%y%compute%end = msg(5)
domain%list(listpos)%tile_id(1) = msg(6)
domain%list(listpos)%x%global %begin = msg(12)
domain%list(listpos)%x%global %end = msg(13)
domain%list(listpos)%y%global %begin = msg(14)
domain%list(listpos)%y%global %end = msg(15)
listpos = listpos + 1
if( debug )write( errunit,* )'PE ', mpp_pe(), 'received domain from PE ', msg(1), 'is,ie,js,je=', msg(2:5)
end if
end do
end subroutine mpp_broadcast_domain_nest_coarse
!> @}
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! !
! MPP_UPDATE_DOMAINS: fill halos for 2D decomposition !
! !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#undef VECTOR_FIELD_
#define VECTOR_FIELD_
#undef MPP_TYPE_
#define MPP_TYPE_ real(r8_kind)
#undef MPP_UPDATE_DOMAINS_2D_
#define MPP_UPDATE_DOMAINS_2D_ mpp_update_domain2D_r8_2D
#undef MPP_UPDATE_DOMAINS_3D_
#define MPP_UPDATE_DOMAINS_3D_ mpp_update_domain2D_r8_3D
#undef MPP_UPDATE_DOMAINS_4D_
#define MPP_UPDATE_DOMAINS_4D_ mpp_update_domain2D_r8_4D
#undef MPP_UPDATE_DOMAINS_5D_
#define MPP_UPDATE_DOMAINS_5D_ mpp_update_domain2D_r8_5D
#ifdef VECTOR_FIELD_
#undef MPP_UPDATE_DOMAINS_2D_V_
#define MPP_UPDATE_DOMAINS_2D_V_ mpp_update_domain2D_r8_2Dv
#undef MPP_UPDATE_DOMAINS_3D_V_
#define MPP_UPDATE_DOMAINS_3D_V_ mpp_update_domain2D_r8_3Dv
#undef MPP_UPDATE_DOMAINS_4D_V_
#define MPP_UPDATE_DOMAINS_4D_V_ mpp_update_domain2D_r8_4Dv
#undef MPP_UPDATE_DOMAINS_5D_V_
#define MPP_UPDATE_DOMAINS_5D_V_ mpp_update_domain2D_r8_5Dv
#endif
#undef MPP_REDISTRIBUTE_2D_
#define MPP_REDISTRIBUTE_2D_ mpp_redistribute_r8_2D
#undef MPP_REDISTRIBUTE_3D_
#define MPP_REDISTRIBUTE_3D_ mpp_redistribute_r8_3D
#undef MPP_REDISTRIBUTE_4D_
#define MPP_REDISTRIBUTE_4D_ mpp_redistribute_r8_4D
#undef MPP_REDISTRIBUTE_5D_
#define MPP_REDISTRIBUTE_5D_ mpp_redistribute_r8_5D
#include <mpp_update_domains2D.fh>
#undef VECTOR_FIELD_
#ifdef OVERLOAD_C8
#undef MPP_TYPE_