sched_ctx_policy_data.c 2.3 KB

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