starpu_init_noworker.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2009, 2010 Université de Bordeaux 1
  4. * Copyright (C) 2010, 2011, 2012 Centre National de la Recherche Scientifique
  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. #if !defined(STARPU_HAVE_UNSETENV)
  24. #warning unsetenv is not defined. Skipping test
  25. int main(int argc, char **argv)
  26. {
  27. return STARPU_TEST_SKIPPED;
  28. }
  29. #else
  30. static void unset_env_variables(void)
  31. {
  32. (void) unsetenv("STARPU_NCPUS");
  33. (void) unsetenv("STARPU_NCUDA");
  34. (void) unsetenv("STARPU_NOPENCL");
  35. }
  36. int main(int argc, char **argv)
  37. {
  38. int ret;
  39. unset_env_variables();
  40. /* We try to initialize StarPU without any worker */
  41. struct starpu_conf conf =
  42. {
  43. .sched_policy_name = NULL, /* default */
  44. .ncpus = 0,
  45. .ncuda = 0,
  46. .nopencl = 0,
  47. .nspus = 0,
  48. .use_explicit_workers_bindid = 0,
  49. .use_explicit_workers_cuda_gpuid = 0,
  50. .use_explicit_workers_opencl_gpuid = 0,
  51. .calibrate = 0
  52. };
  53. /* starpu_init should return -ENODEV */
  54. ret = starpu_init(&conf);
  55. if (ret == -ENODEV)
  56. return EXIT_SUCCESS;
  57. else
  58. {
  59. unsigned ncpu = starpu_cpu_worker_get_count();
  60. unsigned ncuda = starpu_cuda_worker_get_count();
  61. unsigned nopencl = starpu_opencl_worker_get_count();
  62. FPRINTF(stderr, "StarPU has found :\n");
  63. FPRINTF(stderr, "\t%d CPU cores\n", ncpu);
  64. FPRINTF(stderr, "\t%d CUDA devices\n", ncuda);
  65. FPRINTF(stderr, "\t%d OpenCL devices\n", nopencl);
  66. return EXIT_FAILURE;
  67. }
  68. }
  69. #endif