readers_and_writers.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010 Centre National de la Recherche Scientifique
  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. #include <starpu.h>
  18. static unsigned book = 0;
  19. static starpu_data_handle book_handle;
  20. static void dummy_kernel(void *descr[], void *arg)
  21. {
  22. }
  23. static starpu_codelet rw_cl = {
  24. .where = STARPU_CPU|STARPU_CUDA|STARPU_OPENCL,
  25. .cuda_func = dummy_kernel,
  26. .cpu_func = dummy_kernel,
  27. .opencl_func = dummy_kernel,
  28. .nbuffers = 1
  29. };
  30. int main(int argc, char **argv)
  31. {
  32. starpu_init(NULL);
  33. /* initialize the resource */
  34. starpu_vector_data_register(&book_handle, 0, (uintptr_t)&book, 1, sizeof(unsigned));
  35. unsigned ntasks = 16*1024;
  36. unsigned t;
  37. for (t = 0; t < ntasks; t++)
  38. {
  39. struct starpu_task *task = starpu_task_create();
  40. task->cl = &rw_cl;
  41. /* we randomly select either a reader or a writer (give 10
  42. * times more chances to be a reader) */
  43. task->buffers[0].mode = ((rand() % 10)==0)?STARPU_W:STARPU_R;
  44. task->buffers[0].handle = book_handle;
  45. int ret = starpu_task_submit(task);
  46. STARPU_ASSERT(!ret);
  47. }
  48. starpu_task_wait_for_all();
  49. starpu_shutdown();
  50. return 0;
  51. }