sched_ctx_empty.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), 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. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  18. static void cpu_func(void *descr[], void *arg)
  19. {
  20. (void)descr;
  21. (void)arg;
  22. FPRINTF(stdout, "Hello world\n");
  23. }
  24. static struct starpu_codelet codelet =
  25. {
  26. .cpu_funcs = {cpu_func},
  27. .nbuffers = 0,
  28. .name = "codelet"
  29. };
  30. int main(void)
  31. {
  32. int ret;
  33. int nprocs = 0;
  34. int procs[STARPU_NMAXWORKERS];
  35. unsigned sched_ctx_id;
  36. ret = starpu_init(NULL);
  37. if (ret == -ENODEV) return 77;
  38. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  39. nprocs = starpu_cpu_worker_get_count();
  40. // if there is no cpu, skip
  41. if (nprocs == 0) goto enodev;
  42. sched_ctx_id = starpu_sched_ctx_create(NULL, 0, "ctx", 0);
  43. starpu_sched_ctx_set_context(&sched_ctx_id);
  44. ret = starpu_task_insert(&codelet, 0);
  45. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  46. starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, procs, nprocs);
  47. starpu_sched_ctx_add_workers(procs, nprocs, sched_ctx_id);
  48. starpu_task_wait_for_all();
  49. starpu_sched_ctx_delete(sched_ctx_id);
  50. enodev:
  51. starpu_shutdown();
  52. return nprocs == 0 ? 77 : 0;
  53. }