[1134] | 1 | PROGRAM test_omp |
---|
| 2 | |
---|
| 3 | USE xios |
---|
| 4 | USE mod_wait |
---|
[1642] | 5 | USE omp_lib |
---|
[1134] | 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 |
---|
[1544] | 23 | DOUBLE PRECISION :: lval(llm)=1, scalar = 5 |
---|
[1134] | 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) |
---|
[1544] | 31 | DOUBLE PRECISION,ALLOCATABLE :: lon(:,:),lat(:,:),field_A(:,:,:), lonvalue(:,:), axisValue(:), field_domain(:,:) |
---|
[1134] | 32 | INTEGER :: ni,ibegin,iend,nj,jbegin,jend |
---|
| 33 | INTEGER :: i,j,l,ts,n, provided |
---|
| 34 | |
---|
| 35 | !!! MPI Initialization |
---|
| 36 | CALL MPI_INIT_THREAD(3, provided, ierr) |
---|
[1642] | 37 | if(provided .LT. 3) then |
---|
[1134] | 38 | print*, "provided thread level = ", provided |
---|
| 39 | call MPI_Abort() |
---|
| 40 | endif |
---|
[1642] | 41 | !CALL VTINIT(ierr) |
---|
[1134] | 42 | CALL init_wait |
---|
| 43 | |
---|
| 44 | CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr) |
---|
| 45 | CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierr) |
---|
[1642] | 46 | if(rank < size-4) then |
---|
[1134] | 47 | |
---|
| 48 | |
---|
| 49 | CALL xios_initialize(id,return_comm=comm) |
---|
[1642] | 50 | print*, "comm = ", comm |
---|
[1134] | 51 | CALL MPI_COMM_RANK(comm,rank,ierr) |
---|
| 52 | CALL MPI_COMM_SIZE(comm,size,ierr) |
---|
| 53 | |
---|
| 54 | |
---|
| 55 | DO j=1,nj_glo |
---|
| 56 | DO i=1,ni_glo |
---|
| 57 | lon_glo(i,j)=(i-1)+(j-1)*ni_glo |
---|
| 58 | lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo |
---|
| 59 | DO l=1,llm |
---|
[1544] | 60 | field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo*100+10000*l |
---|
[1134] | 61 | ENDDO |
---|
| 62 | ENDDO |
---|
| 63 | ENDDO |
---|
| 64 | ni=ni_glo ; ibegin=0 |
---|
| 65 | |
---|
| 66 | jbegin=0 |
---|
| 67 | DO n=0,size-1 |
---|
| 68 | nj=nj_glo/size |
---|
| 69 | IF (n<MOD(nj_glo,size)) nj=nj+1 |
---|
| 70 | IF (n==rank) exit |
---|
| 71 | jbegin=jbegin+nj |
---|
| 72 | ENDDO |
---|
| 73 | |
---|
| 74 | iend=ibegin+ni-1 ; jend=jbegin+nj-1 |
---|
| 75 | |
---|
[1544] | 76 | !ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(0:ni+1,-1:nj+2,llm),lonvalue(ni,nj)) |
---|
| 77 | !lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1) |
---|
| 78 | !lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1) |
---|
| 79 | !field_A(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:) |
---|
| 80 | |
---|
| 81 | ALLOCATE(lon(ni,nj),lat(ni,nj),field_A(0:ni+1,-1:nj+2,llm),lonvalue(ni,nj), axisValue(nj_glo), field_domain(0:ni+1,-1:nj+2)) |
---|
[1134] | 82 | lon(:,:)=lon_glo(ibegin+1:iend+1,jbegin+1:jend+1) |
---|
| 83 | lat(:,:)=lat_glo(ibegin+1:iend+1,jbegin+1:jend+1) |
---|
| 84 | field_A(1:ni,1:nj,:)=field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,:) |
---|
[1544] | 85 | field_domain(1:ni,1:nj) = field_A_glo(ibegin+1:iend+1,jbegin+1:jend+1,1) |
---|
| 86 | axisValue(1:nj_glo)=field_A_glo(1,1:nj_glo,1); |
---|
| 87 | |
---|
[1134] | 88 | |
---|
| 89 | |
---|
| 90 | CALL xios_context_initialize("test",comm) |
---|
| 91 | CALL xios_get_handle("test",ctx_hdl) |
---|
| 92 | CALL xios_set_current_context(ctx_hdl) |
---|
| 93 | |
---|
| 94 | CALL xios_get_calendar_type(calendar_type) |
---|
[1544] | 95 | PRINT *, "calendar_type = ", calendar_type |
---|
[1134] | 96 | |
---|
| 97 | CALL xios_set_axis_attr("axis_A",n_glo=llm ,value=lval) ; |
---|
| 98 | 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') |
---|
| 99 | CALL xios_set_domain_attr("domain_A",data_dim=2, data_ibegin=-1, data_ni=ni+2, data_jbegin=-2, data_nj=nj+4) |
---|
| 100 | CALL xios_set_domain_attr("domain_A",lonvalue_2D=lon,latvalue_2D=lat) |
---|
| 101 | CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.) |
---|
| 102 | !print*, "test block OK", rank, size |
---|
| 103 | |
---|
[1544] | 104 | !CALL xios_get_handle("field_definition",fieldgroup_hdl) |
---|
| 105 | !CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B") |
---|
| 106 | !CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B") |
---|
[1134] | 107 | |
---|
[1544] | 108 | !CALL xios_get_handle("output",file_hdl) |
---|
| 109 | !CALL xios_add_child(file_hdl,field_hdl) |
---|
| 110 | !CALL xios_set_attr(field_hdl,field_ref="field_A_zoom",name="field_C") |
---|
[1134] | 111 | |
---|
| 112 | dtime%second = 3600 |
---|
| 113 | CALL xios_set_timestep(dtime) |
---|
| 114 | !print*, "xios_set_timestep OK", rank, size |
---|
| 115 | |
---|
| 116 | ! The calendar is created as soon as the calendar type is defined. This way |
---|
| 117 | ! calendar operations can be used before the context definition is closed |
---|
| 118 | CALL xios_get_time_origin(date) |
---|
[1544] | 119 | PRINT *, "--> year length = ", xios_get_year_length_in_seconds(date%year) |
---|
| 120 | PRINT *, "--> day length = ", xios_get_day_length_in_seconds() |
---|
[1134] | 121 | CALL xios_date_convert_to_string(date, date_str) |
---|
[1544] | 122 | PRINT *, "time_origin = ", date_str |
---|
| 123 | PRINT *, "xios_date_get_second_of_year(time_origin) = ", xios_date_get_second_of_year(date) |
---|
| 124 | PRINT *, "xios_date_get_day_of_year(time_origin) = ", xios_date_get_day_of_year(date) |
---|
| 125 | PRINT *, "xios_date_get_fraction_of_year(time_origin) = ", xios_date_get_fraction_of_year(date) |
---|
| 126 | PRINT *, "xios_date_get_second_of_day(time_origin) = ", xios_date_get_second_of_day(date) |
---|
| 127 | PRINT *, "xios_date_get_fraction_of_day(time_origin) = ", xios_date_get_fraction_of_day(date) |
---|
[1134] | 128 | dtime%timestep = 1 |
---|
| 129 | dtime = 0.5 * dtime |
---|
| 130 | CALL xios_duration_convert_to_string(dtime, dtime_str) |
---|
[1544] | 131 | PRINT *, "duration = ", dtime_str |
---|
[1134] | 132 | date = date + 3 * (dtime + dtime) |
---|
| 133 | CALL xios_date_convert_to_string(date, date_str) |
---|
[1544] | 134 | PRINT *, "date = time_origin + 3 * (duration + duration) = ", date_str |
---|
| 135 | PRINT *, "xios_date_convert_to_seconds(date) = ", xios_date_convert_to_seconds(date) |
---|
| 136 | PRINT *, "xios_date_convert_to_seconds(date - 2.5h) = ", xios_date_convert_to_seconds(date - 2.5 * xios_hour) |
---|
[1134] | 137 | |
---|
| 138 | ni=0 ; lonvalue(:,:)=0; |
---|
| 139 | CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_2D=lonvalue) |
---|
[1642] | 140 | !print *,"ni",ni |
---|
| 141 | !print *,"lonvalue",lonvalue; |
---|
[1134] | 142 | |
---|
| 143 | CALL xios_is_defined_field_attr("field_A",enabled=ok) |
---|
[1544] | 144 | PRINT *,"field_A : attribute enabled is defined ? ",ok |
---|
[1134] | 145 | CALL xios_close_context_definition() |
---|
| 146 | |
---|
| 147 | PRINT*,"field field_A is active ? ",xios_field_is_active("field_A") |
---|
| 148 | |
---|
[1544] | 149 | DO ts=1,4 |
---|
[1134] | 150 | CALL xios_update_calendar(ts) |
---|
| 151 | CALL xios_send_field("field_A",field_A) |
---|
[1642] | 152 | !CALL xios_send_field("field_Axis",axisValue) |
---|
[1544] | 153 | ! CALL xios_send_field("field_Axis",lval) |
---|
[1642] | 154 | !CALL xios_send_field("field_Domain",field_domain) |
---|
| 155 | !CALL xios_send_field("field_Scalar",scalar) |
---|
[1134] | 156 | CALL wait_us(5000) |
---|
| 157 | ENDDO |
---|
| 158 | |
---|
| 159 | CALL xios_context_finalize() |
---|
| 160 | !print*, "xios_context_finalize OK", rank, size |
---|
| 161 | |
---|
| 162 | CALL xios_finalize() |
---|
[1642] | 163 | print*, "xios_finalize OK", rank, size |
---|
[1134] | 164 | |
---|
[1544] | 165 | DEALLOCATE(lon, lat, field_A, lonvalue, axisValue, field_domain) |
---|
[1642] | 166 | print*, "deallocate OK", rank, size |
---|
[1134] | 167 | CALL MPI_COMM_FREE(comm, ierr) |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | |
---|
| 174 | else |
---|
| 175 | |
---|
| 176 | CALL xios_init_server |
---|
[1642] | 177 | |
---|
| 178 | print*, "server ready to end ", rank, size |
---|
[1134] | 179 | |
---|
| 180 | endif |
---|
| 181 | |
---|
[1642] | 182 | CALL MPI_BARRIER(MPI_COMM_WORLD, ierr) |
---|
| 183 | CALL MPI_BARRIER(MPI_COMM_WORLD, ierr) |
---|
| 184 | CALL MPI_COMM_RANK(MPI_COMM_WORLD, rank, ierr) |
---|
| 185 | CALL MPI_COMM_SIZE(MPI_COMM_WORLD, size, ierr) |
---|
| 186 | print*, "before MPI_Finalize : rank = ", rank, size |
---|
[1134] | 187 | CALL MPI_FINALIZE(ierr) |
---|
[1642] | 188 | !CALL VTFINI(ierr) |
---|
| 189 | print*, "after MPI_Finalize : rank = ", rank, size |
---|
[1134] | 190 | |
---|
| 191 | END PROGRAM test_omp |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | |
---|
| 195 | |
---|
| 196 | |
---|