1 | PROGRAM test_remap_omp |
---|
2 | |
---|
3 | USE xios |
---|
4 | USE mod_wait |
---|
5 | USE omp_lib |
---|
6 | USE netcdf |
---|
7 | |
---|
8 | IMPLICIT NONE |
---|
9 | INCLUDE "mpif.h" |
---|
10 | INTEGER :: rank |
---|
11 | INTEGER :: size |
---|
12 | INTEGER :: ierr |
---|
13 | |
---|
14 | CHARACTER(len=*),PARAMETER :: id="client" |
---|
15 | INTEGER :: comm |
---|
16 | TYPE(xios_duration) :: dtime |
---|
17 | TYPE(xios_context) :: ctx_hdl |
---|
18 | |
---|
19 | DOUBLE PRECISION,ALLOCATABLE :: src_lon(:), dst_lon(:) |
---|
20 | DOUBLE PRECISION,ALLOCATABLE :: src_lat(:), dst_lat(:) |
---|
21 | DOUBLE PRECISION,ALLOCATABLE :: src_boundslon(:,:), dst_boundslon(:,:) |
---|
22 | DOUBLE PRECISION,ALLOCATABLE :: src_boundslat(:,:), dst_boundslat(:,:) |
---|
23 | DOUBLE PRECISION,ALLOCATABLE :: src_field_2D(:) |
---|
24 | DOUBLE PRECISION,ALLOCATABLE :: tmp_field_0(:), tmp_field_1(:), tmp_field_2(:) |
---|
25 | DOUBLE PRECISION,ALLOCATABLE :: src_field_3D(:,:), src_field_4D(:,:,:), lval(:), lval1(:), lval2(:), src_field_pression(:,:) |
---|
26 | LOGICAL,ALLOCATABLE :: src_mask_2D(:) |
---|
27 | INTEGER :: src_ni_glo, dst_ni_glo; |
---|
28 | INTEGER :: src_nvertex, dst_nvertex; |
---|
29 | INTEGER :: src_ibegin, dst_ibegin; |
---|
30 | INTEGER :: src_ni, dst_ni; |
---|
31 | INTEGER :: src_tmp_ni, src_tmp_nj, src_tmp_n; |
---|
32 | CHARACTER(LEN=*),PARAMETER :: src_file="h14.nc" |
---|
33 | CHARACTER(LEN=*),PARAMETER :: dst_file="r180x90.nc" |
---|
34 | INTEGER :: ncid |
---|
35 | INTEGER :: dimids(2) |
---|
36 | INTEGER :: div,remain |
---|
37 | INTEGER :: varid |
---|
38 | INTEGER :: ts |
---|
39 | INTEGER :: i |
---|
40 | INTEGER,PARAMETER :: llm=5, interpolatedLlm = 4, llm2 = 6 |
---|
41 | DOUBLE PRECISION, PARAMETER :: missing_value = 100000 |
---|
42 | INTEGER :: provided |
---|
43 | |
---|
44 | integer :: num_args, ix, nb_servers |
---|
45 | character(len=12), dimension(:), allocatable :: args |
---|
46 | |
---|
47 | num_args = command_argument_count() |
---|
48 | if(num_args<1) then |
---|
49 | print*, "please give the number of servers as argument." |
---|
50 | call abort |
---|
51 | endif |
---|
52 | |
---|
53 | allocate(args(num_args)) ! I've omitted checking the return status of the allocation |
---|
54 | |
---|
55 | do ix = 1, num_args |
---|
56 | call get_command_argument(ix,args(ix)) |
---|
57 | ! now parse the argument as you wish |
---|
58 | end do |
---|
59 | |
---|
60 | READ(args(1),*) nb_servers |
---|
61 | |
---|
62 | CALL MPI_INIT_THREAD(3, provided, ierr) |
---|
63 | if(provided .NE. 3) then |
---|
64 | print*, "provided thread level = ", provided |
---|
65 | call MPI_Abort() |
---|
66 | endif |
---|
67 | CALL init_wait |
---|
68 | |
---|
69 | CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr) |
---|
70 | CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierr) |
---|
71 | if(rank < size-nb_servers) then |
---|
72 | |
---|
73 | !$omp parallel default(firstprivate) |
---|
74 | |
---|
75 | !!! XIOS Initialization (get the local communicator) |
---|
76 | |
---|
77 | CALL xios_initialize(id,return_comm=comm) |
---|
78 | CALL MPI_COMM_RANK(comm,rank,ierr) |
---|
79 | CALL MPI_COMM_SIZE(comm,size,ierr) |
---|
80 | |
---|
81 | rank = rank*omp_get_num_threads() + omp_get_thread_num() |
---|
82 | size = size*omp_get_num_threads() |
---|
83 | |
---|
84 | print*, "rank = ", rank, " size = ", size |
---|
85 | |
---|
86 | !$omp critical (open_file) |
---|
87 | ierr=NF90_OPEN(src_file, NF90_NOWRITE, ncid) |
---|
88 | ierr=NF90_INQ_VARID(ncid,"bounds_lon",varid) |
---|
89 | ierr=NF90_INQUIRE_VARIABLE(ncid, varid,dimids=dimids) |
---|
90 | ierr=NF90_INQUIRE_DIMENSION(ncid, dimids(1), len=src_nvertex) |
---|
91 | ierr=NF90_INQUIRE_DIMENSION(ncid, dimids(2), len=src_ni_glo) |
---|
92 | |
---|
93 | div = src_ni_glo/size |
---|
94 | remain = MOD( src_ni_glo, size ) |
---|
95 | IF (rank < remain) THEN |
---|
96 | src_ni=div+1 ; |
---|
97 | src_ibegin=rank*(div+1) ; |
---|
98 | ELSE |
---|
99 | src_ni=div ; |
---|
100 | src_ibegin= remain * (div+1) + (rank-remain) * div ; |
---|
101 | ENDIF |
---|
102 | |
---|
103 | ALLOCATE(src_lon(src_ni)) |
---|
104 | ALLOCATE(src_lat(src_ni)) |
---|
105 | ALLOCATE(src_boundslon(src_nvertex,src_ni)) |
---|
106 | ALLOCATE(src_boundslat(src_nvertex,src_ni)) |
---|
107 | ALLOCATE(src_field_2D(src_ni)) |
---|
108 | ALLOCATE(src_field_3D(src_ni,llm)) |
---|
109 | ALLOCATE(src_field_4D(src_ni,llm,llm2)) |
---|
110 | ALLOCATE(src_mask_2D(src_ni)) |
---|
111 | ALLOCATE(src_field_pression(src_ni,llm)) |
---|
112 | ALLOCATE(lval(llm)) |
---|
113 | ALLOCATE(lval1(interpolatedLlm)) |
---|
114 | ALLOCATE(lval2(llm2)) |
---|
115 | lval2 = 0 |
---|
116 | lval=0 |
---|
117 | lval1=0 |
---|
118 | |
---|
119 | ierr=NF90_INQ_VARID(ncid,"lon",varid) |
---|
120 | ierr=NF90_GET_VAR(ncid,varid, src_lon, start=(/src_ibegin+1/),count=(/src_ni/)) |
---|
121 | ierr=NF90_INQ_VARID(ncid,"lat",varid) |
---|
122 | ierr=NF90_GET_VAR(ncid,varid, src_lat, start=(/src_ibegin+1/),count=(/src_ni/)) |
---|
123 | ierr=NF90_INQ_VARID(ncid,"bounds_lon",varid) |
---|
124 | ierr=NF90_GET_VAR(ncid,varid,src_boundslon, start=(/1,src_ibegin+1/),count=(/src_nvertex,src_ni/)) |
---|
125 | ierr=NF90_INQ_VARID(ncid,"bounds_lat",varid) |
---|
126 | ierr=NF90_GET_VAR(ncid,varid, src_boundslat, start=(/1,src_ibegin+1/),count=(/src_nvertex,src_ni/)) |
---|
127 | ierr=NF90_INQ_VARID(ncid,"val",varid) |
---|
128 | ierr=NF90_GET_VAR(ncid,varid, src_field_2D, start=(/src_ibegin+1/),count=(/src_ni/)) |
---|
129 | DO i=1,src_ni |
---|
130 | src_field_3D(i,:) = src_field_2D(i) |
---|
131 | IF (MOD(i,10)==0) THEN |
---|
132 | src_mask_2D(i)=.FALSE. |
---|
133 | ELSE |
---|
134 | src_mask_2D(i)=.TRUE. |
---|
135 | ENDIF |
---|
136 | ENDDO |
---|
137 | |
---|
138 | DO i=1,llm |
---|
139 | lval(i) = i*100 |
---|
140 | src_field_pression(:,i) = i * 100 |
---|
141 | src_field_3D(:,i) = src_field_3D(:,i) + i * 10 |
---|
142 | ENDDO |
---|
143 | |
---|
144 | DO i=1,llm2 |
---|
145 | src_field_4D(:,:,i) = src_field_3D(:,:) |
---|
146 | ENDDO |
---|
147 | |
---|
148 | DO i=1,interpolatedLlm |
---|
149 | lval2(i) = i*10 |
---|
150 | lval1(i) = i*10 + 2 |
---|
151 | ENDDO |
---|
152 | |
---|
153 | print*, "ID = ", rank, "src_ni = ", src_ni, "src_nvertex = ", src_nvertex, "src_ni_glo = ", src_ni_glo |
---|
154 | |
---|
155 | ierr=NF90_OPEN(dst_file, NF90_NOWRITE, ncid) |
---|
156 | ierr=NF90_INQ_VARID(ncid,"bounds_lon",varid) |
---|
157 | ierr=NF90_INQUIRE_VARIABLE(ncid, varid,dimids=dimids) |
---|
158 | ierr=NF90_INQUIRE_DIMENSION(ncid, dimids(1), len=dst_nvertex) |
---|
159 | ierr=NF90_INQUIRE_DIMENSION(ncid, dimids(2), len=dst_ni_glo) |
---|
160 | |
---|
161 | div = dst_ni_glo/size |
---|
162 | remain = MOD( dst_ni_glo, size ) |
---|
163 | IF (rank < remain) THEN |
---|
164 | dst_ni=div+1 ; |
---|
165 | dst_ibegin=rank*(div+1) ; |
---|
166 | ELSE |
---|
167 | dst_ni=div ; |
---|
168 | dst_ibegin= remain * (div+1) + (rank-remain) * div ; |
---|
169 | ENDIF |
---|
170 | |
---|
171 | ALLOCATE(dst_lon(dst_ni)) |
---|
172 | ALLOCATE(dst_lat(dst_ni)) |
---|
173 | ALLOCATE(dst_boundslon(dst_nvertex,dst_ni)) |
---|
174 | ALLOCATE(dst_boundslat(dst_nvertex,dst_ni)) |
---|
175 | |
---|
176 | ierr=NF90_INQ_VARID(ncid,"lon",varid) |
---|
177 | ierr=NF90_GET_VAR(ncid,varid, dst_lon, start=(/dst_ibegin+1/),count=(/dst_ni/)) |
---|
178 | ierr=NF90_INQ_VARID(ncid,"lat",varid) |
---|
179 | ierr=NF90_GET_VAR(ncid,varid, dst_lat, start=(/dst_ibegin+1/),count=(/dst_ni/)) |
---|
180 | ierr=NF90_INQ_VARID(ncid,"bounds_lon",varid) |
---|
181 | ierr=NF90_GET_VAR(ncid,varid,dst_boundslon, start=(/1,dst_ibegin+1/),count=(/dst_nvertex,dst_ni/)) |
---|
182 | ierr=NF90_INQ_VARID(ncid,"bounds_lat",varid) |
---|
183 | ierr=NF90_GET_VAR(ncid,varid, dst_boundslat, start=(/1,dst_ibegin+1/),count=(/dst_nvertex,dst_ni/)) |
---|
184 | |
---|
185 | !$omp end critical (open_file) |
---|
186 | |
---|
187 | !$omp barrier |
---|
188 | |
---|
189 | !$omp master |
---|
190 | CALL MPI_barrier(comm, ierr) |
---|
191 | !$omp end master |
---|
192 | |
---|
193 | !$omp barrier |
---|
194 | |
---|
195 | CALL xios_context_initialize("test",comm) |
---|
196 | CALL xios_get_handle("test",ctx_hdl) |
---|
197 | CALL xios_set_current_context(ctx_hdl) |
---|
198 | |
---|
199 | CALL xios_set_domain_attr("src_domain", ni_glo=src_ni_glo, ibegin=src_ibegin, ni=src_ni, type="unstructured") |
---|
200 | CALL xios_set_domain_attr("src_domain", lonvalue_1D=src_lon, latvalue_1D=src_lat, & |
---|
201 | bounds_lon_1D=src_boundslon, bounds_lat_1D=src_boundslat, nvertex=src_nvertex) |
---|
202 | |
---|
203 | CALL xios_set_domain_attr("src_domain_clone", ni_glo=src_ni_glo, ibegin=src_ibegin, ni=src_ni, type="unstructured") |
---|
204 | CALL xios_set_domain_attr("src_domain_clone", lonvalue_1D=src_lon, latvalue_1D=src_lat, & |
---|
205 | bounds_lon_1D=src_boundslon, bounds_lat_1D=src_boundslat, nvertex=src_nvertex, & |
---|
206 | mask_1d=src_mask_2D) |
---|
207 | |
---|
208 | CALL xios_set_axis_attr("src_axis", n_glo=llm, value=lval) |
---|
209 | CALL xios_set_axis_attr("nq", n_glo=llm2, value=lval2) |
---|
210 | |
---|
211 | CALL xios_set_domain_attr("dst_domain", ni_glo=dst_ni_glo, ibegin=dst_ibegin, ni=dst_ni, type="unstructured") |
---|
212 | CALL xios_set_domain_attr("dst_domain", lonvalue_1D=dst_lon, latvalue_1D=dst_lat, & |
---|
213 | bounds_lon_1D=dst_boundslon, bounds_lat_1D=dst_boundslat, nvertex=dst_nvertex) |
---|
214 | |
---|
215 | dtime%second = 3600 |
---|
216 | CALL xios_set_timestep(dtime) |
---|
217 | |
---|
218 | CALL xios_close_context_definition() |
---|
219 | print *, "xios_close_context_definition OK " |
---|
220 | |
---|
221 | CALL xios_get_domain_attr("src_domain_regular_read", ni=src_tmp_ni, nj=src_tmp_nj) |
---|
222 | ALLOCATE(tmp_field_0(src_tmp_ni*src_tmp_nj)) |
---|
223 | |
---|
224 | !CALL xios_get_axis_attr("src_axis_curvilinear_read", n=src_tmp_n) |
---|
225 | !CALL xios_get_domain_attr("src_domain_curvilinear_read", ni=src_tmp_ni, nj=src_tmp_nj) |
---|
226 | !ALLOCATE(tmp_field_1(src_tmp_ni*src_tmp_nj*src_tmp_n)) |
---|
227 | |
---|
228 | !CALL xios_get_domain_attr("src_domain_unstructured_read", ni=src_tmp_ni, nj=src_tmp_nj) |
---|
229 | !ALLOCATE(tmp_field_2(src_tmp_ni*src_tmp_nj)) |
---|
230 | |
---|
231 | DO ts=1,1 |
---|
232 | CALL xios_recv_field("src_field_regular", tmp_field_0) |
---|
233 | !CALL xios_recv_field("src_field_curvilinear", tmp_field_1) |
---|
234 | !CALL xios_recv_field("src_field_unstructured", tmp_field_2) |
---|
235 | CALL xios_update_calendar(ts) |
---|
236 | CALL xios_send_field("src_field_2D",src_field_2D) |
---|
237 | CALL xios_send_field("src_field_2D_clone",src_field_2D) |
---|
238 | CALL xios_send_field("src_field_3D",src_field_3D) |
---|
239 | !CALL xios_send_field("src_field_4D",src_field_4D) |
---|
240 | !CALL xios_send_field("src_field_3D_pression",src_field_pression) |
---|
241 | CALL xios_send_field("tmp_field_0",tmp_field_0) |
---|
242 | !CALL xios_send_field("tmp_field_1",tmp_field_1) |
---|
243 | !CALL xios_send_field("tmp_field_2",tmp_field_2) |
---|
244 | CALL wait_us(5000) ; |
---|
245 | ENDDO |
---|
246 | |
---|
247 | CALL xios_context_finalize() |
---|
248 | |
---|
249 | DEALLOCATE(src_lon, src_lat, src_boundslon,src_boundslat, src_field_2D) |
---|
250 | DEALLOCATE(dst_lon, dst_lat, dst_boundslon,dst_boundslat) |
---|
251 | ! DEALLOCATE(tmp_field_0, tmp_field_1, tmp_field_2) |
---|
252 | |
---|
253 | CALL xios_finalize() |
---|
254 | print *, "Client : xios_finalize OK", rank, size |
---|
255 | |
---|
256 | !$omp barrier |
---|
257 | |
---|
258 | !$omp master |
---|
259 | CALL MPI_COMM_FREE(comm, ierr) |
---|
260 | !$omp end master |
---|
261 | |
---|
262 | !$omp barrier |
---|
263 | |
---|
264 | !$omp end parallel |
---|
265 | |
---|
266 | else |
---|
267 | |
---|
268 | CALL xios_init_server |
---|
269 | print *, "Server : xios_finalize ", rank |
---|
270 | |
---|
271 | endif |
---|
272 | |
---|
273 | |
---|
274 | |
---|
275 | CALL MPI_FINALIZE(ierr) |
---|
276 | |
---|
277 | END PROGRAM test_remap_omp |
---|
278 | |
---|
279 | |
---|
280 | |
---|
281 | |
---|
282 | |
---|
283 | |
---|