mod_compute.f90 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2015,2017 CNRS
  4. ! Copyright (C) 2015 Inria
  5. ! Copyright (C) 2015 Université de Bordeaux
  6. ! Copyright (C) 2015 ONERA
  7. !
  8. ! StarPU is free software; you can redistribute it and/or modify
  9. ! it under the terms of the GNU Lesser General Public License as published by
  10. ! the Free Software Foundation; either version 2.1 of the License, or (at
  11. ! your option) any later version.
  12. !
  13. ! StarPU is distributed in the hope that it will be useful, but
  14. ! WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16. !
  17. ! See the GNU Lesser General Public License in COPYING.LGPL for more details.
  18. !
  19. ! Computation kernels for the simulation
  20. MODULE mod_compute
  21. USE mod_types
  22. USE starpu_mod
  23. USE mod_interface
  24. USE iso_c_binding
  25. IMPLICIT NONE
  26. CONTAINS
  27. !--------------------------------------------------------------!
  28. SUBROUTINE init_element(ro,dro,basis,Neq_max,Np,Ng,i)
  29. INTEGER(KIND=C_INT),INTENT(IN) :: Neq_max,Np,Ng,i
  30. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: ro,basis,dro
  31. !Local variables
  32. INTEGER(KIND=C_INT) :: n,nb,neq
  33. DO nb=1,Np
  34. DO neq= 1,Neq_max
  35. ro(neq,nb) = 0.01*(nb+neq)*i
  36. END DO
  37. END DO
  38. DO nb=1,Np
  39. DO neq= 1,Neq_max
  40. dro(neq,nb) = 0.05*(nb-neq)*i
  41. END DO
  42. END DO
  43. DO n=1,Ng
  44. DO nb=1,Np
  45. basis(nb,n) = 0.05*(n+nb)*i
  46. END DO
  47. END DO
  48. END SUBROUTINE init_element
  49. !--------------------------------------------------------------!
  50. RECURSIVE SUBROUTINE loop_element_cpu_fortran(coeff,Neq_max,Np,Ng, &
  51. & ro_ptr,dro_ptr,basis_ptr) BIND(C)
  52. INTEGER(KIND=C_INT),VALUE :: Neq_max,Np,Ng
  53. REAL(KIND=C_DOUBLE),VALUE :: coeff
  54. TYPE(C_PTR) :: ro_ptr,dro_ptr,basis_ptr
  55. !Local variables
  56. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro,basis
  57. CALL C_F_POINTER(ro_ptr,ro,[Neq_max,Np])
  58. CALL C_F_POINTER(dro_ptr,dro,[Neq_max,Np])
  59. CALL C_F_POINTER(basis_ptr,basis,[Np,Ng])
  60. CALL loop_element_cpu(ro,dro,basis,coeff,Neq_max,Ng,Np)
  61. END SUBROUTINE loop_element_cpu_fortran
  62. !--------------------------------------------------------------!
  63. RECURSIVE SUBROUTINE loop_element_cpu(ro,dro,basis,coeff,Neq_max,Ng,Np)
  64. REAL(KIND=C_DOUBLE),INTENT(IN) :: coeff
  65. INTEGER(KIND=C_INT),INTENT(IN) :: Neq_max,Ng,Np
  66. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(IN) :: ro,basis
  67. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: dro
  68. !Local variables
  69. REAL(KIND=C_DOUBLE) :: coeff2,r
  70. INTEGER(KIND=C_INT) :: n,nb,neq
  71. DO n=1,Ng
  72. r = 0.
  73. DO nb=1,Np
  74. DO neq= 1,Neq_max
  75. r = r + basis(nb,n) * ro(neq,nb)
  76. ENDDO
  77. ENDDO
  78. coeff2 = r + coeff
  79. DO nb=1,Np
  80. DO neq = 1,Neq_max
  81. dro(neq,nb) = coeff2 + dro(neq,nb)
  82. ENDDO
  83. ENDDO
  84. ENDDO
  85. END SUBROUTINE loop_element_cpu
  86. !--------------------------------------------------------------!
  87. RECURSIVE SUBROUTINE copy_element_cpu_fortran(Neq_max,Np, &
  88. & ro_ptr,dro_ptr) BIND(C)
  89. INTEGER(KIND=C_INT),VALUE :: Neq_max,Np
  90. TYPE(C_PTR) :: ro_ptr,dro_ptr
  91. !Local variables
  92. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro
  93. CALL C_F_POINTER(ro_ptr,ro,[Neq_max,Np])
  94. CALL C_F_POINTER(dro_ptr,dro,[Neq_max,Np])
  95. CALL copy_element_cpu(ro,dro)
  96. END SUBROUTINE copy_element_cpu_fortran
  97. !--------------------------------------------------------------!
  98. RECURSIVE SUBROUTINE copy_element_cpu(ro,dro)
  99. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: ro
  100. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(IN) :: dro
  101. ro = ro + dro
  102. END SUBROUTINE copy_element_cpu
  103. END MODULE mod_compute