insert_task_array.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013 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 <config.h>
  17. #include <starpu.h>
  18. #include "../helper.h"
  19. void func_cpu(void *descr[], void *_args)
  20. {
  21. int *x0 = (int *)STARPU_VARIABLE_GET_PTR(descr[0]);
  22. float *x1 = (float *)STARPU_VARIABLE_GET_PTR(descr[1]);
  23. int factor;
  24. starpu_codelet_unpack_args(_args, &factor);
  25. *x0 = *x0 * factor;
  26. *x1 = *x1 * (float)factor;
  27. }
  28. struct starpu_codelet mycodelet =
  29. {
  30. .modes = { STARPU_RW, STARPU_RW },
  31. .cpu_funcs = {func_cpu, NULL},
  32. .nbuffers = 2
  33. };
  34. int main(int argc, char **argv)
  35. {
  36. int x; float f;
  37. int factor=12;
  38. int i, ret;
  39. starpu_data_handle_t data_handles[2];
  40. ret = starpu_init(NULL);
  41. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  42. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  43. x = 1;
  44. starpu_variable_data_register(&data_handles[0], STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  45. f = 2.0;
  46. starpu_variable_data_register(&data_handles[1], STARPU_MAIN_RAM, (uintptr_t)&f, sizeof(f));
  47. ret = starpu_task_insert(&mycodelet,
  48. STARPU_DATA_ARRAY, data_handles, 2,
  49. STARPU_VALUE, &factor, sizeof(factor),
  50. STARPU_PRIORITY, 1,
  51. 0);
  52. if (ret == -ENODEV) goto enodev;
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  54. ret = starpu_task_wait_for_all();
  55. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  56. enodev:
  57. for(i=0 ; i<2 ; i++)
  58. {
  59. starpu_data_unregister(data_handles[i]);
  60. }
  61. starpu_shutdown();
  62. if (ret == -ENODEV)
  63. {
  64. fprintf(stderr, "WARNING: No one can execute this task\n");
  65. /* yes, we do not perform the computation but we did detect that no one
  66. * could perform the kernel, so this is not an error from StarPU */
  67. return STARPU_TEST_SKIPPED;
  68. }
  69. else
  70. {
  71. FPRINTF(stderr, "VALUES: %d %f\n", x, f);
  72. ret = !(x == 12 && f == 24.0);
  73. return ret;
  74. }
  75. }