native_fortran_example.f90 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2016 Inria
  4. !
  5. ! StarPU is free software; you can redistribute it and/or modify
  6. ! it under the terms of the GNU Lesser General Public License as published by
  7. ! the Free Software Foundation; either version 2.1 of the License, or (at
  8. ! your option) any later version.
  9. !
  10. ! StarPU is distributed in the hope that it will be useful, but
  11. ! WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. !
  14. ! See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. program native_fortran_example
  16. use iso_c_binding ! C interfacing module
  17. use fstarpu_mod ! StarPU interfacing module
  18. use codelets
  19. implicit none
  20. real(8), dimension(:), allocatable, target :: va
  21. integer, dimension(:), allocatable, target :: vb
  22. integer :: i
  23. type(c_ptr) :: cl1 ! a pointer for the codelet structure
  24. type(c_ptr) :: dh_va ! a pointer for the 'va' vector data handle
  25. type(c_ptr) :: dh_vb ! a pointer for the 'vb' vector data handle
  26. allocate(va(5))
  27. va = (/ (i,i=1,5) /)
  28. allocate(vb(7))
  29. vb = (/ (i,i=1,7) /)
  30. ! initialize StarPU with default settings
  31. call fstarpu_init()
  32. ! allocate an empty codelet structure
  33. cl1 = fstarpu_codelet_allocate()
  34. ! add a CPU implementation function to the codelet
  35. call fstarpu_codelet_add_cpu_func(cl1, C_FUNLOC(cl_cpu_func1))
  36. ! add a Read-only mode data buffer to the codelet
  37. call fstarpu_codelet_add_buffer(cl1, FSTARPU_R)
  38. ! add a Read-Write mode data buffer to the codelet
  39. call fstarpu_codelet_add_buffer(cl1, FSTARPU_RW)
  40. ! register 'va', a vector of real(8) elements
  41. dh_va = fstarpu_vector_data_register(c_loc(va), 1+ubound(va,1)-lbound(va,1), c_sizeof(va(lbound(va,1))), 0)
  42. ! register 'vb', a vector of integer elements
  43. dh_vb = fstarpu_vector_data_register(c_loc(vb), 1+ubound(vb,1)-lbound(vb,1), c_sizeof(vb(lbound(vb,1))), 0)
  44. ! insert a task with codelet cl1, and vectors 'va' and 'vb'
  45. !
  46. ! Note: The array argument must follow the layout:
  47. ! (/
  48. ! <codelet_ptr>,
  49. ! [<argument_type> [<argument_value(s)],]
  50. ! . . .
  51. ! C_NULL_PTR
  52. ! )/
  53. !
  54. ! Note: The argument type for data handles is FSTARPU_DATA, regardless
  55. ! of the buffer access mode (specified in the codelet)
  56. call fstarpu_insert_task((/ cl1, FSTARPU_DATA, dh_va, FSTARPU_DATA, dh_vb, C_NULL_PTR /))
  57. ! wait for task completion
  58. call fstarpu_task_wait_for_all()
  59. ! unregister 'va'
  60. call fstarpu_data_unregister(dh_va)
  61. ! unregister 'vb'
  62. call fstarpu_data_unregister(dh_vb)
  63. ! free codelet structure
  64. call fstarpu_codelet_free(cl1)
  65. ! shut StarPU down
  66. call fstarpu_shutdown()
  67. deallocate(vb)
  68. deallocate(va)
  69. end program native_fortran_example