mod_compute.f90 4.0 KB

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