nf_basic_ring.f90 4.1 KB

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