nf_matrix.f90 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. integer(c_int) :: ncpu ! number of cpus workers
  14. allocate(ma(5,6))
  15. do i=1,5
  16. do j=1,6
  17. ma(i,j) = (i*10)+j
  18. end do
  19. end do
  20. allocate(mb(7,8))
  21. do i=1,7
  22. do j=1,8
  23. mb(i,j) = (i*10)+j
  24. end do
  25. end do
  26. ! initialize StarPU with default settings
  27. err = fstarpu_init(C_NULL_PTR)
  28. if (err == -19) then
  29. stop 77
  30. end if
  31. ! stop there if no CPU worker available
  32. ncpu = fstarpu_cpu_worker_get_count()
  33. if (ncpu == 0) then
  34. call fstarpu_shutdown()
  35. stop 77
  36. end if
  37. ! allocate an empty codelet structure
  38. cl_mat = fstarpu_codelet_allocate()
  39. ! set the codelet name
  40. call fstarpu_codelet_set_name(cl_mat, C_CHAR_"my_mat_codelet"//C_NULL_CHAR)
  41. ! add a CPU implementation function to the codelet
  42. call fstarpu_codelet_add_cpu_func(cl_mat, C_FUNLOC(cl_cpu_func_mat))
  43. ! add a Read-only mode data buffer to the codelet
  44. call fstarpu_codelet_add_buffer(cl_mat, FSTARPU_R)
  45. ! add a Read-Write mode data buffer to the codelet
  46. call fstarpu_codelet_add_buffer(cl_mat, FSTARPU_RW)
  47. ! register 'ma', a vector of real(8) elements
  48. !dh_ma = fstarpu_matrix_data_register(c_loc(ma), 5, 5, 6, c_sizeof(ma(1,1)), 0)
  49. call fstarpu_matrix_data_register(dh_ma, 0, c_loc(ma), 5, 5, 6, c_sizeof(ma(1,1)))
  50. ! register 'mb', a vector of integer elements
  51. call fstarpu_matrix_data_register(dh_mb, 0, c_loc(mb), 7, 7, 8, c_sizeof(mb(1,1)))
  52. ! insert a task with codelet cl_mat, and vectors 'ma' and 'mb'
  53. !
  54. ! Note: The array argument must follow the layout:
  55. ! (/
  56. ! <codelet_ptr>,
  57. ! [<argument_type> [<argument_value(s)],]
  58. ! . . .
  59. ! C_NULL_PTR
  60. ! )/
  61. call fstarpu_insert_task((/ cl_mat, FSTARPU_R, dh_ma, FSTARPU_RW, dh_mb, C_NULL_PTR /))
  62. ! wait for task completion
  63. call fstarpu_task_wait_for_all()
  64. ! unregister 'ma'
  65. call fstarpu_data_unregister(dh_ma)
  66. ! unregister 'mb'
  67. call fstarpu_data_unregister(dh_mb)
  68. ! free codelet structure
  69. call fstarpu_codelet_free(cl_mat)
  70. ! shut StarPU down
  71. call fstarpu_shutdown()
  72. deallocate(mb)
  73. deallocate(ma)
  74. end program nf_matrix