nf_compute.f90 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2015-2021 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 nf_compute
  19. USE nf_types
  20. USE fstarpu_mod
  21. USE iso_c_binding
  22. IMPLICIT NONE
  23. CONTAINS
  24. !--------------------------------------------------------------!
  25. SUBROUTINE init_element(ro,dro,basis,Neq_max,Np,Ng,i)
  26. INTEGER(KIND=C_INT),INTENT(IN) :: Neq_max,Np,Ng,i
  27. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: ro,basis,dro
  28. !Local variables
  29. INTEGER(KIND=C_INT) :: n,nb,neq
  30. DO nb=1,Np
  31. DO neq= 1,Neq_max
  32. ro(neq,nb) = 0.01*(nb+neq)*i
  33. END DO
  34. END DO
  35. DO nb=1,Np
  36. DO neq= 1,Neq_max
  37. dro(neq,nb) = 0.05*(nb-neq)*i
  38. END DO
  39. END DO
  40. DO n=1,Ng
  41. DO nb=1,Np
  42. basis(nb,n) = 0.05*(n+nb)*i
  43. END DO
  44. END DO
  45. END SUBROUTINE init_element
  46. !--------------------------------------------------------------!
  47. RECURSIVE SUBROUTINE loop_element_cpu_fortran(buffers, cl_args) BIND(C)
  48. TYPE(C_PTR), VALUE, INTENT(IN) :: buffers, cl_args
  49. INTEGER(KIND=C_INT) :: Neq_max,Np,Ng
  50. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro,basis
  51. REAL(KIND=C_DOUBLE),TARGET :: coeff
  52. Neq_max = fstarpu_matrix_get_nx(buffers, 0)
  53. Np = fstarpu_matrix_get_nx(buffers, 2)
  54. Ng = fstarpu_matrix_get_ny(buffers, 2)
  55. CALL fstarpu_unpack_arg(cl_args,(/ c_loc(coeff) /))
  56. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 0), ro, shape=[Neq_max,Np])
  57. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 1), dro, shape=[Neq_max,Np])
  58. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 2), basis, shape=[Np,Ng])
  59. CALL loop_element_cpu(ro,dro,basis,coeff,Neq_max,Ng,Np)
  60. END SUBROUTINE loop_element_cpu_fortran
  61. !--------------------------------------------------------------!
  62. RECURSIVE SUBROUTINE loop_element_cpu(ro,dro,basis,coeff,Neq_max,Ng,Np)
  63. REAL(KIND=C_DOUBLE),INTENT(IN) :: coeff
  64. INTEGER(KIND=C_INT),INTENT(IN) :: Neq_max,Ng,Np
  65. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(IN) :: ro,basis
  66. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: dro
  67. !Local variables
  68. REAL(KIND=C_DOUBLE) :: coeff2,r
  69. INTEGER(KIND=C_INT) :: n,nb,neq
  70. DO n=1,Ng
  71. r = 0.
  72. DO nb=1,Np
  73. DO neq= 1,Neq_max
  74. r = r + basis(nb,n) * ro(neq,nb)
  75. ENDDO
  76. ENDDO
  77. coeff2 = r + coeff
  78. DO nb=1,Np
  79. DO neq = 1,Neq_max
  80. dro(neq,nb) = coeff2 + dro(neq,nb)
  81. ENDDO
  82. ENDDO
  83. ENDDO
  84. END SUBROUTINE loop_element_cpu
  85. !--------------------------------------------------------------!
  86. RECURSIVE SUBROUTINE copy_element_cpu_fortran(buffers, cl_args) BIND(C)
  87. TYPE(C_PTR), VALUE, INTENT(IN) :: buffers, cl_args
  88. INTEGER(KIND=C_INT) :: Neq_max,Np
  89. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro
  90. Neq_max = fstarpu_matrix_get_nx(buffers, 0)
  91. Np = fstarpu_matrix_get_ny(buffers, 0)
  92. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 0), ro, shape=[Neq_max,Np])
  93. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 1), dro, shape=[Neq_max,Np])
  94. CALL copy_element_cpu(ro,dro)
  95. END SUBROUTINE copy_element_cpu_fortran
  96. !--------------------------------------------------------------!
  97. RECURSIVE SUBROUTINE copy_element_cpu(ro,dro)
  98. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: ro
  99. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(IN) :: dro
  100. ro = ro + dro
  101. END SUBROUTINE copy_element_cpu
  102. END MODULE nf_compute