insert_task.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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[], void *_args)
  18. {
  19. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  20. float *x1 = (int *)STARPU_VARIABLE_GET_PTR(descr[1]);
  21. int ifactor;
  22. float ffactor;
  23. starpu_unpack_cl_args(_args, &ifactor, &ffactor);
  24. *x0 = *x0 * ifactor;
  25. *x1 = *x1 * ffactor;
  26. }
  27. starpu_codelet mycodelet = {
  28. .where = STARPU_CPU,
  29. .cpu_func = func_cpu,
  30. .nbuffers = 2
  31. };
  32. int main(int argc, char **argv)
  33. {
  34. int x; float f;
  35. int i;
  36. int ifactor=15;
  37. float ffactor=25.0;
  38. starpu_data_handle data_handles[2];
  39. starpu_init(NULL);
  40. x = 10;
  41. starpu_variable_data_register(&data_handles[0], 0, (uintptr_t)&x, sizeof(x));
  42. f = 20.0;
  43. starpu_variable_data_register(&data_handles[1], 0, (uintptr_t)&f, sizeof(f));
  44. fprintf(stderr, "VALUES: %d %f\n", x, f);
  45. starpu_insert_task(&mycodelet,
  46. STARPU_VALUE, &ifactor, sizeof(ifactor),
  47. STARPU_VALUE, &ffactor, sizeof(ffactor),
  48. STARPU_RW, data_handles[0], STARPU_RW, data_handles[1],
  49. 0);
  50. starpu_task_wait_for_all();
  51. for(i=0 ; i<2 ; i++) {
  52. starpu_data_acquire(data_handles[i], STARPU_R);
  53. }
  54. fprintf(stderr, "VALUES: %d %f\n", x, f);
  55. starpu_shutdown();
  56. return 0;
  57. }