execute_all_tasks.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Inria
  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 <starpu.h>
  17. #include <starpu_scheduler.h>
  18. #include <core/jobs.h>
  19. #include "../helper.h"
  20. /*
  21. * All tasks submitted by StarPU should be executed once.
  22. * Applies to: all schedulers.
  23. */
  24. #define NTASKS 8
  25. void dummy(void *buffers[], void *args)
  26. {
  27. (void) buffers;
  28. (void) args;
  29. }
  30. static int
  31. run(struct starpu_sched_policy *p)
  32. {
  33. int ret;
  34. struct starpu_conf conf;
  35. (void) starpu_conf_init(&conf);
  36. conf.sched_policy = p;
  37. ret = starpu_init(&conf);
  38. if (ret == -ENODEV)
  39. exit(STARPU_TEST_SKIPPED);
  40. struct starpu_task *tasks[NTASKS] = { NULL };
  41. struct starpu_codelet cl =
  42. {
  43. .cpu_funcs = {dummy, NULL},
  44. .cpu_funcs_name = {"dummy", NULL},
  45. .cuda_funcs = {dummy, NULL},
  46. .opencl_funcs = {dummy, NULL},
  47. .nbuffers = 0
  48. };
  49. int i;
  50. for (i = 0; i < NTASKS; i++)
  51. {
  52. struct starpu_task *task = starpu_task_create();
  53. tasks[i] = task;
  54. task->cl = &cl;
  55. task->synchronous = 1;
  56. task->destroy = 0;
  57. ret = starpu_task_submit(task);
  58. if (ret != 0)
  59. {
  60. FPRINTF(stderr,"task submission returned %d\n", ret);
  61. return 1;
  62. }
  63. }
  64. starpu_task_wait_for_all();
  65. ret = 0;
  66. for (i = 0; i < NTASKS; i++)
  67. {
  68. struct _starpu_job *j = tasks[i]->starpu_private;
  69. if (j == NULL || j->terminated == 0)
  70. {
  71. FPRINTF(stderr, "Error with policy %s.\n", p->policy_name);
  72. ret = 1;
  73. break;
  74. }
  75. }
  76. for (i = 0; i < NTASKS; i++)
  77. {
  78. starpu_task_destroy(tasks[i]);
  79. }
  80. starpu_shutdown();
  81. return ret;
  82. }
  83. int
  84. main(void)
  85. {
  86. struct starpu_sched_policy **policies;
  87. struct starpu_sched_policy **policy;
  88. policies = starpu_sched_get_predefined_policies();
  89. for(policy=policies ; *policy!=NULL ; policy++)
  90. {
  91. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  92. int ret;
  93. ret = run(*policy);
  94. if (ret == 1)
  95. return EXIT_FAILURE;
  96. }
  97. return EXIT_SUCCESS;
  98. }