nf_matrix.f90 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. program nf_matrix
  2. use iso_c_binding ! C interfacing module
  3. use fstarpu_mod ! StarPU interfacing module
  4. use nf_codelets
  5. implicit none
  6. real(8), dimension(:,:), allocatable, target :: ma
  7. integer, dimension(:,:), allocatable, target :: mb
  8. integer :: i,j
  9. type(c_ptr) :: cl_mat ! a pointer for the codelet structure
  10. type(c_ptr) :: dh_ma ! a pointer for the 'ma' vector data handle
  11. type(c_ptr) :: dh_mb ! a pointer for the 'mb' vector data handle
  12. integer(c_int) :: err ! return status for fstarpu_init
  13. allocate(ma(5,6))
  14. do i=1,5
  15. do j=1,6
  16. ma(i,j) = (i*10)+j
  17. end do
  18. end do
  19. allocate(mb(7,8))
  20. do i=1,7
  21. do j=1,8
  22. mb(i,j) = (i*10)+j
  23. end do
  24. end do
  25. ! initialize StarPU with default settings
  26. err = fstarpu_init(C_NULL_PTR)
  27. if (err == -19) then
  28. stop 77
  29. end if
  30. ! allocate an empty codelet structure
  31. cl_mat = fstarpu_codelet_allocate()
  32. ! add a CPU implementation function to the codelet
  33. call fstarpu_codelet_add_cpu_func(cl_mat, C_FUNLOC(cl_cpu_func_mat))
  34. ! add a Read-only mode data buffer to the codelet
  35. call fstarpu_codelet_add_buffer(cl_mat, FSTARPU_R)
  36. ! add a Read-Write mode data buffer to the codelet
  37. call fstarpu_codelet_add_buffer(cl_mat, FSTARPU_RW)
  38. ! register 'ma', a vector of real(8) elements
  39. dh_ma = fstarpu_matrix_data_register(c_loc(ma), 5, 5, 6, c_sizeof(ma(1,1)), 0)
  40. ! register 'mb', a vector of integer elements
  41. dh_mb = fstarpu_matrix_data_register(c_loc(mb), 7, 7, 8, c_sizeof(mb(1,1)), 0)
  42. ! insert a task with codelet cl_mat, and vectors 'ma' and 'mb'
  43. !
  44. ! Note: The array argument must follow the layout:
  45. ! (/
  46. ! <codelet_ptr>,
  47. ! [<argument_type> [<argument_value(s)],]
  48. ! . . .
  49. ! C_NULL_PTR
  50. ! )/
  51. !
  52. ! Note: The argument type for data handles is FSTARPU_DATA, regardless
  53. ! of the buffer access mode (specified in the codelet)
  54. call fstarpu_insert_task((/ cl_mat, FSTARPU_DATA, dh_ma, FSTARPU_DATA, dh_mb, C_NULL_PTR /))
  55. ! wait for task completion
  56. call fstarpu_task_wait_for_all()
  57. ! unregister 'ma'
  58. call fstarpu_data_unregister(dh_ma)
  59. ! unregister 'mb'
  60. call fstarpu_data_unregister(dh_mb)
  61. ! free codelet structure
  62. call fstarpu_codelet_free(cl_mat)
  63. ! shut StarPU down
  64. call fstarpu_shutdown()
  65. deallocate(mb)
  66. deallocate(ma)
  67. end program nf_matrix