execute_all_tasks.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. * Copyright (C) 2013 Thibaut Lambert
  5. *
  6. * StarPU is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU Lesser General Public License as published by
  8. * the Free Software Foundation; either version 2.1 of the License, or (at
  9. * your option) any later version.
  10. *
  11. * StarPU is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  14. *
  15. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  16. */
  17. #include <starpu.h>
  18. #include <starpu_scheduler.h>
  19. #include <core/jobs.h>
  20. #include "../helper.h"
  21. /*
  22. * All tasks submitted by StarPU should be executed once.
  23. * Applies to: all schedulers.
  24. */
  25. #define NTASKS 8
  26. void dummy(void *buffers[], void *args)
  27. {
  28. (void) buffers;
  29. (void) args;
  30. }
  31. static int
  32. run(struct starpu_sched_policy *p)
  33. {
  34. int ret;
  35. struct starpu_conf conf;
  36. (void) starpu_conf_init(&conf);
  37. conf.sched_policy = p;
  38. ret = starpu_init(&conf);
  39. if (ret == -ENODEV)
  40. exit(STARPU_TEST_SKIPPED);
  41. struct starpu_task *tasks[NTASKS] = { NULL };
  42. struct starpu_codelet cl =
  43. {
  44. .cpu_funcs = {dummy},
  45. .cpu_funcs_name = {"dummy"},
  46. .cuda_funcs = {dummy},
  47. .opencl_funcs = {dummy},
  48. .fpga_funcs = {dummy},
  49. .nbuffers = 0
  50. };
  51. int i;
  52. for (i = 0; i < NTASKS; i++)
  53. {
  54. struct starpu_task *task = starpu_task_create();
  55. tasks[i] = task;
  56. task->cl = &cl;
  57. task->synchronous = 1;
  58. task->destroy = 0;
  59. ret = starpu_task_submit(task);
  60. if (ret != 0)
  61. {
  62. FPRINTF(stderr,"task submission returned %d\n", ret);
  63. return 1;
  64. }
  65. }
  66. starpu_task_wait_for_all();
  67. ret = 0;
  68. for (i = 0; i < NTASKS; i++)
  69. {
  70. struct _starpu_job *j = tasks[i]->starpu_private;
  71. if (j == NULL || j->terminated == 0)
  72. {
  73. FPRINTF(stderr, "Error with policy %s.\n", p->policy_name);
  74. ret = 1;
  75. break;
  76. }
  77. }
  78. for (i = 0; i < NTASKS; i++)
  79. {
  80. starpu_task_destroy(tasks[i]);
  81. }
  82. starpu_shutdown();
  83. return ret;
  84. }
  85. int main(void)
  86. {
  87. struct starpu_sched_policy **policies;
  88. struct starpu_sched_policy **policy;
  89. char *sched = getenv("STARPU_SCHED");
  90. policies = starpu_sched_get_predefined_policies();
  91. for(policy=policies ; *policy!=NULL ; policy++)
  92. {
  93. if (sched && strcmp(sched, (*policy)->policy_name))
  94. /* Testing another specific scheduler, no need to run this */
  95. continue;
  96. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  97. int ret;
  98. ret = run(*policy);
  99. if (ret == 1)
  100. return EXIT_FAILURE;
  101. }
  102. return EXIT_SUCCESS;
  103. }