starpu_init.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012 Centre National de la Recherche Scientifique
  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 <starpu.h>
  17. #include "../helper.h"
  18. #include <stdlib.h>
  19. static int check_cpu(int env_cpu, int conf_cpu, int expected_cpu, int *cpu)
  20. {
  21. int ret;
  22. if (env_cpu != -1)
  23. {
  24. char string[50];
  25. sprintf(string, "STARPU_NCPUS=%d", env_cpu);
  26. putenv(string);
  27. }
  28. struct starpu_conf user_conf;
  29. starpu_conf_init(&user_conf);
  30. user_conf.ncpus = conf_cpu;
  31. ret = starpu_init(&user_conf);
  32. if (ret == -ENODEV) return STARPU_TEST_SKIPPED;
  33. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  34. *cpu = starpu_cpu_worker_get_count();
  35. starpu_shutdown();
  36. if (env_cpu != -1)
  37. {
  38. unsetenv("STARPU_NCPUS");
  39. }
  40. if (expected_cpu == -1)
  41. {
  42. FPRINTF(stderr, "Number of CPUS: %3d\n", *cpu);
  43. return 0;
  44. }
  45. else
  46. {
  47. FPRINTF(stderr, "Number of CPUS: %3d -- Number of expected CPUs: %3d\n", *cpu, expected_cpu);
  48. return (*cpu != expected_cpu);
  49. }
  50. }
  51. int main(int argc, char **argv)
  52. {
  53. int ret;
  54. int cpu, cpu_init;
  55. unsetenv("STARPU_NCPUS");
  56. ret = check_cpu(-1, -1, -1, &cpu_init);
  57. if (ret) return ret;
  58. ret = check_cpu(cpu_init*2, -1, cpu_init*2, &cpu);
  59. if (ret) return ret;
  60. ret = check_cpu(-1, -1, -1, &cpu);
  61. if (ret) return ret;
  62. if (cpu != cpu_init)
  63. {
  64. FPRINTF(stderr, "The number of CPUs is incorrect\n");
  65. return 1;
  66. }
  67. ret = check_cpu(-1, cpu_init+3, cpu_init+3, &cpu);
  68. if (ret) return ret;
  69. ret = check_cpu(cpu_init+1, cpu_init*3, cpu_init*3, &cpu);
  70. if (ret) return ret;
  71. return ret;
  72. }