starpu_init_noworker.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009-2016 Université de Bordeaux
  4. * Copyright (C) 2012,2016,2017 Inria
  5. * Copyright (C) 2010-2013,2015,2017,2019 CNRS
  6. *
  7. * StarPU is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU Lesser General Public License as published by
  9. * the Free Software Foundation; either version 2.1 of the License, or (at
  10. * your option) any later version.
  11. *
  12. * StarPU is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. *
  16. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. */
  18. #include <stdio.h>
  19. #include <unistd.h>
  20. #include <errno.h>
  21. #include <starpu.h>
  22. #include <stdlib.h>
  23. #include "../helper.h"
  24. /*
  25. * Test that starpu_initialize returns ENODEV when no worker is available
  26. */
  27. #if !defined(STARPU_HAVE_UNSETENV)
  28. #warning unsetenv is not defined. Skipping test
  29. int main(void)
  30. {
  31. return STARPU_TEST_SKIPPED;
  32. }
  33. #else
  34. static void unset_env_variables(void)
  35. {
  36. (void) unsetenv("STARPU_NCPUS");
  37. (void) unsetenv("STARPU_NCPU");
  38. (void) unsetenv("STARPU_NCUDA");
  39. (void) unsetenv("STARPU_NOPENCL");
  40. (void) unsetenv("STARPU_NMIC");
  41. }
  42. int main(int argc, char **argv)
  43. {
  44. int ret;
  45. unset_env_variables();
  46. /* We try to initialize StarPU without any worker */
  47. struct starpu_conf conf;
  48. starpu_conf_init(&conf);
  49. conf.ncpus = 0;
  50. conf.ncuda = 0;
  51. conf.nopencl = 0;
  52. conf.nmic = 0;
  53. conf.nmpi_ms = 0;
  54. /* starpu_init should return -ENODEV */
  55. ret = starpu_initialize(&conf, &argc, &argv);
  56. if (ret == -ENODEV)
  57. return EXIT_SUCCESS;
  58. else
  59. {
  60. unsigned ncpu = starpu_cpu_worker_get_count();
  61. unsigned ncuda = starpu_cuda_worker_get_count();
  62. unsigned nopencl = starpu_opencl_worker_get_count();
  63. unsigned nmic = starpu_mic_worker_get_count();
  64. unsigned nmpi_ms = starpu_mpi_ms_worker_get_count();
  65. FPRINTF(stderr, "StarPU has found :\n");
  66. FPRINTF(stderr, "\t%u CPU cores\n", ncpu);
  67. FPRINTF(stderr, "\t%u CUDA devices\n", ncuda);
  68. FPRINTF(stderr, "\t%u OpenCL devices\n", nopencl);
  69. FPRINTF(stderr, "\t%u MIC devices\n", nmic);
  70. FPRINTF(stderr, "\t%u MPI Master-Slaves devices\n", nmpi_ms);
  71. return EXIT_FAILURE;
  72. }
  73. }
  74. #endif