partition_dep.c 2.8 KB

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