f90_example.f90 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2015 ONERA
  4. ! Copyright (C) 2015 Inria
  5. !
  6. ! StarPU is free software; you can redistribute it and/or modify
  7. ! it under the terms of the GNU Lesser General Public License as published by
  8. ! the Free Software Foundation; either version 2.1 of the License, or (at
  9. ! your option) any later version.
  10. !
  11. ! StarPU is distributed in the hope that it will be useful, but
  12. ! WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. !
  15. ! See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. PROGRAM f90_example
  17. USE mod_types
  18. USE mod_starpu
  19. USE mod_interface
  20. USE mod_compute
  21. USE iso_c_binding
  22. IMPLICIT NONE
  23. TYPE(type_mesh) :: mesh
  24. TYPE(type_numpar) :: numpar
  25. TYPE(type_mesh_elt),POINTER :: elt => NULL()
  26. INTEGER(KIND=C_INT) :: i,Nelt,res
  27. INTEGER(KIND=C_INT) :: neq,ng,nb,it,it_tot
  28. REAL(KIND=C_DOUBLE) :: r, coeff2
  29. !Initialization with arbitrary data
  30. Nelt = 2
  31. it_tot = 2
  32. numpar%Neq_max = 5
  33. numpar%coeff = 1.0
  34. ALLOCATE(mesh%elt(Nelt))
  35. DO i = 1,Nelt
  36. elt => mesh%elt(i)
  37. elt%Ng = 4
  38. elt%Np = 2
  39. ALLOCATE(elt%ro(numpar%Neq_max,elt%Np))
  40. ALLOCATE(elt%dro(numpar%Neq_max,elt%Np))
  41. ALLOCATE(elt%basis(elt%Np,elt%Ng))
  42. CALL init_element(elt%ro,elt%dro,elt%basis,numpar%Neq_max,elt%Np,elt%Ng,i)
  43. ENDDO
  44. !Initialization of StarPU
  45. res = starpu_my_init_c()
  46. !Registration of elements
  47. DO i = 1,Nelt
  48. elt => mesh%elt(i)
  49. CALL starpu_register_element_c(numpar%Neq_max,elt%Np,elt%Ng,elt%ro,elt%dro, &
  50. elt%basis,elt%ro_h,elt%dro_h,elt%basis_h)
  51. ENDDO
  52. !Compute
  53. DO it = 1,it_tot
  54. ! compute new dro for each element
  55. DO i = 1,Nelt
  56. elt => mesh%elt(i)
  57. CALL starpu_loop_element_task_c(numpar%coeff,elt%ro_h,elt%dro_h,elt%basis_h)
  58. ENDDO
  59. ! sync (if needed by the algorithm)
  60. CALL starpu_task_wait_for_all_c()
  61. ! - - - - -
  62. ! copy dro to ro for each element
  63. DO i = 1,Nelt
  64. elt => mesh%elt(i)
  65. CALL starpu_copy_element_task_c(elt%ro_h,elt%dro_h)
  66. ENDDO
  67. ! sync (if needed by the algorithm)
  68. CALL starpu_task_wait_for_all_c()
  69. ENDDO
  70. !Unregistration of elements
  71. DO i = 1,Nelt
  72. elt => mesh%elt(i)
  73. CALL starpu_unregister_element_c(elt%ro_h,elt%dro_h,elt%basis_h)
  74. ENDDO
  75. !Terminate StarPU, no task can be submitted after
  76. CALL starpu_shutdown_c()
  77. !Check data with StarPU
  78. WRITE(6,'(a)') " "
  79. WRITE(6,'(a)') " %%%% RESULTS STARPU %%%% "
  80. WRITE(6,'(a)') " "
  81. DO i = 1,Nelt
  82. WRITE(6,'(a,i4,a)') " elt ", i , " ; elt%ro = "
  83. WRITE(6,'(10(1x,F11.2))') mesh%elt(i)%ro
  84. WRITE(6,'(a)') " ------------------------ "
  85. ENDDO
  86. !Same compute without StarPU
  87. DO i = 1,Nelt
  88. elt => mesh%elt(i)
  89. CALL init_element(elt%ro,elt%dro,elt%basis,numpar%Neq_max,elt%Np,elt%Ng,i)
  90. ENDDO
  91. DO it = 1, it_tot
  92. DO i = 1,Nelt
  93. elt => mesh%elt(i)
  94. CALL loop_element_cpu(elt%ro,elt%dro,elt%basis,numpar%coeff,numpar%Neq_max,elt%Ng,elt%Np)
  95. elt%ro = elt%ro + elt%dro
  96. ENDDO
  97. ENDDO
  98. WRITE(6,'(a)') " "
  99. WRITE(6,'(a)') " %%%% RESULTS VERIFICATION %%%% "
  100. WRITE(6,'(a)') " "
  101. DO i = 1,Nelt
  102. WRITE(6,'(a,i4,a)') " elt ", i , " ; elt%ro = "
  103. WRITE(6,'(10(1x,F11.2))') mesh%elt(i)%ro
  104. WRITE(6,'(a)') " ------------------------ "
  105. ENDDO
  106. WRITE(6,'(a)') " "
  107. !Deallocation
  108. DO i = 1,Nelt
  109. elt => mesh%elt(i)
  110. DEALLOCATE(elt%ro)
  111. DEALLOCATE(elt%dro)
  112. DEALLOCATE(elt%basis)
  113. ENDDO
  114. DEALLOCATE(mesh%elt)
  115. END PROGRAM f90_example