nf_compute.f90 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2015 ONERA
  4. ! Copyright (C) 2015-2016 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. ! Computation kernels for the simulation
  17. MODULE nf_compute
  18. USE nf_types
  19. USE fstarpu_mod
  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. RECURSIVE SUBROUTINE loop_element_cpu_fortran(buffers, cl_args) BIND(C)
  47. TYPE(C_PTR), VALUE, INTENT(IN) :: buffers, cl_args
  48. INTEGER(KIND=C_INT) :: Neq_max,Np,Ng
  49. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro,basis
  50. REAL(KIND=C_DOUBLE),TARGET :: coeff
  51. Neq_max = fstarpu_matrix_get_nx(buffers, 0)
  52. Np = fstarpu_matrix_get_nx(buffers, 2)
  53. Ng = fstarpu_matrix_get_ny(buffers, 2)
  54. CALL fstarpu_unpack_arg(cl_args,(/ c_loc(coeff) /))
  55. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 0), ro, shape=[Neq_max,Np])
  56. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 1), dro, shape=[Neq_max,Np])
  57. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 2), basis, shape=[Np,Ng])
  58. CALL loop_element_cpu(ro,dro,basis,coeff,Neq_max,Ng,Np)
  59. END SUBROUTINE loop_element_cpu_fortran
  60. !--------------------------------------------------------------!
  61. RECURSIVE SUBROUTINE loop_element_cpu(ro,dro,basis,coeff,Neq_max,Ng,Np)
  62. REAL(KIND=C_DOUBLE),INTENT(IN) :: coeff
  63. INTEGER(KIND=C_INT),INTENT(IN) :: Neq_max,Ng,Np
  64. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(IN) :: ro,basis
  65. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: dro
  66. !Local variables
  67. REAL(KIND=C_DOUBLE) :: coeff2,r
  68. INTEGER(KIND=C_INT) :: n,nb,neq
  69. DO n=1,Ng
  70. r = 0.
  71. DO nb=1,Np
  72. DO neq= 1,Neq_max
  73. r = r + basis(nb,n) * ro(neq,nb)
  74. ENDDO
  75. ENDDO
  76. coeff2 = r + coeff
  77. DO nb=1,Np
  78. DO neq = 1,Neq_max
  79. dro(neq,nb) = coeff2 + dro(neq,nb)
  80. ENDDO
  81. ENDDO
  82. ENDDO
  83. END SUBROUTINE loop_element_cpu
  84. !--------------------------------------------------------------!
  85. RECURSIVE SUBROUTINE copy_element_cpu_fortran(buffers, cl_args) BIND(C)
  86. TYPE(C_PTR), VALUE, INTENT(IN) :: buffers, cl_args
  87. INTEGER(KIND=C_INT) :: Neq_max,Np
  88. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER :: ro,dro
  89. Neq_max = fstarpu_matrix_get_nx(buffers, 0)
  90. Np = fstarpu_matrix_get_ny(buffers, 0)
  91. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 0), ro, shape=[Neq_max,Np])
  92. CALL c_f_pointer(fstarpu_matrix_get_ptr(buffers, 1), dro, shape=[Neq_max,Np])
  93. CALL copy_element_cpu(ro,dro)
  94. END SUBROUTINE copy_element_cpu_fortran
  95. !--------------------------------------------------------------!
  96. RECURSIVE SUBROUTINE copy_element_cpu(ro,dro)
  97. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(INOUT) :: ro
  98. REAL(KIND=C_DOUBLE),DIMENSION(:,:),POINTER,INTENT(IN) :: dro
  99. ro = ro + dro
  100. END SUBROUTINE copy_element_cpu
  101. END MODULE nf_compute