New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
make_partition.f90 in branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/TOOLS/RK_PARTITION/src – NEMO

source: branches/2011/DEV_r2739_STFC_dCSE/NEMOGCM/TOOLS/RK_PARTITION/src/make_partition.f90 @ 3849

Last change on this file since 3849 was 3849, checked in by trackstand2, 11 years ago

Merge branch 'partitioner'

File size: 5.6 KB
Line 
1PROGRAM make_partition
2   USE iso_c_binding ! For command-line interface
3   USE partition_mod, ONLY: jpiglo, jpjglo, write_partition, nemo_partition, &
4                            allocate_arrays, partition_mca_rk, cyclic_bc
5   USE mask_mod, ONLY: imask, generate_mask
6   IMPLICIT none
7
8   INTEGER :: narg, iarg, arglen
9   INTEGER :: ji, ierr
10   INTEGER :: num_pes
11   CHARACTER(len=100) :: argval
12   INTEGER :: cores_per_node ! No. of cores per compute node on the machine
13                             ! that NEMO will run on.
14   LOGICAL :: regular ! True for regular decomp, false otherwise
15
16   !!----------------------------------------------------------------------
17
18   ! Initialise domain size
19   jpiglo  = 0 ; jpjglo = 0
20   num_pes = 0
21   cores_per_node = 16
22   regular   = .FALSE.        ! By default we do recursive partitioning
23   cyclic_bc = .FALSE.        ! Cyclic boundary conditions off by default
24
25   ! Parse the command-line arguments
26   narg = COMMAND_ARGUMENT_COUNT()
27
28   IF(narg == 0)THEN
29      CALL print_usage()
30      STOP
31   END IF
32
33   iarg = 1
34   parse_args: DO WHILE(iarg <= narg)
35
36      CALL GET_COMMAND_ARGUMENT(iarg,argval,arglen,ierr)
37
38      IF(TRIM(argval) == '-d')THEN
39         iarg = iarg + 1
40         CALL GET_COMMAND_ARGUMENT(iarg,argval,arglen,ierr)
41
42         ! Parse this argument. We expect it to be of the form <nx>x<ny>.
43         ji = INDEX(argval,"x")
44         IF(ji < 2 .OR. ji > (arglen-1))THEN
45            WRITE(*,"('ERROR: unrecognised argument format: ',(A))") TRIM(argval)
46         END IF
47         READ(argval(1:ji-1),*,IOSTAT=ierr) jpiglo
48         IF(ierr /= 0)THEN
49            WRITE(*,"('ERROR: failed to parse jpiglo argument')")
50            STOP
51         END IF
52         READ(argval(ji+1:),*,IOSTAT=ierr) jpjglo
53         IF(ierr /= 0)THEN
54            WRITE(*,"('ERROR: failed to parse jpjglo argument')")
55            STOP
56         END IF
57
58      ELSE IF(TRIM(argval) == '-np')THEN
59         iarg = iarg + 1
60         CALL GET_COMMAND_ARGUMENT(iarg,argval,arglen,ierr)
61
62         ! Parse this argument. We expect it to be of the form <np>.
63         READ(argval,*,IOSTAT=ierr) num_pes
64         IF(ierr /= 0)THEN
65            WRITE(*,"('ERROR: failed to parse num_pes argument')")
66            STOP
67         END IF
68
69      ELSE IF(TRIM(argval) == '-c')THEN
70         iarg = iarg + 1
71         CALL GET_COMMAND_ARGUMENT(iarg,argval,arglen,ierr)
72         ! Parse this argument. We expect it to be of the form <cpn>.
73         READ(argval,*,IOSTAT=ierr) cores_per_node
74
75      ELSE IF(TRIM(argval) == '-r')THEN
76         ! Switch-on regular partitioning
77         regular = .TRUE.
78
79      ELSE IF(TRIM(argval) == '-cyclic')THEN
80         ! Switch-on cyclic boundary conditions
81         cyclic_bc = .TRUE.
82
83      ELSE IF(TRIM(argval) == '-h')THEN
84         CALL print_usage()
85
86      ELSE
87         WRITE(*,"('ERROR: unrecognised argument: ',(A))") TRIM(argval)
88         STOP
89
90      END IF
91
92      iarg = iarg + 1
93   END DO parse_args
94
95   ! Check that essential parameters have been supplied by user
96   IF( num_pes == 0 )THEN
97      WRITE (*,*) 'ERROR: you must specify num. PEs to decompose over!'
98      CALL print_usage()
99      STOP
100   END IF
101
102   ! Check whether domain dimensions have been specified
103   IF( jpiglo < 1 .OR. jpjglo < 1 )THEN
104      IF( regular )THEN
105         ! Actually, I could read the bathy file if available to get the domain
106         ! dimensions for this case.
107         WRITE (*,*) 'ERROR: you must specify domain extent when doing regular partition!'
108         CALL print_usage()
109         STOP
110      ELSE
111         WRITE(*,*) 'Domain dimensions will be read from bathymetry file'
112      END IF
113   END IF
114
115   WRITE (*,FMT="(/'No. of MPI Processes = ',I4)") num_pes
116   IF(.NOT. regular)THEN
117      WRITE (*,FMT="('No. of cores per compute node = ',I4)") cores_per_node
118   END IF
119
120   ! Generate the land/sea mask from the bathymetry which is read
121   ! from file
122   CALL generate_mask(regular, ierr)
123   IF(ierr /= 0)THEN
124      STOP 'Failed to generate land/sea mask'
125   END IF
126
127   CALL allocate_arrays(num_pes, ierr)
128
129   IF(regular)THEN
130
131      ! Imitate standard NEMO regular partitioning
132      CALL nemo_partition(num_pes)
133
134   ELSE
135
136      ! Multi-core aware version of recursive k-section partitioning.
137      ! Currently only accounts for whether a grid point is wet or dry.
138      ! It has no knowledge of the number of wet levels at a point.
139      CALL partition_mca_rk ( imask, num_pes, cores_per_node, ierr )
140
141      ! Check the error code from partitioning.
142      IF ( ierr /= 0 ) THEN
143         STOP 'nemo_recursive_partition: Partitioning failed'
144      ENDIF
145
146   END IF
147
148   CALL write_partition(imask)
149
150   WRITE(*,FMT="(/'Partitioning done and written to partition.dat.new. Also'/ &
151        &  'written in postscript to domain_decomp.ps.'/)")
152
153CONTAINS
154
155  SUBROUTINE print_usage()
156     IMPLICIT None
157     WRITE(*,*)
158     WRITE(*,*) 'Usage: make_partition.exe -d <jpiglo>x<jpjglo> -np <nproc> -c <cores_per_node> [-r] [-cyclic] [-h]'
159     WRITE(*,*) 'Where:  domain is jpiglo x jpjglo in extent'
160     WRITE(*,*) '        nproc is no. of sub-domains/MPI procs required'
161     WRITE(*,*) '        cores_per_node is no. of cores per compute node on machine'
162     WRITE(*,*) '           on which NEMO is to be executed'
163     WRITE(*,*) '        -r      : generate regular (old style) partition'
164     WRITE(*,*) '        -cyclic : enable cyclic E/W boundary conditions'
165     WRITE(*,*) '        -h       : print this message'
166     WRITE(*,*)
167     WRITE(*,*) 'Vertical coordinate options are read from the NEMO namelist file and'
168     WRITE(*,*) 'used to determine whether to smooth the bathy.'
169     WRITE(*,*)
170  END SUBROUTINE print_usage
171
172
173END PROGRAM make_partition
Note: See TracBrowser for help on using the repository browser.