nf_matrix.f90 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2017 CNRS
  4. ! Copyright (C) 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. !
  17. program nf_matrix
  18. use iso_c_binding ! C interfacing module
  19. use fstarpu_mod ! StarPU interfacing module
  20. use nf_codelets
  21. implicit none
  22. real(8), dimension(:,:), allocatable, target :: ma
  23. integer, dimension(:,:), allocatable, target :: mb
  24. integer :: i,j
  25. type(c_ptr) :: cl_mat ! a pointer for the codelet structure
  26. type(c_ptr) :: dh_ma ! a pointer for the 'ma' vector data handle
  27. type(c_ptr) :: dh_mb ! a pointer for the 'mb' vector data handle
  28. integer(c_int) :: err ! return status for fstarpu_init
  29. integer(c_int) :: ncpu ! number of cpus workers
  30. allocate(ma(5,6))
  31. do i=1,5
  32. do j=1,6
  33. ma(i,j) = (i*10)+j
  34. end do
  35. end do
  36. allocate(mb(7,8))
  37. do i=1,7
  38. do j=1,8
  39. mb(i,j) = (i*10)+j
  40. end do
  41. end do
  42. ! initialize StarPU with default settings
  43. err = fstarpu_init(C_NULL_PTR)
  44. if (err == -19) then
  45. stop 77
  46. end if
  47. ! stop there if no CPU worker available
  48. ncpu = fstarpu_cpu_worker_get_count()
  49. if (ncpu == 0) then
  50. call fstarpu_shutdown()
  51. stop 77
  52. end if
  53. ! allocate an empty codelet structure
  54. cl_mat = fstarpu_codelet_allocate()
  55. ! set the codelet name
  56. call fstarpu_codelet_set_name(cl_mat, C_CHAR_"my_mat_codelet"//C_NULL_CHAR)
  57. ! add a CPU implementation function to the codelet
  58. call fstarpu_codelet_add_cpu_func(cl_mat, C_FUNLOC(cl_cpu_func_mat))
  59. ! add a Read-only mode data buffer to the codelet
  60. call fstarpu_codelet_add_buffer(cl_mat, FSTARPU_R)
  61. ! add a Read-Write mode data buffer to the codelet
  62. call fstarpu_codelet_add_buffer(cl_mat, FSTARPU_RW)
  63. ! register 'ma', a vector of real(8) elements
  64. !dh_ma = fstarpu_matrix_data_register(c_loc(ma), 5, 5, 6, c_sizeof(ma(1,1)), 0)
  65. call fstarpu_matrix_data_register(dh_ma, 0, c_loc(ma), 5, 5, 6, c_sizeof(ma(1,1)))
  66. ! register 'mb', a vector of integer elements
  67. call fstarpu_matrix_data_register(dh_mb, 0, c_loc(mb), 7, 7, 8, c_sizeof(mb(1,1)))
  68. ! insert a task with codelet cl_mat, and vectors 'ma' and 'mb'
  69. !
  70. ! Note: The array argument must follow the layout:
  71. ! (/
  72. ! <codelet_ptr>,
  73. ! [<argument_type> [<argument_value(s)],]
  74. ! . . .
  75. ! C_NULL_PTR
  76. ! )/
  77. call fstarpu_insert_task((/ cl_mat, FSTARPU_R, dh_ma, FSTARPU_RW, dh_mb, C_NULL_PTR /))
  78. ! wait for task completion
  79. call fstarpu_task_wait_for_all()
  80. ! unregister 'ma'
  81. call fstarpu_data_unregister(dh_ma)
  82. ! unregister 'mb'
  83. call fstarpu_data_unregister(dh_mb)
  84. ! free codelet structure
  85. call fstarpu_codelet_free(cl_mat)
  86. ! shut StarPU down
  87. call fstarpu_shutdown()
  88. deallocate(mb)
  89. deallocate(ma)
  90. end program nf_matrix