partition_init.c 2.6 KB

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