nf_varbuf.f90 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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_varbuf
  16. use iso_c_binding ! C interfacing module
  17. use fstarpu_mod ! StarPU interfacing module
  18. use nf_varbuf_cl
  19. implicit none
  20. type(c_ptr) :: cl_varbuf ! a pointer for the codelet structure
  21. type(c_ptr) :: dh_var
  22. type(c_ptr) :: descrs_var
  23. integer(c_int),target :: nbuffers
  24. integer(c_int) :: err ! return status for fstarpu_init
  25. integer(c_int) :: ncpu ! number of cpus workers
  26. integer(c_int),target :: var
  27. integer(c_int) :: i
  28. integer(c_int), parameter :: nb_buf_begin = 1
  29. integer(c_int), parameter :: nb_buf_end = 8
  30. var = 42
  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. ! stop there if no CPU worker available
  37. ncpu = fstarpu_cpu_worker_get_count()
  38. if (ncpu == 0) then
  39. call fstarpu_shutdown()
  40. stop 77
  41. end if
  42. ! allocate an empty codelet structure
  43. cl_varbuf = fstarpu_codelet_allocate()
  44. call fstarpu_codelet_set_name(cl_varbuf, C_CHAR_"dummy_kernel"//C_NULL_CHAR)
  45. call fstarpu_codelet_add_cpu_func(cl_varbuf, C_FUNLOC(cl_cpu_func_varbuf))
  46. ! mark codelet as accepting a variable set of buffers
  47. call fstarpu_codelet_set_variable_nbuffers(cl_varbuf)
  48. call fstarpu_variable_data_register(dh_var, 0, c_loc(var), c_sizeof(var))
  49. do nbuffers = nb_buf_begin, nb_buf_end
  50. write(*,*) "nbuffers=", nbuffers
  51. descrs_var = fstarpu_data_descr_array_alloc(nbuffers)
  52. do i=0,nbuffers-1
  53. call fstarpu_data_descr_array_set(descrs_var, i, dh_var, FSTARPU_RW)
  54. end do
  55. call fstarpu_insert_task((/ cl_varbuf, &
  56. FSTARPU_VALUE, c_loc(nbuffers), FSTARPU_SZ_C_INT, &
  57. FSTARPU_DATA_MODE_ARRAY, descrs_var, c_loc(nbuffers), &
  58. C_NULL_PTR /))
  59. call fstarpu_data_descr_array_free(descrs_var)
  60. end do
  61. call fstarpu_task_wait_for_all()
  62. call fstarpu_data_unregister(dh_var)
  63. ! free codelet structure
  64. call fstarpu_codelet_free(cl_varbuf)
  65. ! shut StarPU down
  66. call fstarpu_shutdown()
  67. end program nf_varbuf