hwloc_cpuset.c 2.4 KB

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