multithreaded_init.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 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 <sys/time.h>
  18. #include <stdio.h>
  19. #include <pthread.h>
  20. #include <starpu.h>
  21. #include "../helper.h"
  22. #define NUM_THREADS 5
  23. void *launch_starpu(void *unused)
  24. {
  25. int ret;
  26. (void) unused;
  27. ret = starpu_init(NULL);
  28. if (ret == -ENODEV)
  29. exit(STARPU_TEST_SKIPPED);
  30. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  31. return NULL;
  32. }
  33. void *shutdown_starpu(void *unused)
  34. {
  35. (void) unused;
  36. starpu_shutdown();
  37. return NULL;
  38. }
  39. int main(int argc, char **argv)
  40. {
  41. unsigned i;
  42. double timing;
  43. struct timeval start;
  44. struct timeval end;
  45. pthread_t threads[NUM_THREADS];
  46. gettimeofday(&start, NULL);
  47. for (i = 0; i < NUM_THREADS; ++i)
  48. {
  49. int ret = pthread_create(&threads[i], NULL, launch_starpu, NULL);
  50. STARPU_ASSERT(ret == 0);
  51. }
  52. for (i = 0; i < NUM_THREADS; ++i)
  53. {
  54. int ret = pthread_join(threads[i], NULL);
  55. STARPU_ASSERT(ret == 0);
  56. }
  57. gettimeofday(&end, NULL);
  58. timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  59. FPRINTF(stderr, "Success : %d threads launching simultaneously starpu_init\n", NUM_THREADS);
  60. FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
  61. FPRINTF(stderr, "Per task: %f usecs\n", timing/NUM_THREADS);
  62. for (i = 0; i < NUM_THREADS; i++)
  63. {
  64. int ret = pthread_create(&threads[i], NULL, shutdown_starpu, NULL);
  65. STARPU_ASSERT(ret == 0);
  66. }
  67. for (i = 0; i < NUM_THREADS; i++)
  68. {
  69. int ret = pthread_join(threads[i], NULL);
  70. STARPU_ASSERT(ret == 0);
  71. }
  72. return EXIT_SUCCESS;
  73. }