nf_dynbuf.f90 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_dynbuf
  18. use iso_c_binding ! C interfacing module
  19. use fstarpu_mod ! StarPU interfacing module
  20. use nf_dynbuf_cl
  21. implicit none
  22. type(c_ptr) :: cl_dynbuf_big ! 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. 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_dynbuf_big = fstarpu_codelet_allocate()
  44. call fstarpu_codelet_set_name(cl_dynbuf_big, C_CHAR_"dummy_big_kernel"//C_NULL_CHAR)
  45. call fstarpu_codelet_add_cpu_func(cl_dynbuf_big, C_FUNLOC(cl_cpu_func_dynbuf_big))
  46. write(*,*) "FSTARPU_NMAXBUFS",FSTARPU_NMAXBUFS
  47. nbuffers = FSTARPU_NMAXBUFS+1
  48. call fstarpu_codelet_set_nbuffers(cl_dynbuf_big, nbuffers)
  49. call fstarpu_variable_data_register(dh_var, 0, c_loc(var), c_sizeof(var))
  50. descrs_var = fstarpu_data_descr_array_alloc(nbuffers)
  51. do i=0,nbuffers-1
  52. call fstarpu_data_descr_array_set(descrs_var, i, dh_var, FSTARPU_RW)
  53. end do
  54. call fstarpu_insert_task((/ cl_dynbuf_big, &
  55. FSTARPU_VALUE, c_loc(nbuffers), FSTARPU_SZ_C_INT, &
  56. FSTARPU_DATA_MODE_ARRAY, descrs_var, c_loc(nbuffers), &
  57. C_NULL_PTR /))
  58. call fstarpu_task_wait_for_all()
  59. call fstarpu_data_descr_array_free(descrs_var)
  60. call fstarpu_data_unregister(dh_var)
  61. ! free codelet structure
  62. call fstarpu_codelet_free(cl_dynbuf_big)
  63. ! shut StarPU down
  64. call fstarpu_shutdown()
  65. end program nf_dynbuf