ftest.F90 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. program test
  2. implicit none
  3. include "mpif.h"
  4. integer ier
  5. integer sreq(10), sreq2(10), rreq(10), rreq2(10)
  6. integer sbuf(10), sbuf2(10), rbuf(10), rbuf2(10)
  7. integer tag
  8. integer status(MPI_STATUS_SIZE,10)
  9. integer i
  10. integer comm2;
  11. logical flag;
  12. character pname(MPI_MAX_PROCESSOR_NAME)
  13. integer pnamesize
  14. integer temp,position
  15. external my_op_func
  16. integer myop
  17. print *, 'Time=',mpi_wtime()
  18. call mpi_initialized(flag,ier)
  19. print *, 'MPI is initialized=',flag
  20. call mpi_init(ier)
  21. call mpi_get_processor_name(pname,pnamesize,ier)
  22. print *, 'proc name: "',pname(1:pnamesize),'" size:',pnamesize
  23. call mpi_comm_dup(MPI_COMM_WORLD,comm2,ier)
  24. call mpi_initialized(flag,ier)
  25. print *, 'MPI is initialized=',flag
  26. do i=1,5
  27. tag= 100+i
  28. print *, 'Post receive tag ',tag
  29. call mpi_irecv( rbuf(i),1,MPI_INTEGER,0,tag, &
  30. MPI_COMM_WORLD,rreq(i),ier)
  31. end do
  32. do i=1,5
  33. ! tag=1100+i
  34. ! print *, 'Post receive tag ',tag
  35. call mpi_irecv( rbuf2(i),1,MPI_INTEGER, &
  36. MPI_ANY_SOURCE, MPI_ANY_TAG, &
  37. comm2,rreq2(i),ier)
  38. end do
  39. do i=1,5
  40. sbuf(i)=10*i
  41. tag=100+i
  42. print *, 'Send ',sbuf(i),' tag ',tag
  43. call mpi_isend( sbuf(i),1,MPI_INTEGER,0,tag, &
  44. MPI_COMM_WORLD,sreq(i),ier)
  45. end do
  46. do i=1,5
  47. sbuf2(i)=1000+10*i
  48. tag=1100+i
  49. print *, 'Send ',sbuf2(i),' tag ',tag
  50. call mpi_isend( sbuf2(i),1,MPI_INTEGER,0,tag, &
  51. comm2,sreq2(i),ier)
  52. end do
  53. print *, 'Time=',mpi_wtime()
  54. call mpi_waitall(5,sreq,status,ier)
  55. print *,'sends on MPI_COMM_WORLD done'
  56. call mpi_waitall(5,rreq,status,ier)
  57. print *,'recvs on MPI_COMM_WORLD done'
  58. do i=1,5
  59. print *, 'Status source=',status(MPI_SOURCE,i), &
  60. ' tag=',status(MPI_TAG,i)
  61. end do
  62. call mpi_waitall(5,sreq2,status,ier)
  63. print *,'sends on comm2 done'
  64. call mpi_waitall(5,rreq2,status,ier)
  65. print *,'recvs on comm2 done'
  66. do i=1,5
  67. print *, 'Status source=',status(MPI_SOURCE,i), &
  68. ' tag=',status(MPI_TAG,i)
  69. end do
  70. ! pack/unpack
  71. position=0
  72. do i=1,5
  73. temp=100+i
  74. call mpi_pack(temp,1,MPI_INTEGER,sbuf,20,position,MPI_COMM_WORLD,ier)
  75. end do
  76. call mpi_isend(sbuf,position,MPI_PACKED,0,0,MPI_COMM_WORLD,sreq(1),ier)
  77. call mpi_irecv(rbuf,position,MPI_PACKED,0,0,MPI_COMM_WORLD,rreq(1),ier)
  78. call mpi_waitall(1,rreq,status,ier)
  79. print *,"Pack/send/unpack:"
  80. position=0
  81. do i=1,5
  82. call mpi_unpack( rbuf,20,position,temp,1,MPI_INTEGER, &
  83. MPI_COMM_WORLD,ier)
  84. print *,temp
  85. end do
  86. !
  87. print *,"Creating op"
  88. call mpi_op_create(my_op_func,.TRUE.,myop,ier)
  89. call mpi_finalize(ier)
  90. do i=1,5
  91. print *, 'Time=',mpi_wtime()
  92. call sleep(1)
  93. end do
  94. end
  95. function my_op_func(invec,inoutvec,len,type)
  96. integer invec(len),inoutvec(len)
  97. integer len,type
  98. return
  99. end function my_op_func