prio.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2013 Université Bordeaux 1
  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 <unistd.h>
  17. #include <starpu.h>
  18. #include <starpu_scheduler.h>
  19. #include <stdlib.h>
  20. #include "../helper.h"
  21. #ifdef STARPU_QUICK_CHECK
  22. #define NTASKS 10
  23. #else
  24. #define NTASKS 1000
  25. #endif
  26. /*
  27. * Task1 must be executed before task0, even if task0 is submitted first.
  28. * Applies to : all schedulers.
  29. */
  30. static void
  31. A(void *buffers[], void *args)
  32. {
  33. (void) buffers;
  34. (void) args;
  35. FPRINTF(stdout,"A");
  36. usleep(1000);
  37. }
  38. static void
  39. B(void *buffers[], void *args)
  40. {
  41. (void) buffers;
  42. (void) args;
  43. FPRINTF(stdout,"B");
  44. usleep(1000);
  45. }
  46. static int
  47. run(struct starpu_sched_policy *policy)
  48. {
  49. int ret;
  50. struct starpu_conf conf;
  51. int i;
  52. starpu_conf_init(&conf);
  53. conf.sched_policy = policy;
  54. ret = starpu_init(&conf);
  55. if (ret != 0)
  56. exit(STARPU_TEST_SKIPPED);
  57. starpu_profiling_status_set(1);
  58. struct starpu_codelet clA =
  59. {
  60. .cpu_funcs = {A, NULL},
  61. .nbuffers = 0
  62. };
  63. struct starpu_codelet clB =
  64. {
  65. .cpu_funcs = {B, NULL},
  66. .nbuffers = 0
  67. };
  68. for (i = 0; i < NTASKS; i++) {
  69. struct starpu_task *task = starpu_task_create();
  70. if (random()%2) {
  71. task->cl = &clA;
  72. task->priority=STARPU_MIN_PRIO;
  73. } else {
  74. task->cl = &clB;
  75. task->priority=STARPU_MAX_PRIO;
  76. }
  77. task->detach=1;
  78. ret = starpu_task_submit(task);
  79. if (ret == -ENODEV) goto enodev;
  80. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  81. }
  82. starpu_task_wait_for_all();
  83. FPRINTF(stdout,"\n");
  84. starpu_shutdown();
  85. return 0;
  86. enodev:
  87. starpu_shutdown();
  88. return -ENODEV;
  89. }
  90. int
  91. main(void)
  92. {
  93. struct starpu_sched_policy **policies;
  94. struct starpu_sched_policy **policy;
  95. policies = starpu_sched_get_predefined_policies();
  96. for(policy=policies ; *policy!=NULL ; policy++)
  97. {
  98. int ret;
  99. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  100. ret = run(*policy);
  101. if (ret == -ENODEV)
  102. return STARPU_TEST_SKIPPED;
  103. if (ret == 1)
  104. return EXIT_FAILURE;
  105. }
  106. return EXIT_SUCCESS;
  107. }