submit.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2012 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012, 2013 Centre National de la Recherche Scientifique
  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 <stdio.h>
  18. #include <unistd.h>
  19. #include <starpu.h>
  20. #include "../helper.h"
  21. static int i = 0, j;
  22. void dummy_func(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg STARPU_ATTRIBUTE_UNUSED)
  23. {
  24. i++;
  25. FPRINTF(stdout, "called third task, i = %d\n", i);
  26. }
  27. static struct starpu_codelet dummy_codelet =
  28. {
  29. .cpu_funcs = {dummy_func, NULL},
  30. .cuda_funcs = {dummy_func, NULL},
  31. .opencl_funcs = {dummy_func, NULL},
  32. .model = NULL,
  33. .nbuffers = 0
  34. };
  35. static void callback(void *arg STARPU_ATTRIBUTE_UNUSED)
  36. {
  37. struct starpu_task *task = starpu_task_create();
  38. task->cl = &dummy_codelet;
  39. task->detach = 1;
  40. if (starpu_task_submit(task) == ENODEV)
  41. exit(STARPU_TEST_SKIPPED);
  42. FPRINTF(stdout, "submitted third task, i = %d\n", i);
  43. }
  44. static struct starpu_codelet callback_submit_codelet =
  45. {
  46. .cpu_funcs = {dummy_func, NULL},
  47. .cuda_funcs = {dummy_func, NULL},
  48. .opencl_funcs = {dummy_func, NULL},
  49. .model = NULL,
  50. .nbuffers = 0
  51. };
  52. static void task_submit_func(void *descr[] STARPU_ATTRIBUTE_UNUSED, void *arg STARPU_ATTRIBUTE_UNUSED)
  53. {
  54. struct starpu_task *task = starpu_task_create();
  55. task->cl = &callback_submit_codelet;
  56. task->callback_func = callback;
  57. task->detach = 1;
  58. if (starpu_task_submit(task) == ENODEV)
  59. exit(STARPU_TEST_SKIPPED);
  60. i++;
  61. FPRINTF(stdout, "submitted second task, i = %d\n", i);
  62. }
  63. static struct starpu_codelet task_submit_codelet =
  64. {
  65. .cpu_funcs = {task_submit_func, NULL},
  66. .cuda_funcs = {task_submit_func, NULL},
  67. .opencl_funcs = {task_submit_func, NULL},
  68. .model = NULL,
  69. .nbuffers = 0
  70. };
  71. int main(int argc, char **argv)
  72. {
  73. int ret;
  74. ret = starpu_init(NULL);
  75. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  76. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  77. struct starpu_task *task = starpu_task_create();
  78. task->cl = &task_submit_codelet;
  79. task->detach = 1;
  80. ret = starpu_task_submit(task);
  81. if (ret == -ENODEV) goto enodev;
  82. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_submit");
  83. starpu_task_wait_for_all();
  84. j = i;
  85. starpu_shutdown();
  86. return j == 3 ? EXIT_SUCCESS : EXIT_FAILURE;
  87. enodev:
  88. fprintf(stderr, "WARNING: No one can execute this task\n");
  89. /* yes, we do not perform the computation but we did detect that no one
  90. * could perform the kernel, so this is not an error from StarPU */
  91. starpu_shutdown();
  92. return STARPU_TEST_SKIPPED;
  93. }