in_place_partition.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 <starpu_opencl.h>
  18. #include "../helper.h"
  19. #include "scal.h"
  20. int main(int argc, char **argv)
  21. {
  22. unsigned *foo;
  23. starpu_data_handle_t handle;
  24. int ret;
  25. int n, i, size;
  26. ret = starpu_init(NULL);
  27. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  28. #ifdef STARPU_USE_OPENCL
  29. starpu_opencl_load_opencl_from_file("tests/datawizard/scal_opencl.cl", &opencl_program, NULL);
  30. #endif
  31. n = starpu_worker_get_count();
  32. size = 10 * n;
  33. foo = calloc(size, sizeof(*foo));
  34. for (i = 0; i < size; i++)
  35. foo[i] = i;
  36. starpu_vector_data_register(&handle, 0, (uintptr_t)foo, size, sizeof(*foo));
  37. /* Broadcast the data to force in-place partitioning */
  38. for (i = 0; i < n; i++)
  39. starpu_data_prefetch_on_node(handle, starpu_worker_get_memory_node(i), 0);
  40. struct starpu_data_filter f =
  41. {
  42. .filter_func = starpu_block_filter_func_vector,
  43. .nchildren = n > 1 ? n : 2,
  44. };
  45. starpu_data_partition(handle, &f);
  46. for (i = 0; i < n; i++) {
  47. struct starpu_task *task = starpu_task_create();
  48. task->handles[0] = starpu_data_get_sub_data(handle, 1, i);
  49. task->cl = &scal_codelet;
  50. task->execute_on_a_specific_worker = 1;
  51. task->workerid = i;
  52. ret = starpu_task_submit(task);
  53. if (ret == -ENODEV) goto enodev;
  54. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  55. }
  56. ret = starpu_task_wait_for_all();
  57. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  58. starpu_data_unpartition(handle, 0);
  59. starpu_data_unregister(handle);
  60. starpu_shutdown();
  61. ret = EXIT_SUCCESS;
  62. for (i = 0; i < size; i++) {
  63. if (foo[i] != i*2) {
  64. FPRINTF(stderr,"value %d is %d instead of %d\n", i, foo[i], 2*i);
  65. ret = EXIT_FAILURE;
  66. }
  67. }
  68. return ret;
  69. enodev:
  70. starpu_data_unregister(handle);
  71. fprintf(stderr, "WARNING: No one can execute this task\n");
  72. /* yes, we do not perform the computation but we did detect that no one
  73. * could perform the kernel, so this is not an error from StarPU */
  74. starpu_shutdown();
  75. return STARPU_TEST_SKIPPED;
  76. }