nf_varbuf.f90 3.0 KB

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