readers_and_writers.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * StarPU
  3. * Copyright (C) INRIA 2008-2009 (see AUTHORS file)
  4. *
  5. * This program 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. * This program 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. #include <starpu.h>
  17. static unsigned book = 0;
  18. static starpu_data_handle book_handle;
  19. static void dummy_kernel(void *descr[], void *arg)
  20. {
  21. }
  22. static starpu_codelet rw_cl = {
  23. .where = STARPU_CPU|STARPU_CUDA,
  24. .cuda_func = dummy_kernel,
  25. .cpu_func = dummy_kernel,
  26. .nbuffers = 1
  27. };
  28. int main(int argc, char **argv)
  29. {
  30. starpu_init(NULL);
  31. /* initialize the resource */
  32. starpu_register_vector_data(&book_handle, 0, (uintptr_t)&book, 1, sizeof(unsigned));
  33. unsigned ntasks = 16*1024;
  34. unsigned t;
  35. for (t = 0; t < ntasks; t++)
  36. {
  37. struct starpu_task *task = starpu_task_create();
  38. task->cl = &rw_cl;
  39. /* we randomly select either a reader or a writer (give 10
  40. * times more chances to be a reader) */
  41. task->buffers[0].mode = ((rand() % 10)==0)?STARPU_W:STARPU_R;
  42. task->buffers[0].handle = book_handle;
  43. int ret = starpu_submit_task(task);
  44. STARPU_ASSERT(!ret);
  45. }
  46. starpu_wait_all_tasks();
  47. starpu_shutdown();
  48. return 0;
  49. }