partition_dep.c 2.9 KB

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