readers_and_writers.c 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * StarPU
  3. * Copyright (C) Université Bordeaux 1, CNRS 2008-2010 (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|STARPU_OPENCL,
  24. .cuda_func = dummy_kernel,
  25. .cpu_func = dummy_kernel,
  26. .opencl_func = dummy_kernel,
  27. .nbuffers = 1
  28. };
  29. int main(int argc, char **argv)
  30. {
  31. starpu_init(NULL);
  32. /* initialize the resource */
  33. starpu_vector_data_register(&book_handle, 0, (uintptr_t)&book, 1, sizeof(unsigned));
  34. unsigned ntasks = 16*1024;
  35. unsigned t;
  36. for (t = 0; t < ntasks; t++)
  37. {
  38. struct starpu_task *task = starpu_task_create();
  39. task->cl = &rw_cl;
  40. /* we randomly select either a reader or a writer (give 10
  41. * times more chances to be a reader) */
  42. task->buffers[0].mode = ((rand() % 10)==0)?STARPU_W:STARPU_R;
  43. task->buffers[0].handle = book_handle;
  44. int ret = starpu_task_submit(task);
  45. STARPU_ASSERT(!ret);
  46. }
  47. starpu_task_wait_for_all();
  48. starpu_shutdown();
  49. return 0;
  50. }