prio.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. void
  30. A(void *buffers[], void *args)
  31. {
  32. (void) buffers;
  33. (void) args;
  34. FPRINTF(stdout,"A");
  35. usleep(1000);
  36. }
  37. 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. starpu_srand48(0);
  68. for (i = 0; i < NTASKS; i++) {
  69. struct starpu_task *task = starpu_task_create();
  70. if (((int)(starpu_drand48()*2))%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. }