Newer
Older
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
MODULE mppini
!!======================================================================
!! *** MODULE mppini ***
!! Ocean initialization : distributed memory computing initialization
!!======================================================================
!! History : 6.0 ! 1994-11 (M. Guyon) Original code
!! OPA 7.0 ! 1995-04 (J. Escobar, M. Imbard)
!! 8.0 ! 1998-05 (M. Imbard, J. Escobar, L. Colombet ) SHMEM and MPI versions
!! NEMO 1.0 ! 2004-01 (G. Madec, J.M Molines) F90 : free form , north fold jpni > 1
!! 3.4 ! 2011-10 (A. C. Coward, NOCS & J. Donners, PRACE) add init_nfdcom
!! 3. ! 2013-06 (I. Epicoco, S. Mocavero, CMCC) init_nfdcom: setup avoiding MPI communication
!! 4.0 ! 2016-06 (G. Madec) use domain configuration file instead of bathymetry file
!! 4.0 ! 2017-06 (J.M. Molines, T. Lovato) merge of mppini and mppini_2
!!----------------------------------------------------------------------
!!----------------------------------------------------------------------
!! mpp_init : Lay out the global domain over processors with/without land processor elimination
!! init_ioipsl: IOIPSL initialization in mpp
!! init_nfdcom: Setup for north fold exchanges with explicit point-to-point messaging
!! init_doloop: set the starting/ending indices of DO-loop used in do_loop_substitute
!!----------------------------------------------------------------------
USE dom_oce ! ocean space and time domain
USE bdy_oce ! open BounDarY
!
USE lbcnfd ! Setup of north fold exchanges
USE lib_mpp ! distribued memory computing library
USE iom ! nemo I/O library
USE ioipsl ! I/O IPSL library
USE in_out_manager ! I/O Manager
IMPLICIT NONE
PRIVATE
PUBLIC mpp_init ! called by nemogcm.F90
PUBLIC mpp_getnum ! called by prtctl
PUBLIC mpp_basesplit ! called by prtctl
PUBLIC mpp_is_ocean ! called by prtctl
INTEGER :: numbot = -1 ! 'bottom_level' local logical unit
INTEGER :: numbdy = -1 ! 'bdy_msk' local logical unit
!!----------------------------------------------------------------------
!! NEMO/OCE 4.0 , NEMO Consortium (2018)
!! $Id: mppini.F90 15302 2021-09-29 15:00:15Z smasson $
!! Software governed by the CeCILL license (see ./LICENSE)
!!----------------------------------------------------------------------
CONTAINS
#if defined key_mpi_off
!!----------------------------------------------------------------------
!! Default option : shared memory computing
!!----------------------------------------------------------------------
SUBROUTINE mpp_init
!!----------------------------------------------------------------------
!! *** ROUTINE mpp_init ***
!!
!! ** Purpose : Lay out the global domain over processors.
!!
!! ** Method : Shared memory computing, set the local processor
!! variables to the value of the global domain
!!----------------------------------------------------------------------
!
nn_comm = 1
nn_hls = 1
jpiglo = Ni0glo + 2 * nn_hls
jpjglo = Nj0glo + 2 * nn_hls
jpimax = jpiglo
jpjmax = jpjglo
jpi = jpiglo
jpj = jpjglo
jpk = MAX( 2, jpkglo )
jpij = jpi*jpj
jpni = 1
jpnj = 1
jpnij = jpni*jpnj
nimpp = 1
njmpp = 1
nidom = FLIO_DOM_NONE
!
mpiSnei(:,:) = -1
mpiRnei(:,:) = -1
l_SelfPerio(1:2) = l_Iperio ! west, east periodicity by itself
l_SelfPerio(3:4) = l_Jperio ! south, north periodicity by itself
l_SelfPerio(5:8) = l_Iperio .AND. l_Jperio ! corners bi-periodicity by itself
l_IdoNFold = l_NFold ! is this process doing North fold?
!
CALL init_doloop ! set start/end indices or do-loop depending on the halo width value (nn_hls)
Simon Mueller
committed
CALL init_locglo ! define now functions needed to convert indices from/to global to/from local domains
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
!
IF(lwp) THEN
WRITE(numout,*)
WRITE(numout,*) 'mpp_init : NO massively parallel processing'
WRITE(numout,*) '~~~~~~~~ '
WRITE(numout,*) ' l_Iperio = ', l_Iperio, ' l_Jperio = ', l_Jperio
WRITE(numout,*) ' njmpp = ', njmpp
ENDIF
!
#if defined key_agrif
call agrif_nemo_init()
#endif
END SUBROUTINE mpp_init
#else
!!----------------------------------------------------------------------
!! MPI massively parallel processing
!!----------------------------------------------------------------------
SUBROUTINE mpp_init
!!----------------------------------------------------------------------
!! *** ROUTINE mpp_init ***
!!
!! ** Purpose : Lay out the global domain over processors.
!! If land processors are to be eliminated, this program requires the
!! presence of the domain configuration file. Land processors elimination
!! is performed if jpni x jpnj /= jpnij. In this case, using the MPP_PREP
!! preprocessing tool, help for defining the best cutting out.
!!
!! ** Method : Global domain is distributed in smaller local domains.
!! Periodic condition is a function of the local domain position
!! (global boundary or neighbouring domain) and of the global periodic
!!
!! ** Action : - set domain parameters
!! nimpp : longitudinal index
!! njmpp : latitudinal index
!! narea : number for local area
!! mpinei : number of neighboring domains (starting at 0, -1 if no neighbourg)
!!----------------------------------------------------------------------
INTEGER :: ji, jj, jn, jp, jh
INTEGER :: ii, ij, ii2, ij2
INTEGER :: inijmin ! number of oce subdomains
INTEGER :: inum, inum0
INTEGER :: ifreq, il1, imil, il2, ijm1
INTEGER :: ierr, ios
INTEGER :: inbi, inbj, iimax, ijmax, icnt1, icnt2
INTEGER, DIMENSION(16*n_hlsmax) :: ichanged
INTEGER, ALLOCATABLE, DIMENSION(: ) :: iin, ijn
INTEGER, ALLOCATABLE, DIMENSION(:,: ) :: iimppt, ijpi, ipproc
INTEGER, ALLOCATABLE, DIMENSION(:,: ) :: ijmppt, ijpj
INTEGER, ALLOCATABLE, DIMENSION(:,: ) :: impi
INTEGER, ALLOCATABLE, DIMENSION(:,:,:) :: inei
LOGICAL :: llbest, llauto
LOGICAL :: llwrtlay
LOGICAL :: llmpi_Iperio, llmpi_Jperio, llmpiNFold
LOGICAL :: ln_listonly
LOGICAL, ALLOCATABLE, DIMENSION(:,: ) :: llisOce ! is not land-domain only?
LOGICAL, ALLOCATABLE, DIMENSION(:,:,:) :: llnei ! are neighbourgs existing?
NAMELIST/nambdy/ ln_bdy, nb_bdy, ln_coords_file, cn_coords_file, &
& ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta, &
& cn_dyn3d, nn_dyn3d_dta, cn_tra, nn_tra_dta, &
& ln_tra_dmp, ln_dyn3d_dmp, rn_time_dmp, rn_time_dmp_out, &
& cn_ice, nn_ice_dta, &
& ln_vol, nn_volctl, nn_rimwidth
NAMELIST/nammpp/ jpni, jpnj, nn_hls, ln_nnogather, ln_listonly, nn_comm
!!----------------------------------------------------------------------
!
llwrtlay = lwm .OR. sn_cfctl%l_layout
!
! 0. read namelists parameters
! -----------------------------------
!
READ ( numnam_ref, nammpp, IOSTAT = ios, ERR = 901 )
901 IF( ios /= 0 ) CALL ctl_nam ( ios , 'nammpp in reference namelist' )
READ ( numnam_cfg, nammpp, IOSTAT = ios, ERR = 902 )
902 IF( ios > 0 ) CALL ctl_nam ( ios , 'nammpp in configuration namelist' )
!
nn_hls = MAX(1, nn_hls) ! nn_hls must be > 0

Sebastien Masson
committed
IF( nn_hls > 1 ) CALL ctl_warn( 'mpp_init', 'you use nn_hls > 1, this may significantly slow down NEMO performances' )
IF(lwp) THEN
WRITE(numout,*) ' Namelist nammpp'
IF( jpni < 1 .OR. jpnj < 1 ) THEN
WRITE(numout,*) ' jpni and jpnj will be calculated automatically'
ELSE
WRITE(numout,*) ' processor grid extent in i jpni = ', jpni
WRITE(numout,*) ' processor grid extent in j jpnj = ', jpnj
ENDIF
WRITE(numout,*) ' avoid use of mpi_allgather at the north fold ln_nnogather = ', ln_nnogather
WRITE(numout,*) ' halo width (applies to both rows and columns) nn_hls = ', nn_hls

Sebastien Masson
committed
WRITE(numout,*) ' choice of communication method nn_comm = ', nn_comm
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
ENDIF
!
IF(lwm) WRITE( numond, nammpp )
!
jpiglo = Ni0glo + 2 * nn_hls
jpjglo = Nj0glo + 2 * nn_hls
!
! do we need to take into account bdy_msk?
READ ( numnam_ref, nambdy, IOSTAT = ios, ERR = 903)
903 IF( ios /= 0 ) CALL ctl_nam ( ios , 'nambdy in reference namelist (mppini)' )
READ ( numnam_cfg, nambdy, IOSTAT = ios, ERR = 904 )
904 IF( ios > 0 ) CALL ctl_nam ( ios , 'nambdy in configuration namelist (mppini)' )
!
IF( ln_read_cfg ) CALL iom_open( cn_domcfg, numbot )
IF( ln_bdy .AND. ln_mask_file ) CALL iom_open( cn_mask_file, numbdy )
!
IF( ln_listonly ) CALL bestpartition( MAX(mppsize,jpni*jpnj), ldlist = .TRUE. ) ! must be done by all core
!
! 1. Dimension arrays for subdomains
! -----------------------------------
!
! If dimensions of MPI processes grid weren't specified in the namelist file
! then we calculate them here now that we have our communicator size
IF(lwp) THEN
WRITE(numout,*)
WRITE(numout,*) 'mpp_init:'
WRITE(numout,*) '~~~~~~~~ '
ENDIF
IF( jpni < 1 .OR. jpnj < 1 ) THEN
CALL bestpartition( mppsize, jpni, jpnj ) ! best mpi decomposition for mppsize mpi processes
llauto = .TRUE.
llbest = .TRUE.
ELSE
llauto = .FALSE.
CALL bestpartition( mppsize, inbi, inbj, icnt2 ) ! best mpi decomposition for mppsize mpi processes
! largest subdomain size for mpi decoposition jpni*jpnj given in the namelist
CALL mpp_basesplit( jpiglo, jpjglo, nn_hls, jpni, jpnj, jpimax, jpjmax )
! largest subdomain size for mpi decoposition inbi*inbj given by bestpartition
CALL mpp_basesplit( jpiglo, jpjglo, nn_hls, inbi, inbj, iimax, ijmax )
icnt1 = jpni*jpnj - mppsize ! number of land subdomains that should be removed to use mppsize mpi processes
IF(lwp) THEN
WRITE(numout,9000) ' The chosen domain decomposition ', jpni, ' x ', jpnj, ' with ', icnt1, ' land subdomains'
WRITE(numout,9002) ' - uses a total of ', mppsize,' mpi process'
WRITE(numout,9000) ' - has mpi subdomains with a maximum size of (jpi = ', jpimax, ', jpj = ', jpjmax, &
& ', jpi*jpj = ', jpimax*jpjmax, ')'
WRITE(numout,9000) ' The best domain decompostion ', inbi, ' x ', inbj, ' with ', icnt2, ' land subdomains'
WRITE(numout,9002) ' - uses a total of ', inbi*inbj-icnt2,' mpi process'
WRITE(numout,9000) ' - has mpi subdomains with a maximum size of (jpi = ', iimax, ', jpj = ', ijmax, &
& ', jpi*jpj = ', iimax* ijmax, ')'
ENDIF
IF( iimax*ijmax < jpimax*jpjmax ) THEN ! chosen subdomain size is larger that the best subdomain size
llbest = .FALSE.
IF ( inbi*inbj-icnt2 < mppsize ) THEN
WRITE(ctmp1,*) ' ==> You could therefore have smaller mpi subdomains with less mpi processes'
ELSE
WRITE(ctmp1,*) ' ==> You could therefore have smaller mpi subdomains with the same number of mpi processes'
ENDIF
CALL ctl_warn( ' ', ctmp1, ' ', ' --- YOU ARE WASTING CPU... ---', ' ' )
ELSE IF ( iimax*ijmax == jpimax*jpjmax .AND. (inbi*inbj-icnt2) < mppsize) THEN
llbest = .FALSE.
WRITE(ctmp1,*) ' ==> You could therefore have the same mpi subdomains size with less mpi processes'
CALL ctl_warn( ' ', ctmp1, ' ', ' --- YOU ARE WASTING CPU... ---', ' ' )
ELSE
llbest = .TRUE.
ENDIF
ENDIF
! look for land mpi subdomains...
ALLOCATE( llisOce(jpni,jpnj) )
CALL mpp_is_ocean( llisOce )
inijmin = COUNT( llisOce ) ! number of oce subdomains
IF( mppsize < inijmin ) THEN ! too many oce subdomains: can happen only if jpni and jpnj are prescribed...
WRITE(ctmp1,9001) ' With this specified domain decomposition: jpni = ', jpni, ' jpnj = ', jpnj
WRITE(ctmp2,9002) ' we can eliminate only ', jpni*jpnj - inijmin, ' land mpi subdomains therefore '
WRITE(ctmp3,9001) ' the number of ocean mpi subdomains (', inijmin,') exceed the number of MPI processes:', mppsize
WRITE(ctmp4,*) ' ==>>> There is the list of best domain decompositions you should use: '
CALL ctl_stop( ctmp1, ctmp2, ctmp3, ' ', ctmp4, ' ' )
CALL bestpartition( mppsize, ldlist = .TRUE. ) ! must be done by all core
ENDIF
IF( mppsize > jpni*jpnj ) THEN ! not enough mpi subdomains for the total number of mpi processes
IF(lwp) THEN
WRITE(numout,9003) ' The number of mpi processes: ', mppsize
WRITE(numout,9003) ' exceeds the maximum number of subdomains (ocean+land) = ', jpni*jpnj
WRITE(numout,9001) ' defined by the following domain decomposition: jpni = ', jpni, ' jpnj = ', jpnj
WRITE(numout, *) ' You should: '
IF( llauto ) THEN
WRITE(numout,*) ' - either prescribe your domain decomposition with the namelist variables'
WRITE(numout,*) ' jpni and jpnj to match the number of mpi process you want to use, '
WRITE(numout,*) ' even IF it not the best choice...'
WRITE(numout,*) ' - or keep the automatic and optimal domain decomposition by picking up one'
WRITE(numout,*) ' of the number of mpi process proposed in the list bellow'
ELSE
WRITE(numout,*) ' - either properly prescribe your domain decomposition with jpni and jpnj'
WRITE(numout,*) ' in order to be consistent with the number of mpi process you want to use'
WRITE(numout,*) ' even IF it not the best choice...'
WRITE(numout,*) ' - or use the automatic and optimal domain decomposition and pick up one of'
WRITE(numout,*) ' the domain decomposition proposed in the list bellow'
ENDIF
WRITE(numout,*)
ENDIF
CALL bestpartition( mppsize, ldlist = .TRUE. ) ! must be done by all core
ENDIF
jpnij = mppsize ! force jpnij definition <-- remove as much land subdomains as needed to reach this condition
IF( mppsize > inijmin ) THEN
WRITE(ctmp1,9003) ' The number of mpi processes: ', mppsize
WRITE(ctmp2,9003) ' exceeds the maximum number of ocean subdomains = ', inijmin
WRITE(ctmp3,9002) ' we suppressed ', jpni*jpnj - mppsize, ' land subdomains '
WRITE(ctmp4,9002) ' BUT we had to keep ', mppsize - inijmin, ' land subdomains that are useless...'
CALL ctl_warn( ctmp1, ctmp2, ctmp3, ctmp4, ' ', ' --- YOU ARE WASTING CPU... ---', ' ' )
ELSE ! mppsize = inijmin
IF(lwp) THEN
IF(llbest) WRITE(numout,*) ' ==> you use the best mpi decomposition'
WRITE(numout,*)
WRITE(numout,9003) ' Number of mpi processes: ', mppsize
WRITE(numout,9003) ' Number of ocean subdomains = ', inijmin
WRITE(numout,9003) ' Number of suppressed land subdomains = ', jpni*jpnj - inijmin
WRITE(numout,*)
ENDIF
ENDIF
9000 FORMAT (a, i4, a, i4, a, i7, a)
9001 FORMAT (a, i4, a, i4)
9002 FORMAT (a, i4, a)
9003 FORMAT (a, i5)
ALLOCATE( nfimpp(jpni), nfproc(jpni), nfjpi(jpni), &
& iin(jpnij), ijn(jpnij), &
& iimppt(jpni,jpnj), ijmppt(jpni,jpnj), ijpi(jpni,jpnj), ijpj(jpni,jpnj), ipproc(jpni,jpnj), &
& inei(8,jpni,jpnj), llnei(8,jpni,jpnj), &
& impi(8,jpnij), &
& STAT=ierr )
CALL mpp_sum( 'mppini', ierr )
IF( ierr /= 0 ) CALL ctl_stop( 'STOP', 'mpp_init: unable to allocate standard ocean arrays' )
#if defined key_agrif
CALL agrif_nemo_init()
#endif
!
! 2. Index arrays for subdomains
! -----------------------------------
!
CALL mpp_basesplit( jpiglo, jpjglo, nn_hls, jpni, jpnj, jpimax, jpjmax, iimppt, ijmppt, ijpi, ijpj )
CALL mpp_getnum( llisOce, ipproc, iin, ijn )
!
ii = iin(narea)
ij = ijn(narea)
jpi = ijpi(ii,ij)
jpj = ijpj(ii,ij)
jpk = MAX( 2, jpkglo )
jpij = jpi*jpj
nimpp = iimppt(ii,ij)
njmpp = ijmppt(ii,ij)
!
CALL init_locglo ! define now functions needed to convert indices from/to global to/from local domains
CALL init_doloop ! set start/end indices of do-loop, depending on the halo width value (nn_hls)
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
!
IF(lwp) THEN
WRITE(numout,*)
WRITE(numout,*) 'MPI Message Passing MPI - domain lay out over processors'
WRITE(numout,*)
WRITE(numout,*) ' defines mpp subdomains'
WRITE(numout,*) ' jpni = ', jpni
WRITE(numout,*) ' jpnj = ', jpnj
WRITE(numout,*) ' jpnij = ', jpnij
WRITE(numout,*) ' nimpp = ', nimpp
WRITE(numout,*) ' njmpp = ', njmpp
WRITE(numout,*)
WRITE(numout,*) ' sum ijpi(i,1) = ', sum(ijpi(:,1)), ' jpiglo = ', jpiglo
WRITE(numout,*) ' sum ijpj(1,j) = ', SUM(ijpj(1,:)), ' jpjglo = ', jpjglo
! Subdomain grid print
ifreq = 4
il1 = 1
DO jn = 1, (jpni-1)/ifreq+1
il2 = MIN(jpni,il1+ifreq-1)
WRITE(numout,*)
WRITE(numout,9400) ('***',ji=il1,il2-1)
DO jj = jpnj, 1, -1
WRITE(numout,9403) (' ',ji=il1,il2-1)
WRITE(numout,9402) jj, (ijpi(ji,jj),ijpj(ji,jj),ji=il1,il2)
WRITE(numout,9404) (ipproc(ji,jj),ji=il1,il2)
WRITE(numout,9403) (' ',ji=il1,il2-1)
WRITE(numout,9400) ('***',ji=il1,il2-1)
END DO
WRITE(numout,9401) (ji,ji=il1,il2)
il1 = il1+ifreq
END DO
9400 FORMAT(' ***' ,20('*************',a3) )
9403 FORMAT(' * ',20(' * ',a3) )
9401 FORMAT(' ' ,20(' ',i3,' ') )
9402 FORMAT(' ',i3,' * ',20(i3,' x',i3,' * ') )
9404 FORMAT(' * ' ,20(' ' ,i4,' * ') )
ENDIF
!
! Store informations for the north pole folding communications
nfproc(:) = ipproc(:,jpnj)
nfimpp(:) = iimppt(:,jpnj)
nfjpi (:) = ijpi(:,jpnj)
!
! 3. Define Western, Eastern, Southern and Northern neighbors + corners in the subdomain grid reference
! ------------------------------------------------------------------------------------------------------
!
! note that North fold is has specific treatment for its MPI communications.
! This must not be treated as a "usual" communication with a northern neighbor.
! -> North fold processes have no Northern neighbor in the definition done bellow
!
llmpi_Iperio = jpni > 1 .AND. l_Iperio ! do i-periodicity with an MPI communication?
llmpi_Jperio = jpnj > 1 .AND. l_Jperio ! do j-periodicity with an MPI communication?
!
l_SelfPerio(1:2) = l_Iperio .AND. jpni == 1 ! west, east periodicity by itself
l_SelfPerio(3:4) = l_Jperio .AND. jpnj == 1 ! south, north periodicity by itself
l_SelfPerio(5:8) = l_SelfPerio(jpwe) .AND. l_SelfPerio(jpso) ! corners bi-periodicity by itself
!
! define neighbors mapping (1/2): default definition: ignore if neighbours are land-only subdomains or not
DO jj = 1, jpnj
DO ji = 1, jpni
!
IF ( llisOce(ji,jj) ) THEN ! this subdomain has some ocean: it has neighbours
!
inum0 = ji - 1 + ( jj - 1 ) * jpni ! index in the subdomains grid. start at 0
!
! Is there a neighbor?
llnei(jpwe,ji,jj) = ji > 1 .OR. llmpi_Iperio ! West nei exists if not the first column or llmpi_Iperio
llnei(jpea,ji,jj) = ji < jpni .OR. llmpi_Iperio ! East nei exists if not the last column or llmpi_Iperio
llnei(jpso,ji,jj) = jj > 1 .OR. llmpi_Jperio ! South nei exists if not the first line or llmpi_Jperio
llnei(jpno,ji,jj) = jj < jpnj .OR. llmpi_Jperio ! North nei exists if not the last line or llmpi_Jperio
llnei(jpsw,ji,jj) = llnei(jpwe,ji,jj) .AND. llnei(jpso,ji,jj) ! So-We nei exists if both South and West nei exist
llnei(jpse,ji,jj) = llnei(jpea,ji,jj) .AND. llnei(jpso,ji,jj) ! So-Ea nei exists if both South and East nei exist
llnei(jpnw,ji,jj) = llnei(jpwe,ji,jj) .AND. llnei(jpno,ji,jj) ! No-We nei exists if both North and West nei exist
llnei(jpne,ji,jj) = llnei(jpea,ji,jj) .AND. llnei(jpno,ji,jj) ! No-Ea nei exists if both North and East nei exist
!
! Which index (starting at 0) have neighbors in the subdomains grid?
IF( llnei(jpwe,ji,jj) ) inei(jpwe,ji,jj) = inum0 - 1 + jpni * COUNT( (/ ji == 1 /) )
IF( llnei(jpea,ji,jj) ) inei(jpea,ji,jj) = inum0 + 1 - jpni * COUNT( (/ ji == jpni /) )
IF( llnei(jpso,ji,jj) ) inei(jpso,ji,jj) = inum0 - jpni + jpni * jpnj * COUNT( (/ jj == 1 /) )
IF( llnei(jpno,ji,jj) ) inei(jpno,ji,jj) = inum0 + jpni - jpni * jpnj * COUNT( (/ jj == jpnj /) )
IF( llnei(jpsw,ji,jj) ) inei(jpsw,ji,jj) = inei(jpso,ji,jj) - 1 + jpni * COUNT( (/ ji == 1 /) )
IF( llnei(jpse,ji,jj) ) inei(jpse,ji,jj) = inei(jpso,ji,jj) + 1 - jpni * COUNT( (/ ji == jpni /) )
IF( llnei(jpnw,ji,jj) ) inei(jpnw,ji,jj) = inei(jpno,ji,jj) - 1 + jpni * COUNT( (/ ji == 1 /) )
IF( llnei(jpne,ji,jj) ) inei(jpne,ji,jj) = inei(jpno,ji,jj) + 1 - jpni * COUNT( (/ ji == jpni /) )
!
ELSE ! land-only domain has no neighbour
llnei(:,ji,jj) = .FALSE.
ENDIF
!
END DO
END DO
!
! define neighbors mapping (2/2): check if neighbours are not land-only subdomains
DO jj = 1, jpnj
DO ji = 1, jpni
DO jn = 1, 8
IF( llnei(jn,ji,jj) ) THEN ! if a neighbour is existing -> this should not be a land-only domain
ii = 1 + MOD( inei(jn,ji,jj) , jpni )
ij = 1 + inei(jn,ji,jj) / jpni
llnei(jn,ji,jj) = llisOce( ii, ij )
ENDIF
END DO
END DO
END DO
!
! update index of the neighbours in the subdomains grid
WHERE( .NOT. llnei ) inei = -1
!
! Save processor layout in ascii file
IF (llwrtlay) THEN
CALL ctl_opn( inum, 'layout.dat', 'REPLACE', 'FORMATTED', 'SEQUENTIAL', -1, numout, .FALSE., narea )
WRITE(inum,'(a)') ' jpnij jpimax jpjmax jpk jpiglo jpjglo ( local: narea jpi jpj )'
WRITE(inum,'(6i7,a,3i7,a)') jpnij,jpimax,jpjmax,jpk,jpiglo,jpjglo,' ( local: ',narea,jpi,jpj,' )'
WRITE(inum,*)
WRITE(inum, *) '------------------------------------'
WRITE(inum,'(a,i2)') ' Mapping of the default neighnourgs '
WRITE(inum, *) '------------------------------------'
WRITE(inum,*)
WRITE(inum,'(a)') ' rank ii ij jpi jpj nimpp njmpp mpiwe mpiea mpiso mpino mpisw mpise mpinw mpine'
DO jp = 1, jpnij
ii = iin(jp)
ij = ijn(jp)
WRITE(inum,'(15i6)') jp-1, ii, ij, ijpi(ii,ij), ijpj(ii,ij), iimppt(ii,ij), ijmppt(ii,ij), inei(:,ii,ij)
END DO
ENDIF
!
! 4. Define Western, Eastern, Southern and Northern neighbors + corners for each mpi process
! ------------------------------------------------------------------------------------------
!
! rewrite information from "subdomain grid" to mpi process list
! Warning, for example:
! position of the northern neighbor in the "subdomain grid"
! position of the northern neighbor in the "mpi process list"
! default definition: no neighbors
impi(:,:) = -1 ! (starting at 0, -1 if no neighbourg)
DO jp = 1, jpnij
ii = iin(jp)
ij = ijn(jp)
DO jn = 1, 8
IF( llnei(jn,ii,ij) ) THEN ! must be tested as some land-domain can be kept to fit mppsize
ii2 = 1 + MOD( inei(jn,ii,ij) , jpni )
ij2 = 1 + inei(jn,ii,ij) / jpni
impi(jn,jp) = ipproc( ii2, ij2 )
ENDIF
END DO
END DO
!
! 4. keep information for the local process
! -----------------------------------------
!
! set default neighbours
mpinei(:) = impi(:,narea)
DO jh = 1, n_hlsmax
mpiSnei(jh,:) = impi(:,narea) ! default definition
mpiRnei(jh,:) = impi(:,narea)
END DO
!
IF(lwp) THEN
WRITE(numout,*)
WRITE(numout,*) ' resulting internal parameters : '
WRITE(numout,*) ' narea = ', narea
WRITE(numout,*) ' mpi nei west = ', mpinei(jpwe) , ' mpi nei east = ', mpinei(jpea)
WRITE(numout,*) ' mpi nei south = ', mpinei(jpso) , ' mpi nei north = ', mpinei(jpno)
WRITE(numout,*) ' mpi nei so-we = ', mpinei(jpsw) , ' mpi nei so-ea = ', mpinei(jpse)
WRITE(numout,*) ' mpi nei no-we = ', mpinei(jpnw) , ' mpi nei no-ea = ', mpinei(jpne)
ENDIF
!
CALL mpp_ini_nc(nn_hls) ! Initialize communicator for neighbourhood collective communications
DO jh = 1, n_hlsmax
mpi_nc_com4(jh) = mpi_nc_com4(nn_hls) ! default definition
mpi_nc_com8(jh) = mpi_nc_com8(nn_hls)
END DO
! ! Exclude exchanges which contain only land points
!
IF( jpnij > 1 ) CALL init_excl_landpt
!
! ! Prepare mpp north fold
!
llmpiNFold = jpni > 1 .AND. l_NFold ! is the North fold done with an MPI communication?
l_IdoNFold = ijn(narea) == jpnj .AND. l_NFold ! is this process doing North fold?
!
IF( llmpiNFold ) CALL init_nfdcom( llwrtlay, inum ) ! init northfold communication, must be done after init_excl_landpt
!
! ! Save processor layout changes in ascii file
!
DO jh = 1, n_hlsmax ! different halo size
DO ji = 1, 8
ichanged(16*(jh-1) +ji) = COUNT( mpinei(ji:ji) /= mpiSnei(jh,ji:ji) )
ichanged(16*(jh-1)+8+ji) = COUNT( mpinei(ji:ji) /= mpiRnei(jh,ji:ji) )
END DO
END DO
CALL mpp_sum( "mpp_init", ichanged ) ! must be called by all processes
IF (llwrtlay) THEN
WRITE(inum,*)
WRITE(inum, *) '----------------------------------------------------------------------'
WRITE(inum,'(a,i2)') ' Mapping of the neighnourgs once excluding comm with only land points '
WRITE(inum, *) '----------------------------------------------------------------------'
DO jh = 1, n_hlsmax ! different halo size
WRITE(inum,*)
WRITE(inum,'(a,i2)') 'halo size: ', jh
WRITE(inum, *) '---------'
WRITE(inum,'(a)') ' rank ii ij mpiwe mpiea mpiso mpino mpisw mpise mpinw mpine'
WRITE(inum, '(11i6,a)') narea-1, iin(narea), ijn(narea), mpinei(:), ' <- Org'
WRITE(inum,'(18x,8i6,a,i1,a)') mpiSnei(jh,:), ' <- Send ', COUNT( mpinei(:) /= mpiSnei(jh,:) ), ' modif'
WRITE(inum,'(18x,8i6,a,i1,a)') mpiRnei(jh,:), ' <- Recv ', COUNT( mpinei(:) /= mpiRnei(jh,:) ), ' modif'
WRITE(inum,*) ' total changes among all mpi tasks:'
WRITE(inum,*) ' mpiwe mpiea mpiso mpino mpisw mpise mpinw mpine'
WRITE(inum,'(a,8i6)') ' Send: ', ichanged(jh*16-15:jh*16-8)
WRITE(inum,'(a,8i6)') ' Recv: ', ichanged(jh*16 -7:jh*16 )
END DO
ENDIF
!
CALL init_ioipsl ! Prepare NetCDF output file (if necessary)
!
IF (llwrtlay) CLOSE(inum)
!
DEALLOCATE(iin, ijn, iimppt, ijmppt, ijpi, ijpj, ipproc, inei, llnei, impi, llisOce)
!
END SUBROUTINE mpp_init
#endif
SUBROUTINE mpp_basesplit( kiglo, kjglo, khls, knbi, knbj, kimax, kjmax, kimppt, kjmppt, klci, klcj)
!!----------------------------------------------------------------------
!! *** ROUTINE mpp_basesplit ***
!!
!! ** Purpose : Lay out the global domain over processors.
!!
!! ** Method : Global domain is distributed in smaller local domains.
!!
!! ** Action : - set for all knbi*knbj domains:
!! kimppt : longitudinal index
!! kjmppt : latitudinal index
!! klci : first dimension
!! klcj : second dimension
!!----------------------------------------------------------------------
INTEGER, INTENT(in ) :: kiglo, kjglo
INTEGER, INTENT(in ) :: khls
INTEGER, INTENT(in ) :: knbi, knbj
INTEGER, INTENT( out) :: kimax, kjmax
INTEGER, DIMENSION(knbi,knbj), OPTIONAL, INTENT( out) :: kimppt, kjmppt
INTEGER, DIMENSION(knbi,knbj), OPTIONAL, INTENT( out) :: klci, klcj
!
INTEGER :: ji, jj
INTEGER :: i2hls
INTEGER :: iresti, irestj, irm, ijpjmin
!!----------------------------------------------------------------------
i2hls = 2*khls
!
#if defined key_nemocice_decomp
kimax = ( nx_global+2-i2hls + (knbi-1) ) / knbi + i2hls ! first dim.
kjmax = ( ny_global+2-i2hls + (knbj-1) ) / knbj + i2hls ! second dim.
#else
kimax = ( kiglo - i2hls + (knbi-1) ) / knbi + i2hls ! first dim.
kjmax = ( kjglo - i2hls + (knbj-1) ) / knbj + i2hls ! second dim.
#endif
IF( .NOT. PRESENT(kimppt) ) RETURN
!
! 1. Dimension arrays for subdomains
! -----------------------------------
! Computation of local domain sizes klci() klcj()
! These dimensions depend on global sizes knbi,knbj and kiglo,kjglo
! The subdomains are squares lesser than or equal to the global
! dimensions divided by the number of processors minus the overlap array.
!
iresti = 1 + MOD( kiglo - i2hls - 1 , knbi )
irestj = 1 + MOD( kjglo - i2hls - 1 , knbj )
!
! Need to use kimax and kjmax here since jpi and jpj not yet defined
#if defined key_nemocice_decomp
! Change padding to be consistent with CICE
klci(1:knbi-1,: ) = kimax
klci( knbi ,: ) = kiglo - (knbi - 1) * (kimax - i2hls)
klcj(: ,1:knbj-1) = kjmax
klcj(: , knbj ) = kjglo - (knbj - 1) * (kjmax - i2hls)
#else
klci(1:iresti ,:) = kimax
klci(iresti+1:knbi ,:) = kimax-1
IF( MINVAL(klci) < 3*khls ) THEN
WRITE(ctmp1,*) ' mpp_basesplit: minimum value of jpi must be >= ', 3*khls
WRITE(ctmp2,*) ' We have ', MINVAL(klci)
CALL ctl_stop( 'STOP', ctmp1, ctmp2 )
ENDIF
IF( l_NFold ) THEN
! minimize the size of the last row to compensate for the north pole folding coast
IF( c_NFtype == 'T' ) ijpjmin = 2+3*khls ! V and F folding must be outside of southern halos
IF( c_NFtype == 'F' ) ijpjmin = 1+3*khls ! V and F folding must be outside of southern halos
irm = knbj - irestj ! total number of lines to be removed
klcj(:,knbj) = MAX( ijpjmin, kjmax-irm ) ! we must have jpj >= ijpjmin in the last row
irm = irm - ( kjmax - klcj(1,knbj) ) ! remaining number of lines to remove
irestj = knbj - 1 - irm
klcj(:, irestj+1:knbj-1) = kjmax-1
ELSE
klcj(:, irestj+1:knbj ) = kjmax-1
ENDIF
klcj(:,1:irestj) = kjmax
IF( MINVAL(klcj) < 3*khls ) THEN
WRITE(ctmp1,*) ' mpp_basesplit: minimum value of jpj must be >= ', 3*khls
WRITE(ctmp2,*) ' We have ', MINVAL(klcj)
CALL ctl_stop( 'STOP', ctmp1, ctmp2 )
ENDIF
#endif
! 2. Index arrays for subdomains
! -------------------------------
kimppt(:,:) = 1
kjmppt(:,:) = 1
!
IF( knbi > 1 ) THEN
DO jj = 1, knbj
DO ji = 2, knbi
kimppt(ji,jj) = kimppt(ji-1,jj) + klci(ji-1,jj) - i2hls
END DO
END DO
ENDIF
!
IF( knbj > 1 )THEN
DO jj = 2, knbj
DO ji = 1, knbi
kjmppt(ji,jj) = kjmppt(ji,jj-1) + klcj(ji,jj-1) - i2hls
END DO
END DO
ENDIF
END SUBROUTINE mpp_basesplit
SUBROUTINE bestpartition( knbij, knbi, knbj, knbcnt, ldlist )
!!----------------------------------------------------------------------
!! *** ROUTINE bestpartition ***
!!
!! ** Purpose :
!!
!! ** Method :
!!----------------------------------------------------------------------
INTEGER, INTENT(in ) :: knbij ! total number of subdomains (knbi*knbj)
INTEGER, OPTIONAL, INTENT( out) :: knbi, knbj ! number if subdomains along i and j (knbi and knbj)
INTEGER, OPTIONAL, INTENT( out) :: knbcnt ! number of land subdomains
LOGICAL, OPTIONAL, INTENT(in ) :: ldlist ! .true.: print the list the best domain decompositions (with land)
!
INTEGER :: ji, jj, ii, iitarget
INTEGER :: iszitst, iszjtst
INTEGER :: isziref, iszjref
INTEGER :: iszimin, iszjmin
INTEGER :: inbij, iszij
INTEGER :: inbimax, inbjmax, inbijmax, inbijold
INTEGER :: isz0, isz1
INTEGER, DIMENSION( :), ALLOCATABLE :: indexok
INTEGER, DIMENSION( :), ALLOCATABLE :: inbi0, inbj0, inbij0 ! number of subdomains along i,j
INTEGER, DIMENSION( :), ALLOCATABLE :: iszi0, iszj0, iszij0 ! max size of the subdomains along i,j
INTEGER, DIMENSION( :), ALLOCATABLE :: inbi1, inbj1, inbij1 ! number of subdomains along i,j
INTEGER, DIMENSION( :), ALLOCATABLE :: iszi1, iszj1, iszij1 ! max size of the subdomains along i,j
LOGICAL :: llist
LOGICAL, DIMENSION(:,:), ALLOCATABLE :: llmsk2d ! max size of the subdomains along i,j
LOGICAL, DIMENSION(:,:), ALLOCATABLE :: llisOce ! - -
REAL(wp):: zpropland
!!----------------------------------------------------------------------
!
llist = .FALSE.
IF( PRESENT(ldlist) ) llist = ldlist
CALL mpp_init_landprop( zpropland ) ! get the proportion of land point over the gloal domain
inbij = NINT( REAL(knbij, wp) / ( 1.0 - zpropland ) ) ! define the largest possible value for jpni*jpnj
!
IF( llist ) THEN ; inbijmax = inbij*2
ELSE ; inbijmax = inbij
ENDIF
!
ALLOCATE(inbi0(inbijmax),inbj0(inbijmax),iszi0(inbijmax),iszj0(inbijmax))
!
inbimax = 0
inbjmax = 0
isziref = jpiglo*jpjglo+1 ! define a value that is larger than the largest possible
iszjref = jpiglo*jpjglo+1
!
! WARNING, see also init_excl_landpt: minimum subdomain size defined here according to nn_hls (and not n_hlsmax)
! --> If, one day, we want to use local halos largers than nn_hls, we must replace nn_hls by n_hlsmax
!
iszimin = 3*nn_hls ! minimum size of the MPI subdomain so halos are always adressing neighbor inner domain
iszjmin = 3*nn_hls
IF( c_NFtype == 'T' ) iszjmin = MAX(iszjmin, 2+3*nn_hls) ! V and F folding must be outside of southern halos
IF( c_NFtype == 'F' ) iszjmin = MAX(iszjmin, 1+3*nn_hls) ! V and F folding must be outside of southern halos
!
! get the list of knbi that gives a smaller jpimax than knbi-1
! get the list of knbj that gives a smaller jpjmax than knbj-1
DO ji = 1, inbijmax
#if defined key_nemocice_decomp
iszitst = ( nx_global+2-2*nn_hls + (ji-1) ) / ji + 2*nn_hls ! first dim.
#else
iszitst = ( Ni0glo + (ji-1) ) / ji + 2*nn_hls ! max subdomain i-size
#endif
IF( iszitst < isziref .AND. iszitst >= iszimin ) THEN
isziref = iszitst
inbimax = inbimax + 1
inbi0(inbimax) = ji
iszi0(inbimax) = isziref
ENDIF
#if defined key_nemocice_decomp
iszjtst = ( ny_global+2-2*nn_hls + (ji-1) ) / ji + 2*nn_hls ! first dim.
#else
iszjtst = ( Nj0glo + (ji-1) ) / ji + 2*nn_hls ! max subdomain j-size
#endif
IF( iszjtst < iszjref .AND. iszjtst >= iszjmin ) THEN
iszjref = iszjtst
inbjmax = inbjmax + 1
inbj0(inbjmax) = ji
iszj0(inbjmax) = iszjref
ENDIF
END DO
IF( inbimax == 0 ) THEN
WRITE(ctmp1,'(a,i2,a,i2)') ' mpp_ini bestpartition: Ni0glo (', Ni0glo, ') is too small to be used with nn_hls = ', nn_hls
CALL ctl_stop( 'STOP', ctmp1 )
ENDIF
IF( inbjmax == 0 ) THEN
WRITE(ctmp1,'(a,i2,a,i2)') ' mpp_ini bestpartition: Nj0glo (', Nj0glo, ') is too small to be used with nn_hls = ', nn_hls
CALL ctl_stop( 'STOP', ctmp1 )
ENDIF
! combine these 2 lists to get all possible knbi*knbj < inbijmax
ALLOCATE( llmsk2d(inbimax,inbjmax) )
DO jj = 1, inbjmax
DO ji = 1, inbimax
IF ( inbi0(ji) * inbj0(jj) <= inbijmax ) THEN ; llmsk2d(ji,jj) = .TRUE.
ELSE ; llmsk2d(ji,jj) = .FALSE.
ENDIF
END DO
END DO
isz1 = COUNT(llmsk2d)
ALLOCATE( inbi1(isz1), inbj1(isz1), iszi1(isz1), iszj1(isz1) )
ii = 0
DO jj = 1, inbjmax
DO ji = 1, inbimax
IF( llmsk2d(ji,jj) .EQV. .TRUE. ) THEN
ii = ii + 1
inbi1(ii) = inbi0(ji)
inbj1(ii) = inbj0(jj)
iszi1(ii) = iszi0(ji)
iszj1(ii) = iszj0(jj)
ENDIF
END DO
END DO
DEALLOCATE( inbi0, inbj0, iszi0, iszj0 )
DEALLOCATE( llmsk2d )
ALLOCATE( inbij1(isz1), iszij1(isz1) )
inbij1(:) = inbi1(:) * inbj1(:)
iszij1(:) = iszi1(:) * iszj1(:)
! if there is no land and no print
IF( .NOT. llist .AND. numbot == -1 .AND. numbdy == -1 ) THEN
! get the smaller partition which gives the smallest subdomain size
ii = MINLOC(inbij1, mask = iszij1 == MINVAL(iszij1), dim = 1)
knbi = inbi1(ii)
knbj = inbj1(ii)
IF(PRESENT(knbcnt)) knbcnt = 0
DEALLOCATE( inbi1, inbj1, inbij1, iszi1, iszj1, iszij1 )
RETURN
ENDIF
! extract only the partitions which reduce the subdomain size in comparison with smaller partitions
ALLOCATE( indexok(isz1) ) ! to store indices of the best partitions
isz0 = 0 ! number of best partitions
inbij = 1 ! start with the min value of inbij1 => 1
iszij = jpiglo*jpjglo+1 ! default: larger than global domain
DO WHILE( inbij <= inbijmax ) ! if we did not reach the max of inbij1
ii = MINLOC(iszij1, mask = inbij1 == inbij, dim = 1) ! warning: send back the first occurence if multiple results
IF ( iszij1(ii) < iszij ) THEN
ii = MINLOC( iszi1+iszj1, mask = iszij1 == iszij1(ii) .AND. inbij1 == inbij, dim = 1) ! select the smaller perimeter if multiple min
isz0 = isz0 + 1
indexok(isz0) = ii
iszij = iszij1(ii)
ENDIF
inbij = MINVAL(inbij1, mask = inbij1 > inbij) ! warning: return largest integer value if mask = .false. everywhere
END DO
DEALLOCATE( inbij1, iszij1 )
! keep only the best partitions (sorted by increasing order of subdomains number and decreassing subdomain size)
ALLOCATE( inbi0(isz0), inbj0(isz0), iszi0(isz0), iszj0(isz0) )
DO ji = 1, isz0
ii = indexok(ji)
inbi0(ji) = inbi1(ii)
inbj0(ji) = inbj1(ii)
iszi0(ji) = iszi1(ii)
iszj0(ji) = iszj1(ii)
END DO
DEALLOCATE( indexok, inbi1, inbj1, iszi1, iszj1 )
IF( llist ) THEN
IF(lwp) THEN
WRITE(numout,*)
WRITE(numout,*) ' For your information:'
WRITE(numout,*) ' list of the best partitions including land supression'
WRITE(numout,*) ' -----------------------------------------------------'
WRITE(numout,*)
ENDIF
ji = isz0 ! initialization with the largest value
ALLOCATE( llisOce(inbi0(ji), inbj0(ji)) )
CALL mpp_is_ocean( llisOce ) ! Warning: must be call by all cores (call mpp_sum)
inbijold = COUNT(llisOce)
DEALLOCATE( llisOce )
DO ji =isz0-1,1,-1
ALLOCATE( llisOce(inbi0(ji), inbj0(ji)) )
CALL mpp_is_ocean( llisOce ) ! Warning: must be call by all cores (call mpp_sum)
inbij = COUNT(llisOce)
DEALLOCATE( llisOce )
IF(lwp .AND. inbij < inbijold) THEN
WRITE(numout,'(a, i6, a, i6, a, f4.1, a, i9, a, i6, a, i6, a)') &
& 'nb_cores oce: ', inbij, ', land domains excluded: ', inbi0(ji)*inbj0(ji) - inbij, &
& ' (', REAL(inbi0(ji)*inbj0(ji) - inbij,wp) / REAL(inbi0(ji)*inbj0(ji),wp) *100., &
& '%), largest oce domain: ', iszi0(ji)*iszj0(ji), ' ( ', iszi0(ji),' x ', iszj0(ji), ' )'
inbijold = inbij
ENDIF
END DO
DEALLOCATE( inbi0, inbj0, iszi0, iszj0 )
IF(lwp) THEN
WRITE(numout,*)
WRITE(numout,*) ' -----------------------------------------------------------'
Guillaume S
committed
CALL FLUSH(numout)
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
ENDIF
CALL mppsync
CALL mppstop( ld_abort = .TRUE. )
ENDIF
DEALLOCATE( iszi0, iszj0 )
inbij = inbijmax + 1 ! default: larger than possible
ii = isz0+1 ! start from the end of the list (smaller subdomains)
DO WHILE( inbij > knbij ) ! while the number of ocean subdomains exceed the number of procs
ii = ii -1
ALLOCATE( llisOce(inbi0(ii), inbj0(ii)) )
CALL mpp_is_ocean( llisOce ) ! must be done by all core
inbij = COUNT(llisOce)
DEALLOCATE( llisOce )
END DO
knbi = inbi0(ii)
knbj = inbj0(ii)
IF(PRESENT(knbcnt)) knbcnt = knbi * knbj - inbij
DEALLOCATE( inbi0, inbj0 )
!
END SUBROUTINE bestpartition
SUBROUTINE mpp_init_landprop( propland )
!!----------------------------------------------------------------------
!! *** ROUTINE mpp_init_landprop ***
!!
!! ** Purpose : the the proportion of land points in the surface land-sea mask
!!
!! ** Method : read iproc strips (of length Ni0glo) of the land-sea mask
!!----------------------------------------------------------------------
REAL(wp), INTENT( out) :: propland ! proportion of land points in the global domain (between 0 and 1)
!
INTEGER, DIMENSION(jpni*jpnj) :: kusedom_1d
INTEGER :: inboce, iarea
INTEGER :: iproc, idiv, ijsz
INTEGER :: ijstr
LOGICAL, ALLOCATABLE, DIMENSION(:,:) :: lloce
!!----------------------------------------------------------------------
! do nothing if there is no land-sea mask
IF( numbot == -1 .and. numbdy == -1 ) THEN
propland = 0.
RETURN
ENDIF
! number of processes reading the bathymetry file
iproc = MINVAL( (/mppsize, Nj0glo/2, 100/) ) ! read a least 2 lines, no more that 100 processes reading at the same time
! we want to read iproc strips of the land-sea mask. -> pick up iproc processes every idiv processes starting at 1
IF( iproc == 1 ) THEN ; idiv = mppsize
ELSE ; idiv = ( mppsize - 1 ) / ( iproc - 1 )
ENDIF
iarea = (narea-1)/idiv ! involed process number (starting counting at 0)
IF( MOD( narea-1, idiv ) == 0 .AND. iarea < iproc ) THEN ! beware idiv can be = to 1
!
ijsz = Nj0glo / iproc ! width of the stripe to read
IF( iarea < MOD(Nj0glo,iproc) ) ijsz = ijsz + 1
ijstr = iarea*(Nj0glo/iproc) + MIN(iarea, MOD(Nj0glo,iproc)) + 1 ! starting j position of the reading
!
ALLOCATE( lloce(Ni0glo, ijsz) ) ! allocate the strip
CALL read_mask( 1, ijstr, Ni0glo, ijsz, lloce )
inboce = COUNT(lloce) ! number of ocean point in the stripe
DEALLOCATE(lloce)
!
ELSE
inboce = 0
ENDIF
CALL mpp_sum( 'mppini', inboce ) ! total number of ocean points over the global domain
!
propland = REAL( Ni0glo*Nj0glo - inboce, wp ) / REAL( Ni0glo*Nj0glo, wp )
!
END SUBROUTINE mpp_init_landprop
SUBROUTINE mpp_is_ocean( ldIsOce )
!!----------------------------------------------------------------------
!! *** ROUTINE mpp_is_ocean ***
!!
!! ** Purpose : Check for a mpi domain decomposition inbi x inbj which
!! subdomains, including 1 halo (even if nn_hls>1), contain
!! at least 1 ocean point.
!! We must indeed ensure that each subdomain that is a neighbour
!! of a land subdomain, has only land points on its boundary
!! (inside the inner subdomain) with the land subdomain.
!! This is needed to get the proper bondary conditions on
!! a subdomain with a closed boundary.
!!
!! ** Method : read inbj strips (of length Ni0glo) of the land-sea mask
!!----------------------------------------------------------------------
LOGICAL, DIMENSION(:,:), INTENT( out) :: ldIsOce ! .true. if a sub domain constains 1 ocean point
!
INTEGER :: idiv, iimax, ijmax, iarea
INTEGER :: inbi, inbj, inx, iny, inry, isty
sebastien masson
committed
INTEGER :: ji, jj, jn
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
INTEGER, ALLOCATABLE, DIMENSION(:,:) :: inboce ! number oce oce pint in each mpi subdomain
INTEGER, ALLOCATABLE, DIMENSION(: ) :: inboce_1d
INTEGER, ALLOCATABLE, DIMENSION(:,:) :: iimppt, ijpi
INTEGER, ALLOCATABLE, DIMENSION(:,:) :: ijmppt, ijpj
LOGICAL, ALLOCATABLE, DIMENSION(:,:) :: lloce ! lloce(i,j) = .true. if the point (i,j) is ocean
!!----------------------------------------------------------------------
! do nothing if there is no land-sea mask
IF( numbot == -1 .AND. numbdy == -1 ) THEN
ldIsOce(:,:) = .TRUE.
RETURN
ENDIF
!
inbi = SIZE( ldIsOce, dim = 1 )
inbj = SIZE( ldIsOce, dim = 2 )
!
! we want to read inbj strips of the land-sea mask. -> pick up inbj processes every idiv processes starting at 1
IF ( inbj == 1 ) THEN ; idiv = mppsize
ELSE IF ( mppsize < inbj ) THEN ; idiv = 1
ELSE ; idiv = ( mppsize - 1 ) / ( inbj - 1 )
ENDIF
!
ALLOCATE( inboce(inbi,inbj), inboce_1d(inbi*inbj) )
inboce(:,:) = 0 ! default no ocean point found
!
DO jn = 0, (inbj-1)/mppsize ! if mppsize < inbj : more strips than mpi processes (because of potential land domains)
!
iarea = (narea-1)/idiv + jn * mppsize + 1 ! involed process number (starting counting at 1)
IF( MOD( narea-1, idiv ) == 0 .AND. iarea <= inbj ) THEN ! beware idiv can be = to 1
!
ALLOCATE( iimppt(inbi,inbj), ijmppt(inbi,inbj), ijpi(inbi,inbj), ijpj(inbi,inbj) )
CALL mpp_basesplit( Ni0glo, Nj0glo, 0, inbi, inbj, iimax, ijmax, iimppt, ijmppt, ijpi, ijpj )
!
inx = Ni0glo + 2 ; iny = ijpj(1,iarea) + 2 ! strip size + 1 halo on each direction (even if nn_hls>1)
ALLOCATE( lloce(inx, iny) ) ! allocate the strip
inry = iny - COUNT( (/ iarea == 1, iarea == inbj /) ) ! number of point to read in y-direction
isty = 1 + COUNT( (/ iarea == 1 /) ) ! read from the first or the second line?
CALL read_mask( 1, ijmppt(1,iarea) - 2 + isty, Ni0glo, inry, lloce(2:inx-1, isty:inry+isty-1) ) ! read the strip
!
IF( iarea == 1 ) THEN ! the first line was not read
IF( l_Jperio ) THEN ! north-south periodocity
CALL read_mask( 1, Nj0glo, Ni0glo, 1, lloce(2:inx-1, 1) ) ! read the last line -> first line of lloce
ELSE
lloce(2:inx-1, 1) = .FALSE. ! closed boundary
ENDIF
ENDIF