simple_deps.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <unistd.h>
  17. #include <starpu.h>
  18. #include <starpu_scheduler.h>
  19. #include "../helper.h"
  20. /*
  21. * Task1 must be executed before task0, even if task0 is submitted first.
  22. * Applies to : all schedulers.
  23. */
  24. void dummy(void *buffers[], void *args)
  25. {
  26. (void) buffers;
  27. (void) args;
  28. usleep(1000000);
  29. }
  30. static int
  31. run(struct starpu_sched_policy *policy)
  32. {
  33. int ret;
  34. struct starpu_conf conf;
  35. starpu_conf_init(&conf);
  36. conf.sched_policy = policy;
  37. ret = starpu_init(&conf);
  38. if (ret != 0)
  39. exit(STARPU_TEST_SKIPPED);
  40. starpu_profiling_status_set(1);
  41. struct starpu_codelet cl =
  42. {
  43. .cpu_funcs = {dummy, NULL},
  44. .nbuffers = 0
  45. };
  46. struct starpu_task *task0 = starpu_task_create();
  47. task0->cl = &cl;
  48. task0->destroy = 0;
  49. struct starpu_task *task1 = starpu_task_create();
  50. task1->cl = &cl;
  51. task1->destroy = 0;
  52. starpu_task_declare_deps_array(task0, 1, &task1);
  53. ret = starpu_task_submit(task0);
  54. if (ret == -ENODEV) goto enodev;
  55. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  56. ret = starpu_task_submit(task1);
  57. if (ret == -ENODEV) goto enodev;
  58. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  59. starpu_task_wait_for_all();
  60. double task1_end, task0_start;
  61. task1_end = starpu_timing_timespec_to_us(&task1->profiling_info->end_time);
  62. task0_start = starpu_timing_timespec_to_us(&task0->profiling_info->start_time);
  63. starpu_task_destroy(task0);
  64. starpu_task_destroy(task1);
  65. starpu_shutdown();
  66. return !!(task1_end > task0_start);
  67. enodev:
  68. starpu_shutdown();
  69. return -ENODEV;
  70. }
  71. int
  72. main(void)
  73. {
  74. struct starpu_sched_policy **policies;
  75. struct starpu_sched_policy **policy;
  76. policies = starpu_sched_get_predefined_policies();
  77. for(policy=policies ; *policy!=NULL ; policy++)
  78. {
  79. int ret;
  80. FPRINTF(stderr, "Running with policy %s.\n", (*policy)->policy_name);
  81. ret = run(*policy);
  82. if (ret == -ENODEV)
  83. return STARPU_TEST_SKIPPED;
  84. if (ret == 1)
  85. return EXIT_FAILURE;
  86. }
  87. return EXIT_SUCCESS;
  88. }