prio.c 2.5 KB

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