mod_compute.f90 3.7 KB

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