temporary_partition.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 clw =
  28. {
  29. .where = STARPU_CPU,
  30. .cpu_funcs = {codelet},
  31. .nbuffers = 1,
  32. .modes = {STARPU_W}
  33. };
  34. static struct starpu_codelet clr =
  35. {
  36. .where = STARPU_CPU,
  37. .cpu_funcs = {codelet},
  38. .nbuffers = 1,
  39. .modes = {STARPU_R}
  40. };
  41. int main(int argc, char **argv)
  42. {
  43. int ret;
  44. starpu_data_handle_t handle, handles[NPARTS];
  45. int i;
  46. ret = starpu_init(NULL);
  47. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  48. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  49. starpu_vector_data_register(&handle, -1, 0, SIZE, sizeof(char));
  50. /* Fork */
  51. struct starpu_data_filter f =
  52. {
  53. .filter_func = starpu_vector_filter_block,
  54. .nchildren = NPARTS
  55. };
  56. starpu_data_partition_plan(handle, &f, handles);
  57. starpu_data_partition_submit(handle, NPARTS, handles);
  58. /* Process in parallel */
  59. for (i = 0; i < NPARTS; i++)
  60. {
  61. ret = starpu_task_insert(&clw,
  62. STARPU_W, handles[i],
  63. 0);
  64. if (ret == -ENODEV) goto enodev;
  65. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  66. }
  67. /* Invalidate one random piece we don't care coherency about */
  68. starpu_data_invalidate_submit(handles[NPARTS/2]);
  69. /* Join */
  70. starpu_data_unpartition_submit(handle, NPARTS, handles, -1);
  71. starpu_data_partition_clean(handle, NPARTS, handles);
  72. /* Read result */
  73. starpu_task_insert(&clr, STARPU_R, handle, 0);
  74. starpu_data_unregister(handle);
  75. starpu_shutdown();
  76. return 0;
  77. enodev:
  78. starpu_data_unpartition_submit(handle, NPARTS, handles, -1);
  79. starpu_data_partition_clean(handle, NPARTS, handles);
  80. starpu_data_unregister(handle);
  81. starpu_shutdown();
  82. /* yes, we do not perform the computation but we did detect that no one
  83. * could perform the kernel, so this is not an error from StarPU */
  84. fprintf(stderr, "WARNING: No one can execute this task\n");
  85. return STARPU_TEST_SKIPPED;
  86. }