locality.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016 Université de Bordeaux
  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. /*
  17. * This is a dumb sample of stencil application
  18. *
  19. * Dumb domain split in N pieces:
  20. *
  21. * 0 | 1 | ... | N-1
  22. *
  23. * for each simulation iteration, a task works on some adjactent pieces
  24. *
  25. * Locality is thus set on the central piece.
  26. */
  27. #include <starpu.h>
  28. #include "../helper.h"
  29. #define N 50
  30. #define ITER 50
  31. int task_worker[N][ITER];
  32. void cpu_f(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *_args)
  33. {
  34. unsigned i, loop;
  35. starpu_codelet_unpack_args(_args, &loop, &i);
  36. task_worker[i][loop] = starpu_worker_get_id();
  37. starpu_sleep(0.001);
  38. }
  39. static struct starpu_codelet cl =
  40. {
  41. .cpu_funcs = { cpu_f },
  42. .cpu_funcs_name = { "cpu_f" },
  43. .nbuffers = 3,
  44. .modes =
  45. {
  46. STARPU_RW | STARPU_COMMUTE | STARPU_LOCALITY,
  47. STARPU_RW | STARPU_COMMUTE | STARPU_LOCALITY,
  48. STARPU_RW | STARPU_COMMUTE | STARPU_LOCALITY,
  49. },
  50. };
  51. int main(int argc, char *argv[])
  52. {
  53. int ret;
  54. starpu_data_handle_t A[N];
  55. unsigned i, loop;
  56. ret = starpu_initialize(NULL, &argc, &argv);
  57. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  59. /* Get most parallelism by using an arbiter */
  60. starpu_arbiter_t arbiter = starpu_arbiter_create();
  61. for (i = 0; i < N; i++)
  62. {
  63. starpu_void_data_register(&A[i]);
  64. starpu_data_assign_arbiter(A[i], arbiter);
  65. }
  66. for (loop = 0; loop < ITER; loop++)
  67. {
  68. for (i = 1; i < N-1; i++)
  69. {
  70. starpu_task_insert(&cl,
  71. STARPU_RW | STARPU_COMMUTE | STARPU_LOCALITY, A[i-1],
  72. STARPU_RW | STARPU_COMMUTE | STARPU_LOCALITY, A[i],
  73. STARPU_RW | STARPU_COMMUTE | STARPU_LOCALITY, A[i+1],
  74. STARPU_VALUE, &loop, sizeof(loop),
  75. STARPU_VALUE, &i, sizeof(i),
  76. 0);
  77. }
  78. }
  79. starpu_task_wait_for_all();
  80. for (loop = 0; loop < ITER; loop++)
  81. {
  82. for (i = 1; i < N-1; i++)
  83. {
  84. printf("%d ", task_worker[i][loop]);
  85. }
  86. printf("\n");
  87. }
  88. starpu_shutdown();
  89. return EXIT_SUCCESS;
  90. }