temporary_partition.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013, 2017 CNRS
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include "../helper.h"
  19. #define SIZE (1<<20)
  20. #define NPARTS 16
  21. /*
  22. * Test asynchronous partitioning on a temporary data.
  23. */
  24. static void codelet(void *descr[], void *_args)
  25. {
  26. (void)descr;
  27. (void)_args;
  28. }
  29. static struct starpu_codelet clw =
  30. {
  31. .where = STARPU_CPU,
  32. .cpu_funcs = {codelet},
  33. .nbuffers = 1,
  34. .modes = {STARPU_W}
  35. };
  36. static struct starpu_codelet clr =
  37. {
  38. .where = STARPU_CPU,
  39. .cpu_funcs = {codelet},
  40. .nbuffers = 1,
  41. .modes = {STARPU_R}
  42. };
  43. int main(void)
  44. {
  45. int ret;
  46. starpu_data_handle_t handle, handles[NPARTS];
  47. int i;
  48. ret = starpu_init(NULL);
  49. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  50. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  51. starpu_vector_data_register(&handle, -1, 0, SIZE, sizeof(char));
  52. /* Fork */
  53. struct starpu_data_filter f =
  54. {
  55. .filter_func = starpu_vector_filter_block,
  56. .nchildren = NPARTS
  57. };
  58. starpu_data_partition_plan(handle, &f, handles);
  59. starpu_data_partition_submit(handle, NPARTS, handles);
  60. /* Process in parallel */
  61. for (i = 0; i < NPARTS; i++)
  62. {
  63. ret = starpu_task_insert(&clw,
  64. STARPU_W, handles[i],
  65. 0);
  66. if (ret == -ENODEV) goto enodev;
  67. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  68. }
  69. /* Invalidate one random piece we don't care coherency about */
  70. starpu_data_invalidate_submit(handles[NPARTS/2]);
  71. /* Join */
  72. starpu_data_unpartition_submit(handle, NPARTS, handles, -1);
  73. starpu_data_partition_clean(handle, NPARTS, handles);
  74. /* Read result */
  75. starpu_task_insert(&clr, STARPU_R, handle, 0);
  76. starpu_data_unregister(handle);
  77. starpu_shutdown();
  78. return 0;
  79. enodev:
  80. starpu_data_unpartition_submit(handle, NPARTS, handles, -1);
  81. starpu_data_partition_clean(handle, NPARTS, handles);
  82. starpu_data_unregister(handle);
  83. starpu_shutdown();
  84. /* yes, we do not perform the computation but we did detect that no one
  85. * could perform the kernel, so this is not an error from StarPU */
  86. fprintf(stderr, "WARNING: No one can execute this task\n");
  87. return STARPU_TEST_SKIPPED;
  88. }