nf_compute.f90 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2017 CNRS
  4. ! Copyright (C) 2015,2016 Inria
  5. ! Copyright (C) 2015 ONERA
  6. !
  7. ! StarPU is free software; you can redistribute it and/or modify
  8. ! it under the terms of the GNU Lesser General Public License as published by
  9. ! the Free Software Foundation; either version 2.1 of the License, or (at
  10. ! your option) any later version.
  11. !
  12. ! StarPU is distributed in the hope that it will be useful, but
  13. ! WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. !
  16. ! See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. !
  18. ! Computation kernels for the simulation
  19. MODULE nf_compute
  20. USE nf_types
  21. USE fstarpu_mod
  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(buffers, cl_args) BIND(C)
  49. TYPE(C_PTR), VALUE, INTENT(IN) :: buffers, cl_args
  50. INTEGER(KIND=C_INT) :: Neq_max,Np,Ng
  51. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro,basis
  52. REAL(KIND=C_DOUBLE),TARGET :: coeff
  53. Neq_max = fstarpu_matrix_get_nx(buffers, 0)
  54. Np = fstarpu_matrix_get_nx(buffers, 2)
  55. Ng = fstarpu_matrix_get_ny(buffers, 2)
  56. CALL fstarpu_unpack_arg(cl_args,(/ c_loc(coeff) /))
  57. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 0), ro, shape=[Neq_max,Np])
  58. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 1), dro, shape=[Neq_max,Np])
  59. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 2), basis, shape=[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(buffers, cl_args) BIND(C)
  88. TYPE(C_PTR), VALUE, INTENT(IN) :: buffers, cl_args
  89. INTEGER(KIND=C_INT) :: Neq_max,Np
  90. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro
  91. Neq_max = fstarpu_matrix_get_nx(buffers, 0)
  92. Np = fstarpu_matrix_get_ny(buffers, 0)
  93. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 0), ro, shape=[Neq_max,Np])
  94. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 1), dro, shape=[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 nf_compute