insert_task_array.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_array(&mycodelet, 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_insert_task");
  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. FPRINTF(stderr, "VALUES: %d %f\n", x, f);
  71. ret = !(x == 12 && f == 24.0);
  72. STARPU_RETURN(ret);
  73. }
  74. }