nf_varbuf.f90 3.0 KB

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