03_cpusets.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* StarPU --- Resource Management Layer.
  2. *
  3. * Copyright (C) 2017, 2018 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 <starpu.h>
  18. #include <starpurm.h>
  19. static void disp_cpuset(const char * name, hwloc_cpuset_t cpuset)
  20. {
  21. int strl = hwloc_bitmap_snprintf(NULL, 0, cpuset);
  22. char str[strl+1];
  23. hwloc_bitmap_snprintf(str, strl+1, cpuset);
  24. printf(". %s: %s\n", name, str);
  25. }
  26. int main(int argc, char *argv[])
  27. {
  28. starpurm_initialize();
  29. int cpu_id = starpurm_get_device_type_id("cpu");
  30. const int nb_cpu_units = starpurm_get_nb_devices_by_type(cpu_id);
  31. if (nb_cpu_units < 1)
  32. {
  33. starpurm_shutdown();
  34. return 77;
  35. }
  36. hwloc_cpuset_t cpuset;
  37. cpuset = starpurm_get_device_worker_cpuset(cpu_id, 0);
  38. disp_cpuset("worker cpuset", cpuset);
  39. hwloc_bitmap_free(cpuset);
  40. cpuset = starpurm_get_global_cpuset();
  41. disp_cpuset("global cpuset", cpuset);
  42. hwloc_bitmap_free(cpuset);
  43. cpuset = starpurm_get_selected_cpuset();
  44. disp_cpuset("selected cpuset", cpuset);
  45. hwloc_bitmap_free(cpuset);
  46. cpuset = starpurm_get_all_cpu_workers_cpuset();
  47. disp_cpuset("all cpu workers cpuset", cpuset);
  48. hwloc_bitmap_free(cpuset);
  49. cpuset = starpurm_get_all_device_workers_cpuset();
  50. disp_cpuset("all device workers cpuset", cpuset);
  51. hwloc_bitmap_free(cpuset);
  52. starpurm_shutdown();
  53. return 0;
  54. }