source: XIOS/trunk/src/test/test_cs.f90 @ 930

Last change on this file since 930 was 655, checked in by rlacroix, 9 years ago

Properly release all MPI resources.

  • 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: 4.0 KB
RevLine 
[300]1PROGRAM test_cs
2IMPLICIT NONE
3  INCLUDE "mpif.h"
4  INTEGER :: rank
5  INTEGER :: size
6  INTEGER :: ierr
[549]7
[300]8  CALL MPI_INIT(ierr)
9  CALL MPI_COMM_RANK(MPI_COMM_WORLD,rank,ierr)
10  CALL MPI_COMM_SIZE(MPI_COMM_WORLD,size,ierr)
[549]11
[384]12  IF (rank<11) THEN
13   CALL client("client",rank,11)
[549]14  ELSE
[300]15    CALL server
16  ENDIF
[549]17
18
[300]19  CALL MPI_FINALIZE(ierr)
[549]20
[300]21END PROGRAM test_cs
22
23  SUBROUTINE client(id,rank,size)
24  USE xios
[349]25  USE mod_wait
[300]26  IMPLICIT NONE
27  INCLUDE 'mpif.h'
28  CHARACTER(len=*) :: id
29  INTEGER :: rank
30  INTEGER :: size
31  INTEGER :: comm
[537]32  TYPE(xios_duration) :: dtime
[300]33  TYPE(xios_context) :: ctx_hdl
[549]34  INTEGER,PARAMETER :: ni_glo=100
35  INTEGER,PARAMETER :: nj_glo=100
36  INTEGER,PARAMETER :: llm=3
[351]37  DOUBLE PRECISION  :: lval(llm)=(/1.0,2.0,3.0/)
[300]38  TYPE(xios_field) :: field_hdl
39  TYPE(xios_fieldgroup) :: fieldgroup_hdl
40  TYPE(xios_file) :: file_hdl
[549]41
42
[351]43  DOUBLE PRECISION,DIMENSION(ni_glo,nj_glo) :: lon_glo,lat_glo
44  DOUBLE PRECISION :: field_A_glo(ni_glo,nj_glo,llm)
[384]45  DOUBLE PRECISION,ALLOCATABLE :: lon(:),lat(:),field_A(:,:), lonvalue(:) ;
46  LOGICAL,ALLOCATABLE :: mask(:,:)
47  INTEGER :: ni,ibegin,iend,nj,jbegin,jend,data_ibegin,data_ni
48  INTEGER :: i,j,k,l,ts,n,nij_begin
[549]49
50
[349]51  CALL init_wait
[549]52
53
[300]54  DO j=1,nj_glo
55    DO i=1,ni_glo
56      lon_glo(i,j)=(i-1)+(j-1)*ni_glo
57      lat_glo(i,j)=1000+(i-1)+(j-1)*ni_glo
[351]58      DO l=1,llm
59        field_A_glo(i,j,l)=(i-1)+(j-1)*ni_glo+10000*l
60      ENDDO
[300]61    ENDDO
62  ENDDO
63  ni=ni_glo ; ibegin=1
64
[549]65
[384]66  nij_begin=1
[300]67  DO n=0,size-1
[384]68    data_ni=(ni_glo*nj_glo)/size
69    IF (n < MOD (ni_glo*nj_glo,size)) data_ni=data_ni+1
70    IF (n==rank) THEN
71      ibegin=1 ; iend=ni_glo ; ni=iend-ibegin+1
[549]72      jbegin=(nij_begin-1)/ni_glo +1
[384]73      jend=MOD(nij_begin-1 + data_ni-1,ni_glo) +1
74      nj = jend-jbegin+1
75      data_ibegin=MOD(nij_begin-1,ni_glo)
76      exit
77    ELSE
78      nij_begin=nij_begin+data_ni
79    ENDIF
[300]80  ENDDO
81
[549]82
[384]83  ALLOCATE(lon(ni),lat(nj),field_A(data_ni,llm),lonvalue(ni*nj))
84  ALLOCATE(mask(ni,nj))
85  lon(:)=lon_glo(ibegin:iend,1)
86  lat(:)=lat_glo(1,jbegin:jend)
87
88  DO k=1,data_ni
89    n=k-1+(jbegin-1)*ni_glo+data_ibegin
90    i=MOD(n,ni_glo)+1
91    j=n/ni_glo+1
92    field_A(k,:)=field_A_glo(i,j,:)
93  ENDDO
[549]94
[384]95  mask(:,:)=.TRUE.
96  mask(1:ni,6)=.TRUE.
[300]97
[549]98
[327]99  CALL xios_initialize(id,return_comm=comm)
[300]100
101  CALL xios_context_initialize("test",comm)
102  CALL xios_get_handle("test",ctx_hdl)
103  CALL xios_set_current_context(ctx_hdl)
[549]104
105! CALL xios_define_calendar(type="Gregorian")
106! CALL xios_set_start_date(start_date=xios_date(2000, 01, 01, 00, 00, 00))
[351]107  CALL xios_set_axis_attr("axis_A",size=llm ,value=lval) ;
[384]108  CALL xios_set_domain_attr("domain_A",ni_glo=ni_glo, nj_glo=nj_glo, ibegin=ibegin, iend=iend,jbegin=jbegin,jend=jend)
[549]109! CALL xios_set_domain_attr("domain_A",zoom_ni=10,zoom_ibegin=5,zoom_nj=nj_glo,zoom_jbegin=1)
[384]110  CALL xios_set_domain_attr("domain_A",data_dim=1, data_ibegin=data_ibegin, data_ni=data_ni)
111  CALL xios_set_domain_attr("domain_A",lonvalue=lon,latvalue=lat)
[549]112! CALL xios_set_domain_attr("domain_A",mask=mask)
[300]113  CALL xios_set_fieldgroup_attr("field_definition",enabled=.TRUE.)
[549]114
[300]115  CALL xios_get_handle("field_definition",fieldgroup_hdl)
116  CALL xios_add_child(fieldgroup_hdl,field_hdl,"field_B")
117  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_B")
[549]118
[300]119  CALL xios_get_handle("output",file_hdl)
120  CALL xios_add_child(file_hdl,field_hdl)
121  CALL xios_set_attr(field_hdl,field_ref="field_A",name="field_C")
[549]122
123
[300]124    dtime%second=3600
[549]125    CALL xios_set_timestep(timestep=dtime)
126
[384]127!    ni=0 ; lonvalue(:)=0
128!    CALL xios_get_domain_attr("domain_A",ni=ni,lonvalue=lonvalue)
[549]129
[384]130!    print *,"ni",ni
131!    print *,"lonvalue",lonvalue ;
[300]132
133    CALL xios_close_context_definition()
[549]134
[310]135    PRINT*,"field field_A is active ? ",xios_field_is_active("field_A")
[351]136    DO ts=1,24*10
[300]137      CALL xios_update_calendar(ts)
138      CALL xios_send_field("field_A",field_A)
[349]139      CALL wait_us(5000) ;
[300]140    ENDDO
[549]141
[300]142    CALL xios_context_finalize()
[654]143
144    DEALLOCATE(lon, lat, field_A, lonvalue)
145    DEALLOCATE(mask)
146
[655]147    CALL MPI_COMM_FREE(comm, ierr)
148
[300]149    CALL xios_finalize()
[549]150
[300]151  END SUBROUTINE client
152
[549]153
154
[300]155  SUBROUTINE server
156  USE xios
157  IMPLICIT NONE
[549]158
[300]159    CALL xios_init_server
[549]160
[300]161  END SUBROUTINE server
162
[549]163
164
Note: See TracBrowser for help on using the repository browser.