nf_dynbuf.f90 2.7 KB

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