multithreaded_init.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2010 Institut National de Recherche en Informatique et Automatique
  4. * Copyright (C) 2010-2011, 2014 Université de Bordeaux 1
  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 <starpu.h>
  19. #include "../helper.h"
  20. #define NUM_THREADS 5
  21. int *glob_argc;
  22. char ***glob_argv;
  23. static
  24. void *launch_starpu(void *unused)
  25. {
  26. int ret;
  27. (void) unused;
  28. ret = starpu_initialize(NULL, glob_argc, glob_argv);
  29. if (ret == -ENODEV)
  30. exit(STARPU_TEST_SKIPPED);
  31. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  32. return NULL;
  33. }
  34. static
  35. void *shutdown_starpu(void *unused)
  36. {
  37. (void) unused;
  38. starpu_shutdown();
  39. return NULL;
  40. }
  41. int main(int argc, char **argv)
  42. {
  43. unsigned i;
  44. double timing;
  45. double start;
  46. double end;
  47. glob_argc = &argc;
  48. glob_argv = &argv;
  49. starpu_pthread_t threads[NUM_THREADS];
  50. start = starpu_timing_now();
  51. for (i = 0; i < NUM_THREADS; ++i)
  52. {
  53. int ret = starpu_pthread_create(&threads[i], NULL, launch_starpu, NULL);
  54. STARPU_ASSERT(ret == 0);
  55. }
  56. for (i = 0; i < NUM_THREADS; ++i)
  57. {
  58. int ret = starpu_pthread_join(threads[i], NULL);
  59. STARPU_ASSERT(ret == 0);
  60. }
  61. end = starpu_timing_now();
  62. timing = end - start;
  63. FPRINTF(stderr, "Success : %d threads launching simultaneously starpu_init\n", NUM_THREADS);
  64. FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
  65. FPRINTF(stderr, "Per task: %f usecs\n", timing/NUM_THREADS);
  66. for (i = 0; i < NUM_THREADS; i++)
  67. {
  68. int ret = starpu_pthread_create(&threads[i], NULL, shutdown_starpu, NULL);
  69. STARPU_ASSERT(ret == 0);
  70. }
  71. for (i = 0; i < NUM_THREADS; i++)
  72. {
  73. int ret = starpu_pthread_join(threads[i], NULL);
  74. STARPU_ASSERT(ret == 0);
  75. }
  76. return EXIT_SUCCESS;
  77. }