nf_vector.f90 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 nf_vector
  16. use iso_c_binding ! C interfacing module
  17. use fstarpu_mod ! StarPU interfacing module
  18. use nf_codelets
  19. implicit none
  20. real(8), dimension(:), allocatable, target :: va
  21. integer, dimension(:), allocatable, target :: vb
  22. integer :: i
  23. type(c_ptr) :: cl_vec ! 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. integer(c_int) :: err ! return status for fstarpu_init
  27. allocate(va(5))
  28. va = (/ (i,i=1,5) /)
  29. allocate(vb(7))
  30. vb = (/ (i,i=1,7) /)
  31. ! initialize StarPU with default settings
  32. err = fstarpu_init(C_NULL_PTR)
  33. if (err == -19) then
  34. stop 77
  35. end if
  36. ! allocate an empty codelet structure
  37. cl_vec = fstarpu_codelet_allocate()
  38. ! add a CPU implementation function to the codelet
  39. call fstarpu_codelet_add_cpu_func(cl_vec, C_FUNLOC(cl_cpu_func_vec))
  40. ! add a Read-only mode data buffer to the codelet
  41. call fstarpu_codelet_add_buffer(cl_vec, FSTARPU_R)
  42. ! add a Read-Write mode data buffer to the codelet
  43. call fstarpu_codelet_add_buffer(cl_vec, FSTARPU_RW)
  44. ! register 'va', a vector of real(8) elements
  45. dh_va = fstarpu_vector_data_register(c_loc(va), 1+ubound(va,1)-lbound(va,1), c_sizeof(va(lbound(va,1))), 0)
  46. ! register 'vb', a vector of integer elements
  47. dh_vb = fstarpu_vector_data_register(c_loc(vb), 1+ubound(vb,1)-lbound(vb,1), c_sizeof(vb(lbound(vb,1))), 0)
  48. ! insert a task with codelet cl_vec, and vectors 'va' and 'vb'
  49. !
  50. ! Note: The array argument must follow the layout:
  51. ! (/
  52. ! <codelet_ptr>,
  53. ! [<argument_type> [<argument_value(s)],]
  54. ! . . .
  55. ! C_NULL_PTR
  56. ! )/
  57. !
  58. ! Note: The argument type for data handles is FSTARPU_DATA, regardless
  59. ! of the buffer access mode (specified in the codelet)
  60. call fstarpu_insert_task((/ cl_vec, FSTARPU_DATA, dh_va, FSTARPU_DATA, dh_vb, C_NULL_PTR /))
  61. ! wait for task completion
  62. call fstarpu_task_wait_for_all()
  63. ! unregister 'va'
  64. call fstarpu_data_unregister(dh_va)
  65. ! unregister 'vb'
  66. call fstarpu_data_unregister(dh_vb)
  67. ! free codelet structure
  68. call fstarpu_codelet_free(cl_vec)
  69. ! shut StarPU down
  70. call fstarpu_shutdown()
  71. deallocate(vb)
  72. deallocate(va)
  73. end program nf_vector