parallel_independent_homogeneous_tasks.c 3.2 KB

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