[1073] | 1 | PROGRAM 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 | |
---|
[1081] | 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 |
---|
[1073] | 42 | |
---|
[1081] | 43 | CALL init_wait |
---|
[1073] | 44 | |
---|
[1081] | 45 | CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr) |
---|
| 46 | if(rank < 2) then |
---|
| 47 | |
---|
| 48 | !$omp parallel default(private) |
---|
[1073] | 49 | |
---|
[1081] | 50 | CALL xios_initialize(id,return_comm=comm) |
---|
[1073] | 51 | |
---|
[1081] | 52 | CALL MPI_COMM_RANK(comm,rank,ierr) |
---|
| 53 | CALL MPI_COMM_SIZE(comm,size,ierr) |
---|
[1073] | 54 | |
---|
[1081] | 55 | size = size*omp_get_num_threads() |
---|
| 56 | rank = rank*omp_get_num_threads() + omp_get_thread_num() |
---|
[1073] | 57 | |
---|
[1081] | 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 |
---|
[1073] | 65 | ENDDO |
---|
| 66 | ENDDO |
---|
[1081] | 67 | ni=ni_glo ; ibegin=0 |
---|
[1073] | 68 | |
---|
[1081] | 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 |
---|
[1073] | 76 | |
---|
[1081] | 77 | iend=ibegin+ni-1 ; jend=jbegin+nj-1 |
---|
[1073] | 78 | |
---|
[1081] | 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,:) |
---|
[1073] | 83 | |
---|
[1081] | 84 | print*, "xios init OK", rank, size |
---|
[1073] | 85 | |
---|
[1085] | 86 | CALL xios_context_initialize("test",comm) |
---|
[1080] | 87 | |
---|
[1085] | 88 | print*, "xios_context_initialize OK", rank, size |
---|
[1081] | 89 | |
---|
[1101] | 90 | CALL xios_get_handle("test",ctx_hdl) |
---|
| 91 | CALL xios_set_current_context(ctx_hdl) |
---|
[1087] | 92 | |
---|
| 93 | |
---|
[1101] | 94 | CALL xios_get_calendar_type(calendar_type) |
---|
| 95 | print*, "xios_get_calendar_type OK", rank, size |
---|
[1087] | 96 | |
---|
[1101] | 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.) |
---|
[1102] | 102 | ! print*, "test block OK", rank, size |
---|
[1087] | 103 | |
---|
[1102] | 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") |
---|
[1101] | 107 | |
---|
[1102] | 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",name="field_C") |
---|
| 111 | |
---|
[1101] | 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) |
---|
| 119 | PRINT *, "--> year length = ", xios_get_year_length_in_seconds(date%year) |
---|
| 120 | PRINT *, "--> day length = ", xios_get_day_length_in_seconds() |
---|
| 121 | CALL xios_date_convert_to_string(date, date_str) |
---|
| 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) |
---|
| 128 | dtime%timestep = 1 |
---|
| 129 | dtime = 0.5 * dtime |
---|
| 130 | CALL xios_duration_convert_to_string(dtime, dtime_str) |
---|
| 131 | PRINT *, "duration = ", dtime_str |
---|
| 132 | date = date + 3 * (dtime + dtime) |
---|
| 133 | CALL xios_date_convert_to_string(date, date_str) |
---|
| 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) |
---|
| 137 | |
---|
| 138 | ni=0 ; lonvalue(:,:)=0; |
---|
| 139 | CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue_2D=lonvalue) |
---|
| 140 | print *,"ni",ni |
---|
| 141 | !print *,"lonvalue",lonvalue; |
---|
| 142 | |
---|
| 143 | CALL xios_is_defined_field_attr("field_A",enabled=ok) |
---|
| 144 | PRINT *,"field_A : attribute enabled is defined ? ",ok |
---|
| 145 | |
---|
| 146 | CALL xios_close_context_definition() |
---|
| 147 | print*, "xios_close_context_definition OK" |
---|
| 148 | |
---|
| 149 | PRINT*,"field field_A is active ? ",xios_field_is_active("field_A") |
---|
| 150 | |
---|
| 151 | DO ts=1,6 |
---|
| 152 | CALL xios_update_calendar(ts) |
---|
| 153 | CALL xios_send_field("field_A",field_A) |
---|
| 154 | CALL wait_us(5000) |
---|
| 155 | ENDDO |
---|
| 156 | |
---|
[1085] | 157 | CALL xios_context_finalize() |
---|
| 158 | print*, "xios_context_finalize OK", rank, size |
---|
[1081] | 159 | |
---|
[1102] | 160 | !$omp master |
---|
[1094] | 161 | !call MPI_Barrier(comm) |
---|
[1087] | 162 | CALL MPI_COMM_FREE(comm, ierr) |
---|
| 163 | !$omp end master |
---|
[1081] | 164 | |
---|
[1085] | 165 | !$omp barrier |
---|
[1081] | 166 | |
---|
[1085] | 167 | print*, "MPI_COMM_FREE OK", rank, size |
---|
[1081] | 168 | |
---|
[1085] | 169 | CALL xios_finalize() |
---|
| 170 | print*, "xios finalize OK", rank, size |
---|
[1073] | 171 | |
---|
[1101] | 172 | DEALLOCATE(lon, lat, field_A, lonvalue) |
---|
[1074] | 173 | |
---|
[1101] | 174 | |
---|
[1073] | 175 | !$omp end parallel |
---|
[1074] | 176 | |
---|
| 177 | |
---|
[1080] | 178 | else |
---|
[1073] | 179 | |
---|
[1080] | 180 | CALL xios_init_server |
---|
| 181 | print *, "Server : xios_finalize " |
---|
[1073] | 182 | |
---|
[1080] | 183 | endif |
---|
[1073] | 184 | |
---|
| 185 | |
---|
| 186 | CALL MPI_FINALIZE(ierr) |
---|
| 187 | |
---|
| 188 | END PROGRAM test_omp |
---|
| 189 | |
---|
| 190 | |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | |
---|