mod_compute.f90 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. ! Computation kernels for the simulation
  17. MODULE mod_compute
  18. USE mod_types
  19. USE starpu_mod
  20. USE mod_interface
  21. USE iso_c_binding
  22. IMPLICIT NONE
  23. CONTAINS
  24. !--------------------------------------------------------------!
  25. SUBROUTINE init_element(ro,dro,basis,Neq_max,Np,Ng,i)
  26. INTEGER(KIND=C_INT),INTENT(IN) :: Neq_max,Np,Ng,i
  27. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: ro,basis,dro
  28. !Local variables
  29. INTEGER(KIND=C_INT) :: n,nb,neq
  30. DO nb=1,Np
  31. DO neq= 1,Neq_max
  32. ro(neq,nb) = 0.01*(nb+neq)*i
  33. END DO
  34. END DO
  35. DO nb=1,Np
  36. DO neq= 1,Neq_max
  37. dro(neq,nb) = 0.05*(nb-neq)*i
  38. END DO
  39. END DO
  40. DO n=1,Ng
  41. DO nb=1,Np
  42. basis(nb,n) = 0.05*(n+nb)*i
  43. END DO
  44. END DO
  45. END SUBROUTINE init_element
  46. !--------------------------------------------------------------!
  47. RECURSIVE SUBROUTINE loop_element_cpu_fortran(coeff,Neq_max,Np,Ng, &
  48. & ro_ptr,dro_ptr,basis_ptr) BIND(C)
  49. INTEGER(KIND=C_INT),VALUE :: Neq_max,Np,Ng
  50. REAL(KIND=C_DOUBLE),VALUE :: coeff
  51. TYPE(C_PTR) :: ro_ptr,dro_ptr,basis_ptr
  52. !Local variables
  53. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro,basis
  54. CALL C_F_POINTER(ro_ptr,ro,[Neq_max,Np])
  55. CALL C_F_POINTER(dro_ptr,dro,[Neq_max,Np])
  56. CALL C_F_POINTER(basis_ptr,basis,[Np,Ng])
  57. CALL loop_element_cpu(ro,dro,basis,coeff,Neq_max,Ng,Np)
  58. END SUBROUTINE loop_element_cpu_fortran
  59. !--------------------------------------------------------------!
  60. RECURSIVE SUBROUTINE loop_element_cpu(ro,dro,basis,coeff,Neq_max,Ng,Np)
  61. REAL(KIND=C_DOUBLE),INTENT(IN) :: coeff
  62. INTEGER(KIND=C_INT),INTENT(IN) :: Neq_max,Ng,Np
  63. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(IN) :: ro,basis
  64. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: dro
  65. !Local variables
  66. REAL(KIND=C_DOUBLE) :: coeff2,r
  67. INTEGER(KIND=C_INT) :: n,nb,neq
  68. DO n=1,Ng
  69. r = 0.
  70. DO nb=1,Np
  71. DO neq= 1,Neq_max
  72. r = r + basis(nb,n) * ro(neq,nb)
  73. ENDDO
  74. ENDDO
  75. coeff2 = r + coeff
  76. DO nb=1,Np
  77. DO neq = 1,Neq_max
  78. dro(neq,nb) = coeff2 + dro(neq,nb)
  79. ENDDO
  80. ENDDO
  81. ENDDO
  82. END SUBROUTINE loop_element_cpu
  83. !--------------------------------------------------------------!
  84. RECURSIVE SUBROUTINE copy_element_cpu_fortran(Neq_max,Np, &
  85. & ro_ptr,dro_ptr) BIND(C)
  86. INTEGER(KIND=C_INT),VALUE :: Neq_max,Np
  87. TYPE(C_PTR) :: ro_ptr,dro_ptr
  88. !Local variables
  89. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro
  90. CALL C_F_POINTER(ro_ptr,ro,[Neq_max,Np])
  91. CALL C_F_POINTER(dro_ptr,dro,[Neq_max,Np])
  92. CALL copy_element_cpu(ro,dro)
  93. END SUBROUTINE copy_element_cpu_fortran
  94. !--------------------------------------------------------------!
  95. RECURSIVE SUBROUTINE copy_element_cpu(ro,dro)
  96. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: ro
  97. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(IN) :: dro
  98. ro = ro + dro
  99. END SUBROUTINE copy_element_cpu
  100. END MODULE mod_compute