nf_matrix.f90 2.5 KB

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