sched_ctx_empty.c 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010-2018 CNRS
  4. * Copyright (C) 2012-2014,2017,2018 Inria
  5. * Copyright (C) 2010-2014 Université de Bordeaux
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <starpu.h>
  19. #define FPRINTF(ofile, fmt, ...) do { if (!getenv("STARPU_SSILENT")) {fprintf(ofile, fmt, ## __VA_ARGS__); }} while(0)
  20. static void cpu_func(void *descr[], void *arg)
  21. {
  22. (void)descr;
  23. (void)arg;
  24. FPRINTF(stdout, "Hello world\n");
  25. }
  26. static struct starpu_codelet codelet =
  27. {
  28. .cpu_funcs = {cpu_func},
  29. .nbuffers = 0,
  30. .name = "codelet"
  31. };
  32. int main(void)
  33. {
  34. int ret;
  35. int nprocs = 0;
  36. int procs[STARPU_NMAXWORKERS];
  37. unsigned sched_ctx_id;
  38. ret = starpu_init(NULL);
  39. if (ret == -ENODEV) return 77;
  40. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  41. nprocs = starpu_cpu_worker_get_count();
  42. // if there is no cpu, skip
  43. if (nprocs == 0) goto enodev;
  44. sched_ctx_id = starpu_sched_ctx_create(NULL, 0, "ctx", 0);
  45. starpu_sched_ctx_set_context(&sched_ctx_id);
  46. ret = starpu_task_insert(&codelet, 0);
  47. STARPU_CHECK_RETURN_VALUE(ret, "starpu_task_insert");
  48. starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, procs, nprocs);
  49. starpu_sched_ctx_add_workers(procs, nprocs, sched_ctx_id);
  50. starpu_task_wait_for_all();
  51. starpu_sched_ctx_delete(sched_ctx_id);
  52. enodev:
  53. starpu_shutdown();
  54. return nprocs == 0 ? 77 : 0;
  55. }