bind.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2019-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 <stdio.h>
  17. #include <unistd.h>
  18. #include <starpu.h>
  19. #include "../helper.h"
  20. /*
  21. * Test binding the main thread to its dedicated core, making one less CPU core
  22. * available to StarPU.
  23. */
  24. int main(void)
  25. {
  26. int ret;
  27. struct starpu_conf conf;
  28. int ncpus;
  29. unsigned active_bindid;
  30. unsigned passive_bindid1;
  31. unsigned passive_bindid2;
  32. /* First get the number of cores */
  33. starpu_conf_init(&conf);
  34. ret = starpu_init(&conf);
  35. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  36. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  37. ncpus = starpu_worker_get_count_by_type(STARPU_CPU_WORKER);
  38. starpu_shutdown();
  39. /* Check we have enough of them */
  40. if (ncpus <= 2) return STARPU_TEST_SKIPPED;
  41. /* Now re-initialize with two cores less */
  42. starpu_conf_init(&conf);
  43. conf.reserve_ncpus = 2;
  44. ret = starpu_init(&conf);
  45. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  46. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  47. /* Make sure StarPU uses two core less */
  48. STARPU_ASSERT_MSG(starpu_worker_get_count_by_type(STARPU_CPU_WORKER) == ncpus-2, "Expected %d CPUs, got %d\n", ncpus-2, starpu_worker_get_count_by_type(STARPU_CPU_WORKER));
  49. FPRINTF(stderr, "CPUS: %d as expected\n", starpu_worker_get_count_by_type(STARPU_CPU_WORKER));
  50. /* Check we can grab a whole core */
  51. active_bindid = starpu_get_next_bindid(STARPU_THREAD_ACTIVE, NULL, 0);
  52. starpu_bind_thread_on(active_bindid, STARPU_THREAD_ACTIVE, "main");
  53. /* Check we can request for an additional shared core */
  54. passive_bindid1 = starpu_get_next_bindid(0, NULL, 0);
  55. passive_bindid2 = starpu_get_next_bindid(0, NULL, 0);
  56. STARPU_ASSERT(passive_bindid1 != active_bindid);
  57. STARPU_ASSERT(passive_bindid1 == passive_bindid2);
  58. starpu_bind_thread_on(passive_bindid1, 0, "main");
  59. starpu_bind_thread_on(passive_bindid2, 0, "main");
  60. starpu_shutdown();
  61. return EXIT_SUCCESS;
  62. }