nf_basic_ring.f90 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2016-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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. !
  16. program nf_basic_ring
  17. use iso_c_binding ! C interfacing module
  18. use fstarpu_mod ! StarPU interfacing module
  19. use fstarpu_mpi_mod ! StarPU-MPI interfacing module
  20. implicit none
  21. integer(c_int) :: ncpu
  22. integer(c_int) :: ret
  23. integer(c_int) :: rank,sz
  24. integer(c_int),target :: token = 42
  25. integer(c_int) :: nloops = 32
  26. integer(c_int) :: loop
  27. integer(c_int64_t) :: tag
  28. integer(c_int) :: world
  29. integer(c_int) :: src,dst
  30. type(c_ptr) :: token_dh, st
  31. ret = fstarpu_init(C_NULL_PTR)
  32. if (ret == -19) then
  33. stop 77
  34. else if (ret /= 0) then
  35. stop 1
  36. end if
  37. ret = fstarpu_mpi_init(1)
  38. print *,"fstarpu_mpi_init status:", ret
  39. if (ret /= 0) then
  40. stop 1
  41. end if
  42. ! stop there if no CPU worker available
  43. ncpu = fstarpu_cpu_worker_get_count()
  44. if (ncpu == 0) then
  45. call fstarpu_shutdown()
  46. ret = fstarpu_mpi_shutdown()
  47. stop 77
  48. end if
  49. world = fstarpu_mpi_world_comm()
  50. rank = fstarpu_mpi_world_rank()
  51. sz = fstarpu_mpi_world_size()
  52. write(*,*) "rank=", rank,"size=",sz,"world=",world
  53. if (sz < 2) then
  54. call fstarpu_shutdown()
  55. ret = fstarpu_mpi_shutdown()
  56. stop 77
  57. end if
  58. call fstarpu_variable_data_register(token_dh, 0, c_loc(token), c_sizeof(token))
  59. st = fstarpu_mpi_status_alloc()
  60. do loop=1,nloops
  61. tag = loop*sz+rank
  62. token = 0
  63. if (loop == 1.and.rank == 0) then
  64. write(*,*) "rank=", rank,"token=",token
  65. else
  66. src = modulo((rank+sz-1),sz)
  67. write(*,*) "rank=", rank,"recv--> src =", src, "tag =", tag
  68. ret = fstarpu_mpi_recv(token_dh, src, tag, world, st)
  69. if (ret /= 0) then
  70. write(*,*) "fstarpu_mpi_recv failed"
  71. stop 1
  72. end if
  73. write(*,*) "rank=", rank,"recv<--","token=",token
  74. token = token+1
  75. end if
  76. if (loop == nloops.and.rank == (sz-1)) then
  77. call fstarpu_data_acquire(token_dh, FSTARPU_R)
  78. write(*,*) "finished: rank=", rank,"token=",token
  79. call fstarpu_data_release(token_dh)
  80. else
  81. dst = modulo((rank+1),sz)
  82. write(*,*) "rank=", rank,"send--> dst =", dst, "tag =", tag+1
  83. ret = fstarpu_mpi_send(token_dh, dst, tag+1, world)
  84. if (ret /= 0) then
  85. write(*,*) "fstarpu_mpi_recv failed"
  86. stop 1
  87. end if
  88. write(*,*) "rank=", rank,"send<--"
  89. end if
  90. end do
  91. call fstarpu_mpi_status_free(st)
  92. call fstarpu_data_unregister(token_dh)
  93. call fstarpu_shutdown()
  94. ret = fstarpu_mpi_shutdown()
  95. print *,"fstarpu_mpi_shutdown status:", ret
  96. if (ret /= 0) then
  97. stop 1
  98. end if
  99. end program nf_basic_ring