source: XIOS/dev/branch_openmp/src/test/test_unstruct_complete.f90 @ 1350

Last change on this file since 1350 was 1350, checked in by yushan, 6 years ago

toy_cmip6_omp from Curie

  • Property copyright set to
    Software name : XIOS (Xml I/O Server)
    http://forge.ipsl.jussieu.fr/ioserver
    Creation date : January 2009
    Licence : CeCCIL version2
    see license file in root directory : Licence_CeCILL_V2-en.txt
    or http://www.cecill.info/licences/Licence_CeCILL_V2-en.html
    Holder : CEA/LSCE (Laboratoire des Sciences du CLimat et de l'Environnement)
    CNRS/IPSL (Institut Pierre Simon Laplace)
    Project Manager : Yann Meurdesoif
    yann.meurdesoif@cea.fr
File size: 9.1 KB
Line 
1PROGRAM test_unstruct_complete
2
3  USE xios
4  USE mod_wait
5  IMPLICIT NONE
6  INCLUDE "mpif.h"
7  INTEGER :: mpi_rank
8  INTEGER :: mpi_size
9  INTEGER :: ierr
10
11  CHARACTER(len=*),PARAMETER :: id="client"
12  INTEGER :: comm
13  TYPE(xios_duration) :: dtime
14  TYPE(xios_context) :: ctx_hdl
15  INTEGER, PARAMETER :: nlon=60
16  INTEGER, PARAMETER :: nlat=30
17  INTEGER,PARAMETER :: ni_glo=100
18  INTEGER,PARAMETER :: nj_glo=100
19  INTEGER,PARAMETER :: llm=5
20  DOUBLE PRECISION  :: lval(llm)=1
21  TYPE(xios_field) :: field_hdl
22  TYPE(xios_fieldgroup) :: fieldgroup_hdl
23  TYPE(xios_file) :: file_hdl
24  LOGICAL :: ok
25
26  DOUBLE PRECISION,ALLOCATABLE :: lon_glo(:),lat_glo(:)
27  DOUBLE PRECISION,ALLOCATABLE :: bounds_lon_glo(:,:),bounds_lat_glo(:,:)
28  DOUBLE PRECISION,ALLOCATABLE :: field_A_glo(:,:)
29  INTEGER,ALLOCATABLE :: i_index_glo(:)
30  INTEGER,ALLOCATABLE :: i_index(:)
31  LOGICAL,ALLOCATABLE :: mask_glo(:),mask(:)
32  INTEGER,ALLOCATABLE :: n_local(:),local_neighbor(:,:)
33  DOUBLE PRECISION,ALLOCATABLE :: lon(:),lat(:),field_A_srf(:,:), lonvalue(:) ;
34  DOUBLE PRECISION,ALLOCATABLE :: bounds_lon(:,:),bounds_lat(:,:) ;
35  INTEGER :: ni,ibegin,iend,nj,jbegin,jend
36  INTEGER :: i,j,l,ts,n, nbMax
37  INTEGER :: ncell_glo,ncell,ind
38  REAL :: ilon,ilat
39  DOUBLE PRECISION, PARAMETER :: Pi=3.14159265359
40  INTEGER :: list_ind(nlon,nlat)
41  INTEGER :: rank,j1,j2,np,ncell_x
42  INTEGER :: data_n_index
43  INTEGER,ALLOCATABLE :: data_i_index(:)
44  DOUBLE PRECISION,ALLOCATABLE :: field_A_compressed(:,:)
45
46  CALL MPI_INIT(ierr)
47  CALL init_wait
48
49  CALL xios_initialize(id,return_comm=comm)
50  CALL MPI_COMM_RANK(comm,mpi_rank,ierr)
51  CALL MPI_COMM_SIZE(comm,mpi_size,ierr)
52
53 
54
55  ncell_glo=0
56  DO j=1,nlat
57    n =  NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon)
58    IF (n<8) n=8
59    ncell_glo=ncell_glo+n
60  ENDDO
61
62  ALLOCATE(lon_glo(ncell_glo))
63  ALLOCATE(lat_glo(ncell_glo))
64  ALLOCATE(bounds_lon_glo(4,ncell_glo))
65  ALLOCATE(bounds_lat_glo(4,ncell_glo))
66  ALLOCATE(i_index_glo(ncell_glo))
67  ALLOCATE(field_A_glo(ncell_glo,llm))
68  ALLOCATE(mask_glo(ncell_glo))
69
70  ind=0
71  DO j=1,nlat
72    n = NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon)
73    if (j==1) PRINT*,"--- ",n
74    if (j==nlat) PRINT*,"--- ",n
75    IF (n<8) n=8
76
77    DO i=1,n
78      ind=ind+1
79      list_ind(i,j)=ind
80      ilon=i-0.5
81      ilat=j-0.5
82
83      lat_glo(ind)= 90-(ilat*180./nlat)
84      lon_glo(ind)= (ilon*360./n)
85
86
87      bounds_lat_glo(1,ind)= 90-((ilat-0.5)*180./nlat)
88      bounds_lon_glo(1,ind)=((ilon-0.5)*360./n)
89
90      bounds_lat_glo(2,ind)= 90-((ilat-0.5)*180./nlat)
91      bounds_lon_glo(2,ind)=((ilon+0.5)*360./n)
92
93      bounds_lat_glo(3,ind)= 90-((ilat+0.5)*180./nlat)
94      bounds_lon_glo(3,ind)=((ilon+0.5)*360./n)
95
96      bounds_lat_glo(4,ind)= 90-((ilat+0.5)*180./nlat)
97      bounds_lon_glo(4,ind)=((ilon-0.5)*360./n)
98
99    ENDDO
100  ENDDO
101
102!  mpi_size=32
103  rank=(mpi_size-1)/2
104  ncell_x=sqrt(ncell_glo*1./mpi_size)
105
106  j1=nlat/2
107  DO WHILE(rank>=0)
108    j2=MAX(j1-ncell_x+1,1)
109    j=(j1+j2)/2
110    n=NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon)
111    np = MIN(n/ncell_x,rank+1) ;
112    if (j2==1) np=rank+1
113
114    PRINT *,"domain ",j2,j1,rank,np ;
115    DO j=j2,j1
116      n=NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon)
117      IF (n<8) n=8
118      DO i=1,n
119        ind=list_ind(i,j)
120        IF ( (i-1) < MOD(n,np)*(n/np+1)) THEN
121          i_index_glo(ind) = rank - (i-1)/(n/np+1)
122        ELSE
123          i_index_glo(ind) = rank-(MOD(n,np)+ (i-1-MOD(n,np)*(n/np+1))/(n/np))
124        ENDIF
125      ENDDO
126    ENDDO
127    rank=rank-np
128    j1=j2-1
129  ENDDO
130
131  rank=(mpi_size-1)/2+1
132  ncell_x=sqrt(ncell_glo*1./mpi_size)
133
134  j1=nlat/2+1
135  DO WHILE(rank<=mpi_size-1)
136    j2=MIN(j1+ncell_x-1,nlat)
137    j=(j1+j2)/2
138    n=NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon)
139    np = MIN(n/ncell_x,mpi_size-rank) ;
140    if (j2==nlat) np=mpi_size-rank
141
142    PRINT *,"domain ",j2,j1,rank,np ;
143    DO j=j1,j2
144      n=NINT(COS(Pi/2-(j-0.5)*PI/nlat)*nlon)
145      IF (n<8) n=8
146      DO i=1,n
147        ind=list_ind(i,j)
148        IF ( (i-1) < MOD(n,np)*(n/np+1)) THEN
149          i_index_glo(ind) = rank + (i-1)/(n/np+1)
150        ELSE
151          i_index_glo(ind) = rank+(MOD(n,np)+ (i-1-MOD(n,np)*(n/np+1))/(n/np))
152        ENDIF
153      ENDDO
154    ENDDO
155    rank=rank+np
156    j1=j2+1
157  ENDDO
158
159  ncell=0
160  DO ind=1,ncell_glo
161    IF (i_index_glo(ind)==mpi_rank) ncell=ncell+1
162  ENDDO
163  ALLOCATE(i_index(ncell))
164  ALLOCATE(lon(ncell))
165  ALLOCATE(lat(ncell))
166  ALLOCATE(bounds_lon(4,ncell))
167  ALLOCATE(bounds_lat(4,ncell))
168  ALLOCATE(field_A_srf(ncell,llm))
169  ALLOCATE(mask(ncell))
170  ALLOCATE(n_local(ncell))
171  ncell=0
172  data_n_index=0
173  DO ind=1,ncell_glo
174    IF (i_index_glo(ind)==mpi_rank) THEN
175      ncell=ncell+1
176      i_index(ncell)=ind-1
177      lon(ncell)=lon_glo(ind)
178      lat(ncell)=lat_glo(ind)
179      bounds_lon(:,ncell)=bounds_lon_glo(:,ind)
180      bounds_lat(:,ncell)=bounds_lat_glo(:,ind)
181      field_A_srf(ncell,:)=i_index_glo(ind)
182      IF (MOD(ind,8)>=0 .AND. MOD(ind,8)<2) THEN
183        mask(ncell)=.FALSE.
184      ELSE
185        mask(ncell)=.TRUE.
186        data_n_index=data_n_index+1
187      ENDIF
188    ENDIF
189  ENDDO
190
191  ALLOCATE(field_A_compressed(data_n_index,llm))
192  ALLOCATE(data_i_index(data_n_index))
193  data_n_index=0
194  DO ind=1,ncell
195    IF (mask(ind)) THEN
196      data_n_index=data_n_index+1
197      data_i_index(data_n_index)=ind-1
198      field_A_compressed(data_n_index,:)=field_A_srf(ind,:)
199    ENDIF
200  ENDDO
201
202  CALL xios_context_initialize("surface",comm)
203  CALL xios_get_handle("surface",ctx_hdl)
204  CALL xios_set_current_context(ctx_hdl)
205
206  CALL xios_set_axis_attr("axis_srf",n_glo=llm ,value=lval) ;
207  CALL xios_set_domain_attr("domain_srf", ni_glo=ncell_glo, ni=ncell, ibegin=0, i_index=i_index)
208  CALL xios_set_domain_attr("domain_srf", type='unstructured', data_dim=1, data_ni=data_n_index, &
209                                          data_i_index=data_i_index)
210  CALL xios_set_domain_attr("domain_srf", lonvalue_1D=lon, latvalue_1D=lat)
211  CALL xios_set_domain_attr("domain_srf", nvertex=4, bounds_lon_1D=bounds_lon, bounds_lat_1D=bounds_lat)
212  CALL xios_set_compute_connectivity_domain_attr("compute", n_neighbor=n_local, local_neighbor=local_neighbor)
213
214
215
216  dtime%second=3600
217  CALL xios_set_timestep(dtime)
218
219  !CALL MSE_XIOS_GAUSS_GRID(NDGLG,NDLON,NPRGPNS ,NPRGPEW,MYSETA,MYSETB)
220   CALL MSE_XIOS_GAUSS_GRID(127  ,255  ,mpi_size,1      ,mpi_rank+1, 1)
221
222  CALL xios_close_context_definition()
223
224  CALL xios_get_compute_connectivity_domain_attr("compute", n_neighbor_max=nbMax)
225  ALLOCATE(local_neighbor(nbMax,ncell))
226  CALL xios_get_compute_connectivity_domain_attr("compute", n_neighbor=n_local, local_neighbor=local_neighbor)
227
228   DO ts=1,24*10
229     CALL xios_update_calendar(ts)
230     CALL xios_send_field("field_A_srf",field_A_compressed)
231     CALL xios_send_field("field_B_srf",field_A_compressed(:,1))
232    ENDDO
233
234    CALL xios_context_finalize()
235
236  DEALLOCATE(lon_glo)
237  DEALLOCATE(lat_glo)
238  DEALLOCATE(bounds_lon_glo)
239  DEALLOCATE(bounds_lat_glo)
240  DEALLOCATE(i_index_glo)
241  DEALLOCATE(field_A_glo)
242  DEALLOCATE(mask_glo)
243  DEALLOCATE(i_index)
244  DEALLOCATE(lon)
245  DEALLOCATE(lat)
246  DEALLOCATE(bounds_lon)
247  DEALLOCATE(bounds_lat)
248  DEALLOCATE(field_A_srf)
249  DEALLOCATE(mask)
250  DEALLOCATE(field_A_compressed)
251  DEALLOCATE(data_i_index)
252
253  CALL xios_finalize()
254  CALL MPI_COMM_FREE(comm, ierr)
255 
256  CALL MPI_FINALIZE(ierr)
257
258CONTAINS
259SUBROUTINE MSE_XIOS_GAUSS_GRID(NDGLG,NDLON,NPRGPNS, NPRGPEW,MYSETA, MYSETB)
260!!
261!!     PURPOSE : declare to XIOS a distribution for a rectilinear grid
262!!     --------
263!
264USE XIOS     , ONLY : XIOS_DOMAIN, XIOS_DOMAINGROUP,XIOS_GET_HANDLE, &
265                      XIOS_ADD_CHILD, XIOS_SET_DOMAIN_ATTR
266!
267!
268IMPLICIT NONE
269!
270INTEGER, INTENT(IN) :: NDGLG,NDLON,NPRGPNS, NPRGPEW,MYSETA, MYSETB
271!
272!
273!*       0.2   Declarations of local variables
274!              -------------------------------
275!
276CHARACTER(LEN=8), PARAMETER       :: YNAMGRID="complete"
277INTEGER                           :: NI,NJ,I,J,IOFF,JOFF
278REAL                   :: ZINCR
279DOUBLE PRECISION, ALLOCATABLE, DIMENSION(:)   :: ZLATI,ZLONG
280!
281TYPE(xios_domaingroup)            :: domaingroup_hdl
282TYPE(xios_domain)                 :: domain_hdl
283!
284! Basic XIOS declarations
285 CALL XIOS_GET_HANDLE("domain_definition",domaingroup_hdl)
286 CALL XIOS_ADD_CHILD(domaingroup_hdl,domain_hdl,YNAMGRID)
287 CALL XIOS_SET_DOMAIN_ATTR(YNAMGRID, type="rectilinear", data_dim=2)
288!
289! Compute domain size in longitude
290!
291IF (MOD(NDLON,NPRGPEW)==0) THEN
292   NI=NDLON/NPRGPEW
293   IOFF=(MYSETB-1)*NI
294ELSE
295   NI=NDLON/NPRGPEW+1
296   IOFF=(MYSETB-1)*NI
297   IF (MYSETB==NPRGPEW) NI=MOD(NDLON,NI)
298ENDIF
299!
300! Compute evenly spaced longitudes
301!
302ALLOCATE(ZLONG(NI))
303ZINCR=360./NDLON
304DO I=1,NI
305   ZLONG(I)=(IOFF+I)*ZINCR
306ENDDO
307!
308write(0,*) 'i=',IOFF+1,IOFF+NI
309CALL XIOS_SET_DOMAIN_ATTR(YNAMGRID, ni_glo=NDLON, ni=NI,ibegin=IOFF)
310 CALL XIOS_SET_DOMAIN_ATTR(YNAMGRID, lonvalue_1d=ZLONG(:))
311!
312! Compute domain size in latitude
313!
314IF (MOD(NDGLG,NPRGPNS)==0) THEN
315   NJ=NDGLG/NPRGPNS
316   JOFF=(MYSETA-1)*NJ
317ELSE
318   NJ=NDGLG/NPRGPNS+1
319   JOFF=(MYSETA-1)*NJ
320   IF (MYSETA==NPRGPNS) NJ=MOD(NDGLG,NJ)
321ENDIF
322!
323ALLOCATE(ZLATI(NJ))
324ZINCR=180./NDGLG
325DO J=1,NJ
326   ZLATI(J)=(JOFF+J)*ZINCR
327ENDDO
328!
329!write(0,*) 'j=',JOFF+1,JOFF+NJ ; call flush(0)
330 CALL XIOS_SET_DOMAIN_ATTR(YNAMGRID, nj_glo=NDGLG, nj=NJ, jbegin=JOFF)
331 CALL XIOS_SET_DOMAIN_ATTR(YNAMGRID,latvalue_1d=ZLATI(:)-90.)
332!
333 DEALLOCATE(ZLATI,ZLONG)!,ZLATIC,ZLONGC)
334END SUBROUTINE MSE_XIOS_GAUSS_GRID
335
336END PROGRAM test_unstruct_complete
337
338
339
340
341
Note: See TracBrowser for help on using the repository browser.