starpu_init_noworker.c 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010, 2012-2016 Université de Bordeaux
  4. * Copyright (C) 2010, 2011, 2012, 2013 CNRS
  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 <errno.h>
  20. #include <starpu.h>
  21. #include <stdlib.h>
  22. #include "../helper.h"
  23. /*
  24. * Test that starpu_initialize returns ENODEV when no worker is available
  25. */
  26. #if !defined(STARPU_HAVE_UNSETENV)
  27. #warning unsetenv is not defined. Skipping test
  28. int main(int argc, char **argv)
  29. {
  30. return STARPU_TEST_SKIPPED;
  31. }
  32. #else
  33. static void unset_env_variables(void)
  34. {
  35. (void) unsetenv("STARPU_NCPUS");
  36. (void) unsetenv("STARPU_NCPU");
  37. (void) unsetenv("STARPU_NCUDA");
  38. (void) unsetenv("STARPU_NOPENCL");
  39. (void) unsetenv("STARPU_NMIC");
  40. (void) unsetenv("STARPU_NSCC");
  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.nscc = 0;
  54. conf.nmpi_ms = 0;
  55. /* starpu_init should return -ENODEV */
  56. ret = starpu_initialize(&conf, &argc, &argv);
  57. if (ret == -ENODEV)
  58. return EXIT_SUCCESS;
  59. else
  60. {
  61. unsigned ncpu = starpu_cpu_worker_get_count();
  62. unsigned ncuda = starpu_cuda_worker_get_count();
  63. unsigned nopencl = starpu_opencl_worker_get_count();
  64. unsigned nmic = starpu_mic_worker_get_count();
  65. unsigned nmpi_ms = starpu_mpi_ms_worker_get_count();
  66. FPRINTF(stderr, "StarPU has found :\n");
  67. FPRINTF(stderr, "\t%u CPU cores\n", ncpu);
  68. FPRINTF(stderr, "\t%u CUDA devices\n", ncuda);
  69. FPRINTF(stderr, "\t%u OpenCL devices\n", nopencl);
  70. FPRINTF(stderr, "\t%u MIC devices\n", nmic);
  71. FPRINTF(stderr, "\t%u MPI Master-Slaves devices\n", nmpi_ms);
  72. return EXIT_FAILURE;
  73. }
  74. }
  75. #endif