partition_init.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019 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 <stdio.h>
  17. #include <starpu.h>
  18. #include "../helper.h"
  19. void my_func(void *buffers[], void *cl_arg)
  20. {
  21. unsigned nb = STARPU_VECTOR_GET_NX(buffers[0]);
  22. int *v = (int *)STARPU_VECTOR_GET_PTR(buffers[0]);
  23. unsigned i;
  24. for(i=0 ; i<nb ; i++)
  25. {
  26. v[i] = i+42;
  27. FPRINTF(stderr, "setting v[%d] to %d\n",i, v[i]);
  28. }
  29. }
  30. struct starpu_codelet my_codelet =
  31. {
  32. .cpu_funcs = {my_func},
  33. .nbuffers = 1,
  34. .modes = {STARPU_W}
  35. };
  36. void display_func(void *buffers[], void *cl_arg)
  37. {
  38. unsigned nb = STARPU_VECTOR_GET_NX(buffers[0]);
  39. int *v = (int *)STARPU_VECTOR_GET_PTR(buffers[0]);
  40. unsigned i;
  41. for(i=0 ; i<nb ; i++) FPRINTF(stderr, "v[%d] = %d\n", i, v[i]);
  42. }
  43. struct starpu_codelet display_codelet =
  44. {
  45. .cpu_funcs = {display_func},
  46. .nbuffers = 1,
  47. .modes = {STARPU_R}
  48. };
  49. int main(int argc, char **argv)
  50. {
  51. int ret = starpu_initialize(NULL, &argc, &argv);
  52. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  53. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  54. if (starpu_cpu_worker_get_count() == 0)
  55. {
  56. FPRINTF(stderr, "The test needs at least 1 CPU worker\n");
  57. starpu_shutdown();
  58. return STARPU_TEST_SKIPPED;
  59. }
  60. struct starpu_data_filter f =
  61. {
  62. .filter_func = starpu_vector_filter_block,
  63. .nchildren = starpu_cpu_worker_get_count()
  64. };
  65. starpu_data_handle_t array_handle;
  66. starpu_vector_data_register(&array_handle, -1, (uintptr_t)NULL, f.nchildren*2, sizeof(int));
  67. starpu_data_partition(array_handle, &f);
  68. int i;
  69. for(i=0 ; i<starpu_data_get_nb_children(array_handle) ; i++)
  70. {
  71. starpu_data_handle_t sub_handle = starpu_data_get_sub_data(array_handle, 1, i);
  72. ret = starpu_task_insert(&my_codelet,
  73. STARPU_W, sub_handle,
  74. 0);
  75. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  76. }
  77. starpu_data_unpartition(array_handle, STARPU_MAIN_RAM);
  78. ret = starpu_task_insert(&display_codelet,
  79. STARPU_R, array_handle,
  80. 0);
  81. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  82. starpu_data_unregister(array_handle);
  83. starpu_shutdown();
  84. }