temporary_partition_implicit.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010,2013,2014,2016,2017 Université de Bordeaux
  4. * Copyright (C) 2012,2013 Inria
  5. * Copyright (C) 2010-2013,2015,2017 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. #define SIZE (1<<20)
  21. #define NPARTS 16
  22. /*
  23. * Test asynchronous partitioning on a temporary data without submitting explit
  24. * partitioning/unpartitioning.
  25. */
  26. static void codelet(void *descr[], void *_args)
  27. {
  28. (void)descr;
  29. (void)_args;
  30. }
  31. static struct starpu_codelet clw =
  32. {
  33. .where = STARPU_CPU,
  34. .cpu_funcs = {codelet},
  35. .nbuffers = 1,
  36. .modes = {STARPU_W}
  37. };
  38. static struct starpu_codelet clr =
  39. {
  40. .where = STARPU_CPU,
  41. .cpu_funcs = {codelet},
  42. .nbuffers = 1,
  43. .modes = {STARPU_R}
  44. };
  45. int main(void)
  46. {
  47. int ret;
  48. starpu_data_handle_t handle, handles[NPARTS];
  49. int i;
  50. ret = starpu_init(NULL);
  51. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  52. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  53. starpu_vector_data_register(&handle, -1, 0, SIZE, sizeof(char));
  54. /* Fork */
  55. struct starpu_data_filter f =
  56. {
  57. .filter_func = starpu_vector_filter_block,
  58. .nchildren = NPARTS
  59. };
  60. starpu_data_partition_plan(handle, &f, handles);
  61. /* Process in parallel */
  62. for (i = 0; i < NPARTS; i++)
  63. {
  64. ret = starpu_task_insert(&clw,
  65. STARPU_W, handles[i],
  66. 0);
  67. if (ret == -ENODEV) goto enodev;
  68. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  69. }
  70. /* Invalidate one random piece we don't care coherency about */
  71. starpu_data_invalidate_submit(handles[NPARTS/2]);
  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. }