parallel_independent_homogeneous_tasks.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2016,2017 CNRS
  4. * Copyright (C) 2016 Université de Bordeaux
  5. * Copyright (C) 2016 Bérangère Subervie
  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 <stdbool.h>
  19. #include <starpu.h>
  20. #include "../helper.h"
  21. /* Run a series of independent tasks with homogeneous execution time */
  22. #define TIME 0.010
  23. #ifdef STARPU_QUICK_CHECK
  24. #define TASK_COEFFICIENT 20
  25. #define MARGIN 0.15
  26. #else
  27. #define TASK_COEFFICIENT 100
  28. #define MARGIN 0.05
  29. #endif
  30. #define SECONDS_SCALE_COEFFICIENT_TIMING_NOW 1000000
  31. void wait_homogeneous(void *descr[], void *_args)
  32. {
  33. (void)descr;
  34. (void)_args;
  35. starpu_sleep(TIME);
  36. }
  37. double cost_function(struct starpu_task *t, struct starpu_perfmodel_arch *a, unsigned i)
  38. {
  39. (void)t;
  40. (void)a;
  41. (void)i;
  42. return TIME * 1000000;
  43. }
  44. static struct starpu_perfmodel perf_model =
  45. {
  46. .type = STARPU_PER_ARCH,
  47. .arch_cost_function = cost_function,
  48. };
  49. static struct starpu_codelet cl =
  50. {
  51. .cpu_funcs = { wait_homogeneous },
  52. .cuda_funcs = { wait_homogeneous },
  53. .opencl_funcs = { wait_homogeneous },
  54. .cpu_funcs_name = { "wait_homogeneous" },
  55. .nbuffers = 0,
  56. .flags = STARPU_CODELET_SIMGRID_EXECUTE,
  57. .model = &perf_model,
  58. };
  59. int main(int argc, char *argv[])
  60. {
  61. int ret;
  62. ret = starpu_initialize(NULL, &argc, &argv);
  63. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  64. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  65. unsigned nb_tasks, nb_workers, i;
  66. double begin_time, end_time, time_m, time_s, speed_up, expected_speed_up, percentage_expected_speed_up;
  67. bool check, check_sup;
  68. nb_workers = starpu_worker_get_count_by_type(STARPU_CPU_WORKER) + starpu_worker_get_count_by_type(STARPU_CUDA_WORKER) + starpu_worker_get_count_by_type(STARPU_OPENCL_WORKER);
  69. nb_tasks = nb_workers*TASK_COEFFICIENT;
  70. begin_time = starpu_timing_now();
  71. /*execution des tasks*/
  72. for (i=0; i<nb_tasks; i++)
  73. {
  74. starpu_task_insert(&cl,0);
  75. }
  76. starpu_task_wait_for_all();
  77. end_time = starpu_timing_now();
  78. /*on determine si le temps mesure est satisfaisant ou pas*/
  79. time_m = (end_time - begin_time)/SECONDS_SCALE_COEFFICIENT_TIMING_NOW; //pour ramener en secondes
  80. time_s = nb_tasks * TIME;
  81. speed_up = time_s/time_m;
  82. expected_speed_up = nb_workers;
  83. percentage_expected_speed_up = 100 * (speed_up/expected_speed_up);
  84. check = speed_up >= ((1 - MARGIN) * expected_speed_up);
  85. check_sup = speed_up <= ((1 + MARGIN) * expected_speed_up);
  86. printf("measured time = %f seconds\nsequential time = %f seconds\nspeed up = %f\nnumber of workers = %u\nnumber of tasks = %u\nexpected speed up = %f\npercentage of expected speed up = %.2f%%\n", time_m, time_s, speed_up, nb_workers, nb_tasks, expected_speed_up, percentage_expected_speed_up);
  87. starpu_shutdown();
  88. //test reussi ou test echoue
  89. if (check && check_sup)
  90. {
  91. return EXIT_SUCCESS;
  92. }
  93. else
  94. {
  95. return EXIT_FAILURE;
  96. }
  97. }