temporary_partition.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010, 2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013 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[], STARPU_ATTRIBUTE_UNUSED void *_args)
  25. {
  26. }
  27. static struct starpu_codelet clrw =
  28. {
  29. .where = STARPU_CPU,
  30. .cpu_funcs = {codelet},
  31. .nbuffers = 1,
  32. .modes = {STARPU_RW}
  33. };
  34. static struct starpu_codelet clw =
  35. {
  36. .where = STARPU_CPU,
  37. .cpu_funcs = {codelet},
  38. .nbuffers = 1,
  39. .modes = {STARPU_W}
  40. };
  41. static struct starpu_codelet clr =
  42. {
  43. .where = STARPU_CPU,
  44. .cpu_funcs = {codelet},
  45. .nbuffers = 1,
  46. .modes = {STARPU_R}
  47. };
  48. int main(int argc, char **argv)
  49. {
  50. int ret;
  51. starpu_data_handle_t handle, handles[NPARTS];
  52. int i;
  53. ret = starpu_init(NULL);
  54. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  55. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  56. starpu_vector_data_register(&handle, -1, 0, SIZE, sizeof(char));
  57. /* Fill temporary */
  58. starpu_task_insert(&clw, STARPU_W, handle, 0);
  59. /* Fork */
  60. struct starpu_data_filter f =
  61. {
  62. .filter_func = starpu_vector_filter_block,
  63. .nchildren = NPARTS
  64. };
  65. starpu_data_partition_plan(handle, &f, handles);
  66. starpu_data_partition_submit(handle, NPARTS, handles);
  67. /* Process in parallel */
  68. for (i = 0; i < NPARTS; i++)
  69. {
  70. ret = starpu_task_insert(&clrw,
  71. STARPU_RW, handles[i],
  72. 0);
  73. if (ret == -ENODEV) goto enodev;
  74. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  75. }
  76. /* Join */
  77. starpu_data_unpartition_submit(handle, NPARTS, handles, -1);
  78. starpu_data_partition_clean(handle, NPARTS, handles);
  79. /* Read result */
  80. starpu_task_insert(&clr, STARPU_R, handle, 0);
  81. starpu_data_unregister(handle);
  82. starpu_shutdown();
  83. return 0;
  84. enodev:
  85. starpu_data_unpartition_submit(handle, NPARTS, handles, -1);
  86. starpu_data_partition_clean(handle, NPARTS, handles);
  87. starpu_data_unregister(handle);
  88. starpu_shutdown();
  89. /* yes, we do not perform the computation but we did detect that no one
  90. * could perform the kernel, so this is not an error from StarPU */
  91. fprintf(stderr, "WARNING: No one can execute this task\n");
  92. return STARPU_TEST_SKIPPED;
  93. }