source: CPL/oasis3/trunk/src/lib/clim/src/CLIM_Export.F @ 1906

Last change on this file since 1906 was 1677, checked in by aclsce, 12 years ago

Imported oasis3 (tag ipslcm5a) from cvs server to svn server (igcmg project).

File size: 5.9 KB
Line 
1      SUBROUTINE CLIM_Export(id_port_id,kstep,pfield,kinfo)
2c
3c*    *** Export ***   
4c
5c     purpose:
6c     --------
7c        give pfield to models connected to port id_port_id  at the time kstep
8c
9c     interface:
10c     ----------
11c        id_port_id : port number of the field
12c        kstep  : current time in seconds
13c        pfield : buffer of reals
14c        kinfo  : output status
15c
16c     lib mp:
17c     -------
18c        mpi-1
19c
20c     author:
21c     -------
22c        Eric Sevault   - METEO FRANCE
23c        Laurent Terray - CERFACS
24c        Jean Latour    - F.S.E.     
25c        Arnaud Caubel  - Fecit
26c
27c     ----------------------------------------------------------------
28#if defined use_comm_MPI1 || defined use_comm_MPI2 || !defined use_comm_MPI1 && !defined use_comm_MPI2 && !defined use_comm_SIPC && !defined use_comm_GMEM && !defined use_comm_PIPE && !defined use_comm_NONE
29      USE mod_kinds_oasis
30      USE mod_clim
31      USE mod_comclim
32#include <mpif.h>
33c     ----------------------------------------------------------------
34      INTEGER (kind=ip_intwp_p)       kstep, kinfo
35      CHARACTER(len=1), DIMENSION(*) :: pfield
36c     ----------------------------------------------------------------
37      INTEGER (kind=ip_intwp_p)    info
38      INTEGER (kind=ip_intwp_p)    isend, ip, iport, ilk, iseg, is, 
39     $    ilgb, imod, itid, itag, ilen, ioff, ityp, ibyt
40      INTEGER (kind=ip_intwp_p)    iposbuf
41c     ----------------------------------------------------------------
42c
43c*    0. First Check
44c     --------------
45c
46      WRITE(nulprt, *)'entering CLIM_Export'
47      IF (nexit.ne.1) THEN
48          kinfo = CLIM_FastExit
49          WRITE(nulprt,FMT='(A)') 'Export - should not be called'
50          GO TO 1010
51      ENDIF
52      kinfo = CLIM_Ok
53c
54c*    1. check for this port in my list
55c     ---------------------------------
56c
57      isend = 0
58      iport = -1
59c
60      IF (myport(1,id_port_id).eq.CLIM_Out) iport=id_port_id
61
62      IF (iport.lt.0) THEN
63         kinfo = CLIM_BadPort
64         WRITE(nulprt,FMT='(A,A)')
65     *         'Export - WARNING - Invalid port out: ',
66     $        cports(id_port_id)
67         GO TO 1010
68      ENDIF
69c
70c*    2. check for connected ports (in)
71c     ---------------------------------
72c
73      WRITE(nulprt,FMT='(A,A)') 'Export - ', cports(iport)
74c
75      ityp = myport(2,iport)
76      ibyt = myport(3,iport)
77c
78      DO 290 ip=1,myport(5,iport)
79c
80         ilk  = myport(5+ip,iport)
81         imod = mylink(1,ilk)
82         itid = mylink(2,ilk)
83         itag = mylink(3,ilk) - kstep / ig_frqmin
84         iseg = mylink(4,ilk)
85c
86             ilgb = 0
87             iposbuf = 0
88             DO 240 is=1,iseg
89               ioff = mylink(4+2*is-1,ilk) * ibyt + 1
90               ilen = mylink(4+2*is,ilk)
91c
92c               IF     ( ityp .EQ. CLIM_Integer ) THEN
93c                   CALL MPI_Pack ( pfield(ioff), ilen, MPI_INTEGER, 
94c     *                 pkwork, ig_maxtype, iposbuf, mpi_comm, info )
95c               ELSEIF ( ityp .EQ. CLIM_Real ) THEN
96               IF ( ityp .EQ. CLIM_Real ) THEN
97C                   IF ( kind(rl_testvar) .eq. 4 ) THEN
98                   IF ( ip_realwp_p .eq. ip_single_p ) THEN
99                       CALL MPI_Pack ( pfield(ioff), ilen, 
100     *                     MPI_REAL,pkwork, ig_maxtype, iposbuf, 
101     *                     mpi_comm, info )
102C                   ELSE IF ( kind(rl_testvar) .eq. 8 ) THEN
103                   ELSE IF ( ip_realwp_p .eq. ip_double_p ) THEN
104                       CALL MPI_Pack ( pfield(ioff), ilen, 
105     *                     MPI_DOUBLE_PRECISION,pkwork, ig_maxtype, 
106     *                     iposbuf, mpi_comm, info )
107                   ENDIF
108c               ELSEIF ( ityp .EQ. CLIM_Double ) THEN
109c                   CALL MPI_Pack ( pfield(ioff), ilen, 
110c     *                 MPI_DOUBLE_PRECISION,
111c     *                 pkwork, ig_maxtype, iposbuf, mpi_comm, info )
112               ELSE
113                   WRITE(nulprt,*)'Export - pb type incorrect ',ityp
114                   kinfo = CLIM_BadType
115                   GO TO 1010
116               ENDIF
117               ilgb = ilgb + ilen
118 240        CONTINUE
119            IF (info.ne.0 .or. ilgb*ibyt .gt. ig_maxtype) THEN
120               kinfo = CLIM_Pack
121               WRITE(nulprt,FMT='(A,I3,I8,A)')
122     *              'Export - pb pack<mpi ',info,ilgb*ibyt,'>'
123            ELSE
124c
125                IF (lg_bsend) then
126c*
127c*   Buffered send
128c*   -> if fields are not sent and received in the same order, and
129c*   and on architectures on which MPI_Send is not implemented with a 
130c*   mailbox (e.g. NEC SX5)
131c*
132                    CALL MPI_BSend ( pkwork, iposbuf, MPI_PACKED, itid,
133     *                  itag, mpi_comm, info )
134                ELSE
135c
136c*   Standard blocking send: To be used
137c*   -> if fields are necessarily sent and received in the same order, 
138c*   -> or on architectures on which MPI_Send is implemented with a 
139c*      mailbox (e.g. VPPs); in this case, make sure that your mailbox
140c*      size is large enough.
141c
142                    CALL MPI_Send ( pkwork, iposbuf, MPI_PACKED, itid,
143     *                  itag, mpi_comm, info )
144c
145                ENDIF
146c
147                 IF (info.eq.CLIM_ok) THEN
148                     isend = isend + 1
149                     nbsend = nbsend + ilgb * ibyt
150                     WRITE(nulprt,FMT='(A,I2,A,I9,A,I7,A,I2,A,I10,A)')
151     *                   'Export - <dest:',imod,
152     *                   '> <step:',kstep,
153     *                   '> <len:',ilgb,
154     *                   '> <type:',ibyt,
155     *                   '> <tag:',itag,'>'
156                 ELSE
157                     kinfo = CLIM_Pvm
158                     WRITE(nulprt,FMT='(A,I3,A)')
159     *                   'Export - pb send <mpi ',info,'>'
160                 ENDIF
161             ENDIF
162c
163c
164 290    CONTINUE
165c
166        WRITE(nulprt,FMT='(A,I3,A)') 
167     *     'Export - ',isend,' fields exported'
168c
169c     ----------------------------------------------------------------
170c
171 1010 CONTINUE
172      CALL FLUSH(nulprt)
173#endif
174      RETURN
175      END
Note: See TracBrowser for help on using the repository browser.