insert_task.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Centre National de la Recherche Scientifique
  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. #include <starpu.h>
  17. void func_cpu(void *descr[], __attribute__ ((unused)) void *_args)
  18. {
  19. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  20. int *x1 = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  21. *x0 = *x0 * 10;
  22. *x1 = *x1 * 10;
  23. }
  24. starpu_codelet mycodelet = {
  25. .where = STARPU_CPU,
  26. .cpu_func = func_cpu,
  27. .nbuffers = 2
  28. };
  29. int main(int argc, char **argv)
  30. {
  31. int x[2];
  32. int i;
  33. starpu_data_handle data_handles[2];
  34. starpu_init(NULL);
  35. for(i=0 ; i<2 ; i++) {
  36. x[i] = 10*(i+1);
  37. starpu_variable_data_register(&data_handles[i], 0, (uintptr_t)&x[i], sizeof(x[i]));
  38. }
  39. starpu_insert_task(&mycodelet,
  40. STARPU_RW, data_handles[0], STARPU_RW, data_handles[1],
  41. 0);
  42. starpu_task_wait_for_all();
  43. for(i=0 ; i<2 ; i++) {
  44. starpu_data_acquire(data_handles[i], STARPU_R);
  45. }
  46. fprintf(stderr, "VALUES: %d %d\n", x[0], x[1]);
  47. starpu_shutdown();
  48. return 0;
  49. }