mod_compute.f90 3.9 KB

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