parallel_kernels_trivial.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Thibaut Lambert
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <limits.h>
  19. #include <unistd.h>
  20. #include "../helper.h"
  21. /*
  22. * Submit a simple testcase for parallel tasks.
  23. */
  24. #define VECTORSIZE 1024
  25. void codelet_null(void *descr[], void *_args)
  26. {
  27. (void)descr;
  28. (void)_args;
  29. STARPU_SKIP_IF_VALGRIND;
  30. int worker_size = starpu_combined_worker_get_size();
  31. STARPU_ASSERT(worker_size > 0);
  32. usleep(1000/worker_size);
  33. #if 0
  34. int id = starpu_worker_get_id();
  35. int combined_id = starpu_combined_worker_get_id();
  36. FPRINTF(stderr, "worker id %d - combined id %d - worker size %d\n", id, combined_id, worker_size);
  37. #endif
  38. }
  39. struct starpu_perfmodel model =
  40. {
  41. .type = STARPU_HISTORY_BASED,
  42. .symbol = "parallel_kernel_test"
  43. };
  44. static struct starpu_codelet cl =
  45. {
  46. .type = STARPU_FORKJOIN,
  47. .max_parallelism = INT_MAX,
  48. .cpu_funcs = {codelet_null},
  49. .cuda_funcs = {codelet_null},
  50. .cpu_funcs_name = {"codelet_null"},
  51. .opencl_funcs = {codelet_null},
  52. .model = &model,
  53. .nbuffers = 1,
  54. .modes = {STARPU_R}
  55. };
  56. static struct starpu_codelet cl_seq =
  57. {
  58. .cpu_funcs = {codelet_null},
  59. .cuda_funcs = {codelet_null},
  60. .cpu_funcs_name = {"codelet_null"},
  61. .opencl_funcs = {codelet_null},
  62. .model = &model,
  63. .nbuffers = 1,
  64. .modes = {STARPU_R}
  65. };
  66. int main(void)
  67. {
  68. int ret;
  69. starpu_data_handle_t v_handle;
  70. unsigned *v;
  71. struct starpu_conf conf;
  72. starpu_conf_init(&conf);
  73. conf.ncpus = 2;
  74. conf.sched_policy_name = "pheft";
  75. conf.calibrate = 1;
  76. ret = starpu_init(&conf);
  77. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  78. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  79. starpu_malloc((void **)&v, VECTORSIZE*sizeof(unsigned));
  80. starpu_vector_data_register(&v_handle, STARPU_MAIN_RAM, (uintptr_t)v, VECTORSIZE, sizeof(unsigned));
  81. /* First submit a sequential task */
  82. ret = starpu_task_insert(&cl_seq, STARPU_R, v_handle, 0);
  83. if (ret == -ENODEV) goto enodev;
  84. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  85. /* Then a parallel task, which is not interesting to run in parallel when we have only two cpus */
  86. ret = starpu_task_insert(&cl, STARPU_R, v_handle, 0);
  87. if (ret == -ENODEV) goto enodev;
  88. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  89. /* Then another parallel task, which is interesting to run in parallel
  90. since the two cpus are now finishing at the same time. */
  91. ret = starpu_task_insert(&cl, STARPU_R, v_handle, 0);
  92. if (ret == -ENODEV) goto enodev;
  93. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  94. ret = starpu_task_wait_for_all();
  95. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_wait_for_all");
  96. starpu_data_unregister(v_handle);
  97. starpu_free(v);
  98. starpu_shutdown();
  99. STARPU_RETURN(EXIT_SUCCESS);
  100. enodev:
  101. starpu_data_unregister(v_handle);
  102. starpu_free(v);
  103. fprintf(stderr, "WARNING: No one can execute this task\n");
  104. /* yes, we do not perform the computation but we did detect that no one
  105. * could perform the kernel, so this is not an error from StarPU */
  106. starpu_shutdown();
  107. STARPU_RETURN(STARPU_TEST_SKIPPED);
  108. }