starpu_init_noworker.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 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. (void) unsetenv("STARPU_NSCC");
  42. }
  43. int main(int argc, char **argv)
  44. {
  45. int ret;
  46. unset_env_variables();
  47. /* We try to initialize StarPU without any worker */
  48. struct starpu_conf conf;
  49. starpu_conf_init(&conf);
  50. conf.ncpus = 0;
  51. conf.ncuda = 0;
  52. conf.nopencl = 0;
  53. conf.nmic = 0;
  54. conf.nscc = 0;
  55. conf.nmpi_ms = 0;
  56. /* starpu_init should return -ENODEV */
  57. ret = starpu_initialize(&conf, &argc, &argv);
  58. if (ret == -ENODEV)
  59. return EXIT_SUCCESS;
  60. else
  61. {
  62. unsigned ncpu = starpu_cpu_worker_get_count();
  63. unsigned ncuda = starpu_cuda_worker_get_count();
  64. unsigned nopencl = starpu_opencl_worker_get_count();
  65. unsigned nmic = starpu_mic_worker_get_count();
  66. unsigned nmpi_ms = starpu_mpi_ms_worker_get_count();
  67. FPRINTF(stderr, "StarPU has found :\n");
  68. FPRINTF(stderr, "\t%u CPU cores\n", ncpu);
  69. FPRINTF(stderr, "\t%u CUDA devices\n", ncuda);
  70. FPRINTF(stderr, "\t%u OpenCL devices\n", nopencl);
  71. FPRINTF(stderr, "\t%u MIC devices\n", nmic);
  72. FPRINTF(stderr, "\t%u MPI Master-Slaves devices\n", nmpi_ms);
  73. return EXIT_FAILURE;
  74. }
  75. }
  76. #endif