hwloc_cpuset.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2017-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 workers hwloc cpusets
  22. */
  23. int main(void)
  24. {
  25. int status = 0;
  26. #ifdef STARPU_HAVE_HWLOC
  27. struct starpu_conf conf;
  28. starpu_conf_init(&conf);
  29. conf.nmpi_ms = 0;
  30. int ret = starpu_init(&conf);
  31. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  32. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  33. int nworkers = starpu_worker_get_count_by_type(STARPU_CPU_WORKER);
  34. if (nworkers != 0)
  35. {
  36. hwloc_cpuset_t accumulator_cpuset = hwloc_bitmap_alloc();
  37. hwloc_cpuset_t temp_cpuset = hwloc_bitmap_alloc();
  38. hwloc_bitmap_zero(accumulator_cpuset);
  39. status = 0;
  40. int workerids[nworkers];
  41. starpu_worker_get_ids_by_type(STARPU_CPU_WORKER, workerids, nworkers);
  42. int i;
  43. for (i=0; i<nworkers; i++)
  44. {
  45. hwloc_cpuset_t cpuset = starpu_worker_get_hwloc_cpuset(workerids[i]);
  46. /* check that the worker cpuset is not empty */
  47. if (hwloc_bitmap_iszero(cpuset))
  48. {
  49. status = EXIT_FAILURE;
  50. hwloc_bitmap_free(cpuset);
  51. break;
  52. }
  53. hwloc_bitmap_zero(temp_cpuset);
  54. /* check that the worker cpuset does not overlap other workers cpusets */
  55. hwloc_bitmap_and(temp_cpuset, accumulator_cpuset, cpuset);
  56. if (!hwloc_bitmap_iszero(temp_cpuset))
  57. {
  58. status = EXIT_FAILURE;
  59. hwloc_bitmap_free(cpuset);
  60. break;
  61. }
  62. hwloc_bitmap_or(accumulator_cpuset, accumulator_cpuset, cpuset);
  63. /* the cpuset returned by starpu_worker_get_hwloc_cpuset() must be freed */
  64. hwloc_bitmap_free(cpuset);
  65. }
  66. hwloc_bitmap_free(temp_cpuset);
  67. hwloc_bitmap_free(accumulator_cpuset);
  68. }
  69. else
  70. {
  71. status = STARPU_TEST_SKIPPED;
  72. }
  73. starpu_shutdown();
  74. #else
  75. status = STARPU_TEST_SKIPPED;
  76. #endif
  77. return status;
  78. }