temporary_partition.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-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 <starpu.h>
  17. #include "../helper.h"
  18. #define SIZE (1<<20)
  19. #define NPARTS 16
  20. /*
  21. * Test asynchronous partitioning on a temporary data.
  22. */
  23. static void codelet(void *descr[], void *_args)
  24. {
  25. (void)descr;
  26. (void)_args;
  27. }
  28. static struct starpu_codelet clw =
  29. {
  30. .where = STARPU_CPU,
  31. .cpu_funcs = {codelet},
  32. .nbuffers = 1,
  33. .modes = {STARPU_W}
  34. };
  35. static struct starpu_codelet clr =
  36. {
  37. .where = STARPU_CPU,
  38. .cpu_funcs = {codelet},
  39. .nbuffers = 1,
  40. .modes = {STARPU_R}
  41. };
  42. int main(void)
  43. {
  44. int ret;
  45. starpu_data_handle_t handle, handles[NPARTS];
  46. int i;
  47. ret = starpu_init(NULL);
  48. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  49. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  50. starpu_vector_data_register(&handle, -1, 0, SIZE, sizeof(char));
  51. /* Fork */
  52. struct starpu_data_filter f =
  53. {
  54. .filter_func = starpu_vector_filter_block,
  55. .nchildren = NPARTS
  56. };
  57. starpu_data_partition_plan(handle, &f, handles);
  58. starpu_data_partition_submit(handle, NPARTS, handles);
  59. /* Process in parallel */
  60. for (i = 0; i < NPARTS; i++)
  61. {
  62. ret = starpu_task_insert(&clw,
  63. STARPU_W, handles[i],
  64. 0);
  65. if (ret == -ENODEV) goto enodev;
  66. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  67. }
  68. /* Invalidate one random piece we don't care coherency about */
  69. starpu_data_invalidate_submit(handles[NPARTS/2]);
  70. /* Try to wontuse the whole thing */
  71. starpu_data_wont_use(handle);
  72. /* Clean */
  73. starpu_data_unpartition_submit(handle, NPARTS, handles, -1);
  74. starpu_data_partition_clean(handle, NPARTS, handles);
  75. /* Read result */
  76. starpu_task_insert(&clr, STARPU_R, handle, 0);
  77. starpu_data_unregister(handle);
  78. starpu_shutdown();
  79. return 0;
  80. enodev:
  81. starpu_data_unpartition_submit(handle, NPARTS, handles, -1);
  82. starpu_data_partition_clean(handle, NPARTS, handles);
  83. starpu_data_unregister(handle);
  84. starpu_shutdown();
  85. /* yes, we do not perform the computation but we did detect that no one
  86. * could perform the kernel, so this is not an error from StarPU */
  87. fprintf(stderr, "WARNING: No one can execute this task\n");
  88. return STARPU_TEST_SKIPPED;
  89. }