nf_basic_ring.f90 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2016 Inria
  4. !
  5. ! StarPU is free software; you can redistribute it and/or modify
  6. ! it under the terms of the GNU Lesser General Public License as published by
  7. ! the Free Software Foundation; either version 2.1 of the License, or (at
  8. ! your option) any later version.
  9. !
  10. ! StarPU is distributed in the hope that it will be useful, but
  11. ! WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. !
  14. ! See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. program nf_basic_ring
  16. use iso_c_binding ! C interfacing module
  17. use fstarpu_mod ! StarPU interfacing module
  18. use fstarpu_mpi_mod ! StarPU-MPI interfacing module
  19. implicit none
  20. integer(c_int) :: ncpu
  21. integer(c_int) :: ret
  22. integer(c_int) :: rank,sz
  23. integer(c_int),target :: token = 42
  24. integer(c_int) :: nloops = 32
  25. integer(c_int) :: loop
  26. integer(c_int) :: tag
  27. integer(c_int) :: world
  28. integer(c_int) :: src,dst
  29. type(c_ptr) :: token_dh, st
  30. ret = fstarpu_init(C_NULL_PTR)
  31. if (ret == -19) then
  32. stop 77
  33. else if (ret /= 0) then
  34. stop 1
  35. end if
  36. ret = fstarpu_mpi_init(1)
  37. print *,"fstarpu_mpi_init status:", ret
  38. if (ret /= 0) then
  39. stop 1
  40. end if
  41. ! stop there if no CPU worker available
  42. ncpu = fstarpu_cpu_worker_get_count()
  43. if (ncpu == 0) then
  44. call fstarpu_shutdown()
  45. ret = fstarpu_mpi_shutdown()
  46. stop 77
  47. end if
  48. world = fstarpu_mpi_world_comm()
  49. rank = fstarpu_mpi_world_rank()
  50. sz = fstarpu_mpi_world_size()
  51. write(*,*) "rank=", rank,"size=",sz,"world=",world
  52. if (sz < 2) then
  53. call fstarpu_shutdown()
  54. ret = fstarpu_mpi_shutdown()
  55. stop 77
  56. end if
  57. call fstarpu_variable_data_register(token_dh, 0, c_loc(token), c_sizeof(token))
  58. st = fstarpu_mpi_status_alloc()
  59. do loop=1,nloops
  60. tag = loop*sz+rank
  61. token = 0
  62. if (loop == 1.and.rank == 0) then
  63. write(*,*) "rank=", rank,"token=",token
  64. else
  65. src = modulo((rank+sz-1),sz)
  66. write(*,*) "rank=", rank,"recv--> src =", src, "tag =", tag
  67. ret = fstarpu_mpi_recv(token_dh, src, tag, world, st)
  68. if (ret /= 0) then
  69. write(*,*) "fstarpu_mpi_recv failed"
  70. stop 1
  71. end if
  72. write(*,*) "rank=", rank,"recv<--","token=",token
  73. token = token+1
  74. end if
  75. if (loop == nloops.and.rank == (sz-1)) then
  76. call fstarpu_data_acquire(token_dh, FSTARPU_R)
  77. write(*,*) "finished: rank=", rank,"token=",token
  78. call fstarpu_data_release(token_dh)
  79. else
  80. dst = modulo((rank+1),sz)
  81. write(*,*) "rank=", rank,"send--> dst =", dst, "tag =", tag+1
  82. ret = fstarpu_mpi_send(token_dh, dst, tag+1, world)
  83. if (ret /= 0) then
  84. write(*,*) "fstarpu_mpi_recv failed"
  85. stop 1
  86. end if
  87. write(*,*) "rank=", rank,"send<--"
  88. end if
  89. end do
  90. call fstarpu_mpi_status_free(st)
  91. call fstarpu_data_unregister(token_dh)
  92. call fstarpu_shutdown()
  93. ret = fstarpu_mpi_shutdown()
  94. print *,"fstarpu_mpi_shutdown status:", ret
  95. if (ret /= 0) then
  96. stop 1
  97. end if
  98. end program nf_basic_ring