insert_task_array.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011, 2012, 2013 CNRS
  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},
  32. .cpu_funcs_name = {"func_cpu"},
  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], STARPU_MAIN_RAM, (uintptr_t)&x, sizeof(x));
  46. f = 2.0;
  47. starpu_variable_data_register(&data_handles[1], STARPU_MAIN_RAM, (uintptr_t)&f, sizeof(f));
  48. ret = starpu_task_insert(&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_task_insert");
  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. {
  72. FPRINTF(stderr, "VALUES: %d %f\n", x, f);
  73. ret = !(x == 12 && f == 24.0);
  74. return ret;
  75. }
  76. }