insert_task_array.c 2.4 KB

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