f90_example.f90 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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_interface
  19. USE mod_compute
  20. USE iso_c_binding
  21. IMPLICIT NONE
  22. TYPE(type_mesh) :: mesh
  23. TYPE(type_numpar) :: numpar
  24. TYPE(type_mesh_elt),POINTER :: elt => NULL()
  25. INTEGER :: i,Nelt,res
  26. INTEGER :: neq,ng,nb,it,it_tot
  27. REAL :: r, coeff2
  28. !Initialization with arbitrary data
  29. Nelt = 2
  30. it_tot = 2
  31. numpar%Neq_max = 5
  32. numpar%coeff = 1.0
  33. ALLOCATE(mesh%elt(Nelt))
  34. DO i = 1,Nelt
  35. elt => mesh%elt(i)
  36. elt%Ng = 4
  37. elt%Np = 2
  38. ALLOCATE(elt%ro(numpar%Neq_max,elt%Np))
  39. ALLOCATE(elt%dro(numpar%Neq_max,elt%Np))
  40. ALLOCATE(elt%basis(elt%Np,elt%Ng))
  41. CALL init_element(elt%ro,elt%dro,elt%basis,numpar%Neq_max,elt%Np,elt%Ng,i)
  42. ENDDO
  43. !Initialization of StarPU
  44. res = starpu_init_c()
  45. !Registration of elements
  46. DO i = 1,Nelt
  47. elt => mesh%elt(i)
  48. CALL starpu_register_element_c(numpar%Neq_max,elt%Np,elt%Ng,elt%ro,elt%dro, &
  49. elt%basis,elt%ro_h,elt%dro_h,elt%basis_h)
  50. ENDDO
  51. !Compute
  52. DO it = 1,it_tot
  53. ! compute new dro for each element
  54. DO i = 1,Nelt
  55. elt => mesh%elt(i)
  56. CALL starpu_loop_element_task_c(numpar%coeff,elt%ro_h,elt%dro_h,elt%basis_h)
  57. ENDDO
  58. ! sync (if needed by the algorithm)
  59. CALL starpu_task_wait_for_all_c()
  60. ! - - - - -
  61. ! copy dro to ro for each element
  62. DO i = 1,Nelt
  63. elt => mesh%elt(i)
  64. CALL starpu_copy_element_task_c(elt%ro_h,elt%dro_h)
  65. ENDDO
  66. ! sync (if needed by the algorithm)
  67. CALL starpu_task_wait_for_all_c()
  68. ENDDO
  69. !Unregistration of elements
  70. DO i = 1,Nelt
  71. elt => mesh%elt(i)
  72. CALL starpu_unregister_element_c(elt%ro_h,elt%dro_h,elt%basis_h)
  73. ENDDO
  74. !Terminate StarPU, no task can be submitted after
  75. CALL starpu_shutdown_c()
  76. !Check data with StarPU
  77. WRITE(6,'(a)') " "
  78. WRITE(6,'(a)') " %%%% RESULTS STARPU %%%% "
  79. WRITE(6,'(a)') " "
  80. DO i = 1,Nelt
  81. WRITE(6,'(a,i4,a)') " elt ", i , " ; elt%ro = "
  82. WRITE(6,'(10(1x,F11.2))') mesh%elt(i)%ro
  83. WRITE(6,'(a)') " ------------------------ "
  84. ENDDO
  85. !Same compute without StarPU
  86. DO i = 1,Nelt
  87. elt => mesh%elt(i)
  88. CALL init_element(elt%ro,elt%dro,elt%basis,numpar%Neq_max,elt%Np,elt%Ng,i)
  89. ENDDO
  90. DO it = 1, it_tot
  91. DO i = 1,Nelt
  92. elt => mesh%elt(i)
  93. CALL loop_element_cpu(elt%ro,elt%dro,elt%basis,numpar%coeff,numpar%Neq_max,elt%Ng,elt%Np)
  94. elt%ro = elt%ro + elt%dro
  95. ENDDO
  96. ENDDO
  97. WRITE(6,'(a)') " "
  98. WRITE(6,'(a)') " %%%% RESULTS VERIFICATION %%%% "
  99. WRITE(6,'(a)') " "
  100. DO i = 1,Nelt
  101. WRITE(6,'(a,i4,a)') " elt ", i , " ; elt%ro = "
  102. WRITE(6,'(10(1x,F11.2))') mesh%elt(i)%ro
  103. WRITE(6,'(a)') " ------------------------ "
  104. ENDDO
  105. WRITE(6,'(a)') " "
  106. !Deallocation
  107. DO i = 1,Nelt
  108. elt => mesh%elt(i)
  109. DEALLOCATE(elt%ro)
  110. DEALLOCATE(elt%dro)
  111. DEALLOCATE(elt%basis)
  112. ENDDO
  113. DEALLOCATE(mesh%elt)
  114. END PROGRAM f90_example