in_place_partition.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012,2013 Inria
  4. * Copyright (C) 2012,2013,2017 CNRS
  5. * Copyright (C) 2011-2016 Université de Bordeaux
  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. #include "scal.h"
  21. /*
  22. * Trigger in-place partitioning by prefetching the whole data before
  23. * partitioning
  24. */
  25. int main(int argc, char **argv)
  26. {
  27. unsigned *foo;
  28. starpu_data_handle_t handle;
  29. int ret;
  30. unsigned n, i, size;
  31. ret = starpu_initialize(NULL, &argc, &argv);
  32. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  33. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  34. #ifdef STARPU_USE_OPENCL
  35. ret = starpu_opencl_load_opencl_from_file("tests/datawizard/scal_opencl.cl", &opencl_program, NULL);
  36. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  37. #endif
  38. n = starpu_worker_get_count();
  39. if (n == 1)
  40. {
  41. starpu_shutdown();
  42. return STARPU_TEST_SKIPPED;
  43. }
  44. size = 10 * n;
  45. foo = (unsigned *) calloc(size, sizeof(*foo));
  46. for (i = 0; i < size; i++)
  47. foo[i] = i;
  48. starpu_vector_data_register(&handle, STARPU_MAIN_RAM, (uintptr_t)foo, size, sizeof(*foo));
  49. /* Broadcast the data to force in-place partitioning */
  50. for (i = 0; i < n; i++)
  51. starpu_data_prefetch_on_node(handle, starpu_worker_get_memory_node(i), 0);
  52. struct starpu_data_filter f =
  53. {
  54. .filter_func = starpu_vector_filter_block,
  55. .nchildren = n,
  56. };
  57. starpu_data_partition(handle, &f);
  58. for (i = 0; i < f.nchildren; i++)
  59. {
  60. struct starpu_task *task = starpu_task_create();
  61. task->handles[0] = starpu_data_get_sub_data(handle, 1, i);
  62. task->cl = &scal_codelet;
  63. task->execute_on_a_specific_worker = 1;
  64. task->workerid = i;
  65. ret = starpu_task_submit(task);
  66. if (ret == -ENODEV) goto enodev;
  67. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  68. }
  69. ret = starpu_task_wait_for_all();
  70. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  71. starpu_data_unpartition(handle, STARPU_MAIN_RAM);
  72. starpu_data_unregister(handle);
  73. starpu_shutdown();
  74. ret = EXIT_SUCCESS;
  75. for (i = 0; i < size; i++)
  76. {
  77. if (foo[i] != i*2)
  78. {
  79. FPRINTF(stderr,"value %u is %u instead of %u\n", i, foo[i], 2*i);
  80. ret = EXIT_FAILURE;
  81. }
  82. }
  83. free(foo);
  84. return ret;
  85. enodev:
  86. starpu_data_unregister(handle);
  87. fprintf(stderr, "WARNING: No one can execute this task\n");
  88. /* yes, we do not perform the computation but we did detect that no one
  89. * could perform the kernel, so this is not an error from StarPU */
  90. starpu_shutdown();
  91. return STARPU_TEST_SKIPPED;
  92. }