in_place_partition.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011 Université de Bordeaux 1
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. #include <starpu.h>
  17. #include "../helper.h"
  18. #include "scal.h"
  19. int main(int argc, char **argv)
  20. {
  21. unsigned *foo;
  22. starpu_data_handle_t handle;
  23. int ret;
  24. unsigned n, i, size;
  25. ret = starpu_initialize(NULL, &argc, &argv);
  26. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  27. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  28. #ifdef STARPU_USE_OPENCL
  29. ret = starpu_opencl_load_opencl_from_file("tests/datawizard/scal_opencl.cl", &opencl_program, NULL);
  30. STARPU_CHECK_RETURN_VALUE(ret, "starpu_opencl_load_opencl_from_file");
  31. #endif
  32. n = starpu_worker_get_count();
  33. if (n == 1)
  34. {
  35. starpu_shutdown();
  36. return STARPU_TEST_SKIPPED;
  37. }
  38. size = 10 * n;
  39. foo = (unsigned *) calloc(size, sizeof(*foo));
  40. for (i = 0; i < size; i++)
  41. foo[i] = i;
  42. starpu_vector_data_register(&handle, 0, (uintptr_t)foo, size, sizeof(*foo));
  43. /* Broadcast the data to force in-place partitioning */
  44. for (i = 0; i < n; i++)
  45. starpu_data_prefetch_on_node(handle, starpu_worker_get_memory_node(i), 0);
  46. struct starpu_data_filter f =
  47. {
  48. .filter_func = starpu_vector_filter_block,
  49. .nchildren = n,
  50. };
  51. starpu_data_partition(handle, &f);
  52. for (i = 0; i < f.nchildren; i++)
  53. {
  54. struct starpu_task *task = starpu_task_create();
  55. task->handles[0] = starpu_data_get_sub_data(handle, 1, i);
  56. task->cl = &scal_codelet;
  57. task->execute_on_a_specific_worker = 1;
  58. task->workerid = i;
  59. ret = starpu_task_submit(task);
  60. if (ret == -ENODEV) goto enodev;
  61. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  62. }
  63. ret = starpu_task_wait_for_all();
  64. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  65. starpu_data_unpartition(handle, 0);
  66. starpu_data_unregister(handle);
  67. starpu_shutdown();
  68. ret = EXIT_SUCCESS;
  69. for (i = 0; i < size; i++)
  70. {
  71. if (foo[i] != i*2)
  72. {
  73. FPRINTF(stderr,"value %u is %u instead of %u\n", i, foo[i], 2*i);
  74. ret = EXIT_FAILURE;
  75. }
  76. }
  77. return ret;
  78. enodev:
  79. starpu_data_unregister(handle);
  80. fprintf(stderr, "WARNING: No one can execute this task\n");
  81. /* yes, we do not perform the computation but we did detect that no one
  82. * could perform the kernel, so this is not an error from StarPU */
  83. starpu_shutdown();
  84. return STARPU_TEST_SKIPPED;
  85. }