starpu_init_noworker.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2020 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 <errno.h>
  19. #include <starpu.h>
  20. #include <stdlib.h>
  21. #include "../helper.h"
  22. /*
  23. * Test that starpu_initialize returns ENODEV when no worker is available
  24. */
  25. #if !defined(STARPU_HAVE_UNSETENV)
  26. #warning unsetenv is not defined. Skipping test
  27. int main(void)
  28. {
  29. return STARPU_TEST_SKIPPED;
  30. }
  31. #else
  32. static void unset_env_variables(void)
  33. {
  34. (void) unsetenv("STARPU_NCPUS");
  35. (void) unsetenv("STARPU_NCPU");
  36. (void) unsetenv("STARPU_NCUDA");
  37. (void) unsetenv("STARPU_NOPENCL");
  38. (void) unsetenv("STARPU_NMIC");
  39. }
  40. int main(int argc, char **argv)
  41. {
  42. int ret;
  43. unset_env_variables();
  44. /* We try to initialize StarPU without any worker */
  45. struct starpu_conf conf;
  46. starpu_conf_init(&conf);
  47. conf.ncpus = 0;
  48. conf.ncuda = 0;
  49. conf.nopencl = 0;
  50. conf.nmic = 0;
  51. conf.nmpi_ms = 0;
  52. /* starpu_init should return -ENODEV */
  53. ret = starpu_initialize(&conf, &argc, &argv);
  54. if (ret == -ENODEV)
  55. return EXIT_SUCCESS;
  56. else
  57. {
  58. unsigned ncpu = starpu_cpu_worker_get_count();
  59. unsigned ncuda = starpu_cuda_worker_get_count();
  60. unsigned nopencl = starpu_opencl_worker_get_count();
  61. unsigned nmic = starpu_mic_worker_get_count();
  62. unsigned nmpi_ms = starpu_mpi_ms_worker_get_count();
  63. FPRINTF(stderr, "StarPU has found :\n");
  64. FPRINTF(stderr, "\t%u CPU cores\n", ncpu);
  65. FPRINTF(stderr, "\t%u CUDA devices\n", ncuda);
  66. FPRINTF(stderr, "\t%u OpenCL devices\n", nopencl);
  67. FPRINTF(stderr, "\t%u MIC devices\n", nmic);
  68. FPRINTF(stderr, "\t%u MPI Master-Slaves devices\n", nmpi_ms);
  69. return EXIT_FAILURE;
  70. }
  71. }
  72. #endif