[6328] | 1 | |
---|
| 2 | program test |
---|
| 3 | implicit none |
---|
| 4 | include "mpif.h" |
---|
| 5 | |
---|
| 6 | integer ier |
---|
| 7 | |
---|
| 8 | integer sreq(10), sreq2(10), rreq(10), rreq2(10) |
---|
| 9 | integer sbuf(10), sbuf2(10), rbuf(10), rbuf2(10) |
---|
| 10 | integer tag |
---|
| 11 | integer status(MPI_STATUS_SIZE,10) |
---|
| 12 | integer i |
---|
| 13 | integer comm2; |
---|
| 14 | logical flag; |
---|
| 15 | character pname(MPI_MAX_PROCESSOR_NAME) |
---|
| 16 | integer pnamesize |
---|
| 17 | |
---|
| 18 | integer temp,position |
---|
| 19 | integer errcount |
---|
| 20 | |
---|
| 21 | errcount = 0 |
---|
| 22 | |
---|
| 23 | print *, 'Time=',mpi_wtime() |
---|
| 24 | |
---|
| 25 | call mpi_initialized(flag,ier) |
---|
| 26 | print *, 'MPI is initialized=',flag |
---|
| 27 | |
---|
| 28 | call mpi_init(ier) |
---|
| 29 | |
---|
| 30 | call mpi_get_processor_name(pname,pnamesize,ier) |
---|
| 31 | print *, 'proc name: "',pname(1:pnamesize),'" size:',pnamesize |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | call mpi_comm_dup(MPI_COMM_WORLD,comm2,ier) |
---|
| 35 | |
---|
| 36 | call mpi_initialized(flag,ier) |
---|
| 37 | print *, 'MPI is initialized=',flag |
---|
| 38 | |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | |
---|
| 42 | do i=1,5 |
---|
| 43 | tag= 100+i |
---|
| 44 | print *, 'Post receive tag ',tag |
---|
| 45 | |
---|
| 46 | call mpi_irecv( rbuf(i),1,MPI_INTEGER,0,tag, & |
---|
| 47 | MPI_COMM_WORLD,rreq(i),ier) |
---|
| 48 | |
---|
| 49 | end do |
---|
| 50 | do i=1,5 |
---|
| 51 | ! tag=1100+i |
---|
| 52 | ! print *, 'Post receive tag ',tag |
---|
| 53 | |
---|
| 54 | call mpi_irecv( rbuf2(i),1,MPI_INTEGER, & |
---|
| 55 | MPI_ANY_SOURCE, MPI_ANY_TAG, & |
---|
| 56 | comm2,rreq2(i),ier) |
---|
| 57 | |
---|
| 58 | end do |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | do i=1,5 |
---|
| 62 | sbuf(i)=10*i |
---|
| 63 | tag=100+i |
---|
| 64 | print *, 'Send ',sbuf(i),' tag ',tag |
---|
| 65 | |
---|
| 66 | call mpi_isend( sbuf(i),1,MPI_INTEGER,0,tag, & |
---|
| 67 | MPI_COMM_WORLD,sreq(i),ier) |
---|
| 68 | end do |
---|
| 69 | |
---|
| 70 | |
---|
| 71 | do i=1,5 |
---|
| 72 | sbuf2(i)=1000+10*i |
---|
| 73 | tag=1100+i |
---|
| 74 | print *, 'Send ',sbuf2(i),' tag ',tag |
---|
| 75 | |
---|
| 76 | call mpi_isend( sbuf2(i),1,MPI_INTEGER,0,tag, & |
---|
| 77 | comm2,sreq2(i),ier) |
---|
| 78 | end do |
---|
| 79 | |
---|
| 80 | do i=1,5 |
---|
| 81 | if (sbuf(i) .ne. rbuf(i)) then |
---|
| 82 | errcount = errcount+1 |
---|
| 83 | print *, 'error on Send2' |
---|
| 84 | print *, 'found ',sbuf2(i),' should be ',rbuf2(i) |
---|
| 85 | end if |
---|
| 86 | end do |
---|
| 87 | |
---|
| 88 | do i=1,5 |
---|
| 89 | if (sbuf2(i) .ne. rbuf2(i)) then |
---|
| 90 | errcount = errcount+1 |
---|
| 91 | print *, 'error on Send2' |
---|
| 92 | print *, 'found ',sbuf2(i),' should be ',rbuf2(i) |
---|
| 93 | end if |
---|
| 94 | end do |
---|
| 95 | |
---|
| 96 | print *, 'Time=',mpi_wtime() |
---|
| 97 | call mpi_waitall(5,sreq,status,ier) |
---|
| 98 | print *,'sends on MPI_COMM_WORLD done' |
---|
| 99 | |
---|
| 100 | call mpi_waitall(5,rreq,status,ier) |
---|
| 101 | print *,'recvs on MPI_COMM_WORLD done' |
---|
| 102 | |
---|
| 103 | do i=1,5 |
---|
| 104 | print *, 'Status source=',status(MPI_SOURCE,i), & |
---|
| 105 | ' tag=',status(MPI_TAG,i) |
---|
| 106 | end do |
---|
| 107 | |
---|
| 108 | call mpi_waitall(5,sreq2,status,ier) |
---|
| 109 | print *,'sends on comm2 done' |
---|
| 110 | |
---|
| 111 | call mpi_waitall(5,rreq2,status,ier) |
---|
| 112 | print *,'recvs on comm2 done' |
---|
| 113 | |
---|
| 114 | do i=1,5 |
---|
| 115 | print *, 'Status source=',status(MPI_SOURCE,i), & |
---|
| 116 | ' tag=',status(MPI_TAG,i) |
---|
| 117 | end do |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | ! pack/unpack |
---|
| 121 | |
---|
| 122 | position=0 |
---|
| 123 | do i=1,5 |
---|
| 124 | temp=100+i |
---|
| 125 | call mpi_pack(temp,1,MPI_INTEGER,sbuf,20,position,MPI_COMM_WORLD,ier) |
---|
| 126 | end do |
---|
| 127 | |
---|
| 128 | call mpi_isend(sbuf,position,MPI_PACKED,0,0,MPI_COMM_WORLD,sreq(1),ier) |
---|
| 129 | call mpi_irecv(rbuf,position,MPI_PACKED,0,0,MPI_COMM_WORLD,rreq(1),ier) |
---|
| 130 | call mpi_waitall(1,rreq,status,ier) |
---|
| 131 | |
---|
| 132 | print *,"Pack/send/unpack:" |
---|
| 133 | |
---|
| 134 | position=0 |
---|
| 135 | do i=1,5 |
---|
| 136 | call mpi_unpack( rbuf,20,position,temp,1,MPI_INTEGER, & |
---|
| 137 | MPI_COMM_WORLD) |
---|
| 138 | print *,temp |
---|
| 139 | end do |
---|
| 140 | |
---|
| 141 | do i=1,5 |
---|
| 142 | if (rbuf(i) .ne. sbuf(i)) then |
---|
| 143 | errcount = errcount + 1 |
---|
| 144 | print *,"Error for pack/send/unpack" |
---|
| 145 | print *,"found ",rbuf(i)," should be ",sbuf(i) |
---|
| 146 | end if |
---|
| 147 | end do |
---|
| 148 | ! |
---|
| 149 | |
---|
| 150 | |
---|
| 151 | call mpi_finalize(ier) |
---|
| 152 | |
---|
| 153 | do i=1,5 |
---|
| 154 | print *, 'Time=',mpi_wtime() |
---|
| 155 | call sleep(1) |
---|
| 156 | end do |
---|
| 157 | |
---|
| 158 | if (errcount .gt. 0) then |
---|
| 159 | print *,errcount," errors" |
---|
| 160 | else |
---|
| 161 | print *,"No errors" |
---|
| 162 | end if |
---|
| 163 | |
---|
| 164 | end |
---|
| 165 | |
---|