sched_ctx_policy_data.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2015-2021 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. #include "../helper.h"
  18. int main(void)
  19. {
  20. int ret;
  21. int nprocs;
  22. int *procs;
  23. unsigned sched_ctx;
  24. unsigned main_sched_ctx;
  25. int *ptr;
  26. int *main_ptr;
  27. ret = starpu_init(NULL);
  28. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  29. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  30. nprocs = starpu_cpu_worker_get_count();
  31. if (nprocs == 0)
  32. {
  33. starpu_shutdown();
  34. return STARPU_TEST_SKIPPED;
  35. }
  36. procs = (int*)malloc(nprocs*sizeof(int));
  37. starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, procs, nprocs);
  38. sched_ctx = starpu_sched_ctx_create(procs, nprocs, "my_context", 0);
  39. ptr = starpu_sched_ctx_get_policy_data(sched_ctx);
  40. STARPU_ASSERT_MSG(ptr == NULL, "The policy data for the sched ctx should be NULL\n");
  41. starpu_sched_ctx_set_policy_data(sched_ctx, procs);
  42. ptr = starpu_sched_ctx_get_policy_data(sched_ctx);
  43. FPRINTF(stderr, "sched_ctx %u : data %p (procs %p)\n", sched_ctx, ptr, procs);
  44. STARPU_ASSERT_MSG(ptr == procs, "The policy data for the sched ctx is incorrect\n");
  45. main_sched_ctx = starpu_sched_ctx_get_context();
  46. main_ptr = starpu_sched_ctx_get_policy_data(main_sched_ctx);
  47. STARPU_ASSERT_MSG(main_ptr == NULL, "The policy data for the sched ctx should be NULL\n");
  48. starpu_sched_ctx_set_policy_data(main_sched_ctx, procs);
  49. main_ptr = starpu_sched_ctx_get_policy_data(sched_ctx);
  50. FPRINTF(stderr, "sched_ctx %u : data %p (procs %p)\n", main_sched_ctx, main_ptr, procs);
  51. STARPU_ASSERT_MSG(main_ptr == procs, "The policy data for the sched ctx is incorrect\n");
  52. starpu_sched_ctx_delete(sched_ctx);
  53. free(procs);
  54. starpu_shutdown();
  55. return (ptr == procs) ? 0 : 1;
  56. }