| 1 | edhill | 1.1 | C $Header: /u/gcmpack/MITgcm/pkg/ex3/ex3_send_rx1.template,v 1.3 2006/02/06 21:09:54 edhill Exp $ | 
| 2 |  |  | C $Name:  $ | 
| 3 |  |  |  | 
| 4 |  |  | #include "EX3_OPTIONS.h" | 
| 5 |  |  |  | 
| 6 |  |  | C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| | 
| 7 |  |  | CBOP 0 | 
| 8 |  |  | C     !ROUTINE: EX3_SEND_RX1 | 
| 9 |  |  |  | 
| 10 |  |  | C     !INTERFACE: | 
| 11 |  |  | SUBROUTINE EX3_SEND_RX1( | 
| 12 |  |  | I     bufftag, recvProc, | 
| 13 |  |  | I     along_i, | 
| 14 |  |  | I     il,ih,is,  jl,jh,js,  kl,kh,ks, | 
| 15 |  |  | I     io1,jo1,ko1, | 
| 16 |  |  | I     idl1,idh1, jdl1,jdh1, kdl1,kdh1, | 
| 17 |  |  | I     array1, | 
| 18 |  |  | B     buff, n_buff, msgID, | 
| 19 |  |  | I     commType, | 
| 20 |  |  | I     myThid ) | 
| 21 |  |  |  | 
| 22 |  |  | C     !DESCRIPTION: | 
| 23 |  |  | C     Scalar exchange routine which simply copies values from an input | 
| 24 |  |  | C     array to a buffer in the specified order and then, if necessary, | 
| 25 |  |  | C     calls the appropriate MPI send function. | 
| 26 |  |  |  | 
| 27 |  |  | C     !USES: | 
| 28 |  |  | IMPLICIT NONE | 
| 29 |  |  | #include "SIZE.h" | 
| 30 |  |  | #include "EEPARAMS.h" | 
| 31 |  |  | #include "EESUPPORT.h" | 
| 32 |  |  |  | 
| 33 |  |  | C     !INPUT PARAMETERS: | 
| 34 |  |  | INTEGER bufftag, recvProc | 
| 35 |  |  | LOGICAL along_i | 
| 36 |  |  | INTEGER il,ih,is, jl,jh,js, kl,kh,ks | 
| 37 |  |  | INTEGER io1,jo1,ko1 | 
| 38 |  |  | INTEGER idl1,idh1, jdl1,jdh1, kdl1,kdh1 | 
| 39 |  |  | _RX array1( idl1:idh1, jdl1:jdh1, kdl1:kdh1 ) | 
| 40 |  |  | INTEGER n_buff | 
| 41 |  |  | _RX buff( n_buff ) | 
| 42 |  |  | INTEGER msgID(1) | 
| 43 |  |  | CHARACTER commType | 
| 44 |  |  | INTEGER myThid | 
| 45 |  |  | CEOP | 
| 46 |  |  |  | 
| 47 |  |  | C     !LOCAL VARIABLES | 
| 48 |  |  | INTEGER ii,jj,kk, ntb, nbv | 
| 49 |  |  | #ifdef ALLOW_USE_MPI | 
| 50 |  |  | INTEGER mpiid, mpirc | 
| 51 |  |  | #endif | 
| 52 |  |  | character*(100) msgbuf | 
| 53 |  |  |  | 
| 54 |  |  | C     Calculate buffer sizes | 
| 55 |  |  | nbv =  IABS((ih-il+1)/is) | 
| 56 |  |  | &     * IABS((jh-jl+1)/js) | 
| 57 |  |  | &     * IABS((kh-kl+1)/ks) | 
| 58 |  |  | IF ( nbv .GT. n_buff ) THEN | 
| 59 |  |  | WRITE(msgbuf,'(2a)') 'EX3_SEND_RX1 ERROR: buffer too small', | 
| 60 |  |  | &       '--please increase EX3_BUFF_FAC in ''EX3_SIZE.h''' | 
| 61 |  |  | CALL print_error(msgbuf, mythid) | 
| 62 |  |  | WRITE(msgbuf,'(a,i9)') '  current buffer length   = ', n_buff | 
| 63 |  |  | CALL print_error(msgbuf, mythid) | 
| 64 |  |  | WRITE(msgbuf,'(a,i9)') '  requested buffer length = ', nbv | 
| 65 |  |  | CALL print_error(msgbuf, mythid) | 
| 66 |  |  | STOP 'ABNORMAL END: S/R EX3_SEND_RX1' | 
| 67 |  |  | ENDIF | 
| 68 |  |  |  | 
| 69 |  |  | C     Copy the values into the buffer in the specified order | 
| 70 |  |  | ntb = 0 | 
| 71 |  |  | DO kk = kl, kh, ks | 
| 72 |  |  | IF ( along_i ) THEN | 
| 73 |  |  | C         Here, the "i" dimension cycles fastest and it "measures" the | 
| 74 |  |  | C         overlap width | 
| 75 |  |  | DO jj = jl, jh, js | 
| 76 |  |  | DO ii = il, ih, is | 
| 77 |  |  | ntb = ntb + 1 | 
| 78 |  |  | buff( ntb ) = array1( ii, jj, kk ) | 
| 79 |  |  | ENDDO | 
| 80 |  |  | ENDDO | 
| 81 |  |  | ELSE | 
| 82 |  |  | C         Here, the "j" dimension cycles fastest and it "measures" the | 
| 83 |  |  | C         overlap width | 
| 84 |  |  | DO ii = il, ih, is | 
| 85 |  |  | DO jj = jl, jh, js | 
| 86 |  |  | ntb = ntb + 1 | 
| 87 |  |  | buff( ntb ) = array1( ii, jj, kk ) | 
| 88 |  |  | ENDDO | 
| 89 |  |  | ENDDO | 
| 90 |  |  | ENDIF | 
| 91 |  |  | ENDDO | 
| 92 |  |  |  | 
| 93 |  |  | IF ( commType .EQ. 'P' ) THEN | 
| 94 |  |  | C       We may eventually need (?) some sort of synchronization | 
| 95 |  |  | C       mechanism for multi-threaded mode | 
| 96 |  |  | ELSEIF ( commType .EQ. 'M' ) THEN | 
| 97 |  |  | #ifdef ALLOW_USE_MPI | 
| 98 |  |  | CALL MPI_Isend( | 
| 99 |  |  | I       buff, nbv, EX3_MPI_TYPE_RX, recvProc, bufftag, | 
| 100 |  |  | I       MPI_COMM_MODEL, | 
| 101 |  |  | O       mpiid, mpirc ) | 
| 102 |  |  | C       Store MPI_Wait token in msgID. | 
| 103 |  |  | msgID(1) = mpiid | 
| 104 |  |  | #endif | 
| 105 |  |  | ELSE | 
| 106 |  |  | WRITE(msgbuf,'(3a)') 'EX3_SEND_RX1 ERROR: commType ''', | 
| 107 |  |  | &       commType, ''' is invalid' | 
| 108 |  |  | CALL print_error(msgbuf, mythid) | 
| 109 |  |  | STOP 'ABNORMAL END: S/R EX3_SEND_RX1' | 
| 110 |  |  | ENDIF | 
| 111 |  |  |  | 
| 112 |  |  | RETURN | 
| 113 |  |  | END | 
| 114 |  |  |  | 
| 115 |  |  | C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| | 
| 116 |  |  |  | 
| 117 |  |  | CEH3 ;;; Local Variables: *** | 
| 118 |  |  | CEH3 ;;; mode:fortran *** | 
| 119 |  |  | CEH3 ;;; End: *** |