source: XIOS/dev/branch_yushan/src/test/test_omp.f90 @ 1081

Last change on this file since 1081 was 1081, checked in by yushan, 5 years ago

save current modifications

File size: 8.6 KB
Line 
1PROGRAM test_omp
2
3  USE xios
4  USE mod_wait
5  use omp_lib
6  IMPLICIT NONE
7  INCLUDE "mpif.h"
8  INTEGER :: rank
9  INTEGER :: size
10  INTEGER :: ierr
11
12  CHARACTER(len=*),PARAMETER :: id="client"
13  INTEGER :: comm
14  TYPE(xios_duration) :: dtime
15  CHARACTER(len=20) :: dtime_str
16  TYPE(xios_date) :: date
17  CHARACTER(len=20) :: date_str
18  CHARACTER(len=15) :: calendar_type
19  TYPE(xios_context) :: ctx_hdl
20  INTEGER,PARAMETER :: ni_glo=100
21  INTEGER,PARAMETER :: nj_glo=100
22  INTEGER,PARAMETER :: llm=5
23  DOUBLE PRECISION  :: lval(llm)=1
24  TYPE(xios_field) :: field_hdl
25  TYPE(xios_fieldgroup) :: fieldgroup_hdl
26  TYPE(xios_file) :: file_hdl
27  LOGICAL :: ok
28
29  DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo
30  DOUBLE PRECISION :: field_A_glo(ni_glo,nj_glo,llm)
31  DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A(:,:,:), lonvalue(:,:) ;
32  INTEGER :: ni,ibegin,iend,nj,jbegin,jend
33  INTEGER :: i,j,l,ts,n, provided
34
35!!! MPI Initialization   
36
37    CALL MPI_INIT_THREAD(3, provided, ierr)
38    if(provided .NE. 3) then
39      print*, "provided thread level = ", provided
40      call MPI_Abort()
41    endif
42
43    CALL init_wait
44
45    CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
46    if(rank < 2) then
47
48    !$omp parallel default(private)
49 
50    CALL xios_initialize(id,return_comm=comm)
51 
52    CALL MPI_COMM_RANK(comm,rank,ierr)
53    CALL MPI_COMM_SIZE(comm,size,ierr)
54
55    size = size*omp_get_num_threads()
56    rank = rank*omp_get_num_threads() + omp_get_thread_num()
57
58    DO j=1,nj_glo
59      DO i=1,ni_glo
60        lon_glo(i,j)=(i-1)+(j-1)*ni_glo
61        lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo
62        DO l=1,llm
63          field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo+10000*l
64        ENDDO
65      ENDDO
66    ENDDO
67    ni=ni_glo ; ibegin=0
68
69    jbegin=0
70    DO n=0,size-1
71      nj=nj_glo/size
72      IF (n<MOD(nj_glo,size)) nj=nj+1
73      IF (n==rank) exit
74      jbegin=jbegin+nj
75    ENDDO
76
77    iend=ibegin+ni-1 ; jend=jbegin+nj-1
78
79    ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(0:ni+1,-1:nj+2,llm),lonvalue(ni,nj))
80    lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1)
81    lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1)
82    field_A(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:)
83
84    print*, "xios init OK", rank, size
85
86      CALL xios_context_initialize("test",comm)
87      print*, "xios_context init OK", rank, size 
88
89!      CALL xios_context_finalize()
90!      print*, "xios_context finalize OK", rank, size
91
92    CALL xios_finalize()
93    print*, "xios finalize OK", rank, size
94
95
96   
97    !$omp barrier
98    !call MPI_Barrier(MPI_COMM_WORLD)
99    !$omp barrier
100
101    call MPI_Abort()
102
103   
104   
105    CALL xios_get_handle("test",ctx_hdl)
106    print*, "xios_get_handle OK", rank, size 
107   
108    CALL xios_set_current_context(ctx_hdl)
109    print*, "xios_set_current_context OK", rank, size 
110 
111    CALL xios_get_calendar_type(calendar_type)
112    print*, "xios_get_calendar_type OK", rank, size 
113   
114   
115    CALL xios_set_axis_attr("axis_A",n_glo=llm ,value=lval) ;
116    CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj,type='curvilinear')
117    CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
118    CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat)
119    CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
120
121    CALL xios_get_handle("field_definition",fieldgroup_hdl)
122    CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
123    CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
124
125    CALL xios_get_handle("output",file_hdl)
126    CALL xios_add_child(file_hdl,field_hdl)
127    CALL xios_set_attr(field_hdl,field_ref="field_A_zoom",name="field_C")
128 
129    dtime%second = 3600
130    CALL xios_set_timestep(dtime)
131    print*, "xios_set_timestep OK", rank, size 
132
133    CALL xios_get_time_origin(date)
134   
135    PRINT *, "--> year length = ", xios_get_year_length_in_seconds(date%year)
136    PRINT *, "--> day length = ", xios_get_day_length_in_seconds()
137    CALL xios_date_convert_to_string(date, date_str)
138    PRINT *, "time_origin = ", date_str
139    PRINT *, "xios_date_get_second_of_year(time_origin) = ", xios_date_get_second_of_year(date)
140    PRINT *, "xios_date_get_day_of_year(time_origin) = ", xios_date_get_day_of_year(date)
141    PRINT *, "xios_date_get_fraction_of_year(time_origin) = ", xios_date_get_fraction_of_year(date)
142    PRINT *, "xios_date_get_second_of_day(time_origin) = ", xios_date_get_second_of_day(date)
143    PRINT *, "xios_date_get_fraction_of_day(time_origin) = ", xios_date_get_fraction_of_day(date)
144    dtime%timestep = 1
145    dtime = 0.5 * dtime
146    CALL xios_duration_convert_to_string(dtime, dtime_str)
147    PRINT *, "duration = ", dtime_str
148    date = date + 3 * (dtime + dtime)
149    CALL xios_date_convert_to_string(date, date_str)
150    PRINT *, "date = time_origin + 3 * (duration + duration) = ", date_str
151    PRINT *, "xios_date_convert_to_seconds(date) = ", xios_date_convert_to_seconds(date)
152    PRINT *, "xios_date_convert_to_seconds(date - 2.5h) = ", xios_date_convert_to_seconds(date - 2.5 * xios_hour)
153
154    ni=0 ; lonvalue(:,:)=0;
155    CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_2D=lonvalue)
156    print *,"ni",ni
157
158    CALL xios_is_defined_field_attr("field_A",enabled=ok)
159    PRINT *,"field_A : attribute enabled is defined ? ",ok
160
161
162!   CALL xios_close_context_definition()
163 
164!   print*, "xios_close_context_definition OK", rank, size
165
166
167
168  !$omp end parallel
169
170  call MPI_Abort(ierr)
171
172 
173  CALL xios_context_initialize("test",comm)
174
175  CALL xios_get_handle("test",ctx_hdl)
176  CALL xios_set_current_context(ctx_hdl)
177 
178 
179  CALL xios_get_calendar_type(calendar_type)
180
181  CALL xios_set_axis_attr("axis_A",n_glo=llm ,value=lval) ;
182  CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, ni=ni,jbegin=jbegin,nj=nj,type='curvilinear')
183  CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4)
184  CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat)
185  CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
186
187  CALL xios_get_handle("field_definition",fieldgroup_hdl)
188  CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
189  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
190
191  CALL xios_get_handle("output",file_hdl)
192  CALL xios_add_child(file_hdl,field_hdl)
193  CALL xios_set_attr(field_hdl,field_ref="field_A_zoom",name="field_C")
194 
195  dtime%second = 3600
196  CALL xios_set_timestep(dtime)
197
198  ! The calendar is created as soon as the calendar type is defined. This way
199  ! calendar operations can be used before the context definition is closed
200  CALL xios_get_time_origin(date)
201  PRINT *, "--> year length = ", xios_get_year_length_in_seconds(date%year)
202  PRINT *, "--> day length = ", xios_get_day_length_in_seconds()
203  CALL xios_date_convert_to_string(date, date_str)
204  PRINT *, "time_origin = ", date_str
205  PRINT *, "xios_date_get_second_of_year(time_origin) = ", xios_date_get_second_of_year(date)
206  PRINT *, "xios_date_get_day_of_year(time_origin) = ", xios_date_get_day_of_year(date)
207  PRINT *, "xios_date_get_fraction_of_year(time_origin) = ", xios_date_get_fraction_of_year(date)
208  PRINT *, "xios_date_get_second_of_day(time_origin) = ", xios_date_get_second_of_day(date)
209  PRINT *, "xios_date_get_fraction_of_day(time_origin) = ", xios_date_get_fraction_of_day(date)
210  dtime%timestep = 1
211  dtime = 0.5 * dtime
212  CALL xios_duration_convert_to_string(dtime, dtime_str)
213  PRINT *, "duration = ", dtime_str
214  date = date + 3 * (dtime + dtime)
215  CALL xios_date_convert_to_string(date, date_str)
216  PRINT *, "date = time_origin + 3 * (duration + duration) = ", date_str
217  PRINT *, "xios_date_convert_to_seconds(date) = ", xios_date_convert_to_seconds(date)
218  PRINT *, "xios_date_convert_to_seconds(date - 2.5h) = ", xios_date_convert_to_seconds(date - 2.5 * xios_hour)
219
220  ni=0 ; lonvalue(:,:)=0;
221  CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_2D=lonvalue)
222  print *,"ni",ni
223  !print *,"lonvalue",lonvalue;
224
225  CALL xios_is_defined_field_attr("field_A",enabled=ok)
226  PRINT *,"field_A : attribute enabled is defined ? ",ok
227 
228  CALL xios_close_context_definition()
229  print*, "xios_close_context_definition OK" 
230
231  PRINT*,"field field_A is active ? ",xios_field_is_active("field_A")
232
233
234  call MPI_Barrier(comm, ierr)
235
236  !DO ts=1,24*10
237  DO ts=1,6
238    CALL xios_update_calendar(ts)
239    CALL xios_send_field("field_A",field_A)
240    CALL wait_us(5000)
241  ENDDO
242 
243
244  CALL xios_context_finalize()
245
246  DEALLOCATE(lon, lat, field_A, lonvalue)
247
248  CALL MPI_COMM_FREE(comm, ierr)
249
250  CALL xios_finalize()
251  print *, "Client : xios_finalize "
252
253    else
254
255    CALL xios_init_server
256    print *, "Server : xios_finalize "
257 
258    endif
259   
260
261  CALL MPI_FINALIZE(ierr)
262
263END PROGRAM test_omp
264
265
266
267
268
Note: See TracBrowser for help on using the repository browser.