nf_dynbuf.f90 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ! StarPU --- Runtime system for heterogeneous multicore architectures.
  2. !
  3. ! Copyright (C) 2016-2020 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_dynbuf
  17. use iso_c_binding ! C interfacing module
  18. use fstarpu_mod ! StarPU interfacing module
  19. use nf_dynbuf_cl
  20. implicit none
  21. type(c_ptr) :: cl_dynbuf_big ! 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. var = 42
  30. ! initialize StarPU with default settings
  31. err = fstarpu_init(C_NULL_PTR)
  32. if (err == -19) then
  33. stop 77
  34. end if
  35. ! stop there if no CPU worker available
  36. ncpu = fstarpu_cpu_worker_get_count()
  37. if (ncpu == 0) then
  38. call fstarpu_shutdown()
  39. stop 77
  40. end if
  41. ! allocate an empty codelet structure
  42. cl_dynbuf_big = fstarpu_codelet_allocate()
  43. call fstarpu_codelet_set_name(cl_dynbuf_big, C_CHAR_"dummy_big_kernel"//C_NULL_CHAR)
  44. call fstarpu_codelet_add_cpu_func(cl_dynbuf_big, C_FUNLOC(cl_cpu_func_dynbuf_big))
  45. write(*,*) "FSTARPU_NMAXBUFS",FSTARPU_NMAXBUFS
  46. nbuffers = FSTARPU_NMAXBUFS+1
  47. call fstarpu_codelet_set_nbuffers(cl_dynbuf_big, nbuffers)
  48. call fstarpu_variable_data_register(dh_var, 0, c_loc(var), c_sizeof(var))
  49. descrs_var = fstarpu_data_descr_array_alloc(nbuffers)
  50. do i=0,nbuffers-1
  51. call fstarpu_data_descr_array_set(descrs_var, i, dh_var, FSTARPU_RW)
  52. end do
  53. call fstarpu_insert_task((/ cl_dynbuf_big, &
  54. FSTARPU_VALUE, c_loc(nbuffers), FSTARPU_SZ_C_INT, &
  55. FSTARPU_DATA_MODE_ARRAY, descrs_var, c_loc(nbuffers), &
  56. C_NULL_PTR /))
  57. call fstarpu_task_wait_for_all()
  58. call fstarpu_data_descr_array_free(descrs_var)
  59. call fstarpu_data_unregister(dh_var)
  60. ! free codelet structure
  61. call fstarpu_codelet_free(cl_dynbuf_big)
  62. ! shut StarPU down
  63. call fstarpu_shutdown()
  64. end program nf_dynbuf