multithreaded_init.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "../common/helper.h"
  22. #define NUM_THREADS 5
  23. void *launch_starpu(void *id)
  24. {
  25. int ret;
  26. ret = starpu_init(NULL);
  27. STARPU_CHECK_RETURN_VALUE(ret, "starpu_init");
  28. return NULL;
  29. }
  30. int main(int argc, char **argv)
  31. {
  32. unsigned i;
  33. double timing;
  34. struct timeval start;
  35. struct timeval end;
  36. pthread_t threads[NUM_THREADS];
  37. gettimeofday(&start, NULL);
  38. for (i = 0; i < NUM_THREADS; ++i)
  39. {
  40. int ret = pthread_create(&threads[i], NULL, launch_starpu, NULL);
  41. STARPU_ASSERT(ret == 0);
  42. }
  43. for (i = 0; i < NUM_THREADS; ++i)
  44. {
  45. int ret = pthread_join(threads[i], NULL);
  46. STARPU_ASSERT(ret == 0);
  47. }
  48. gettimeofday(&end, NULL);
  49. timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  50. FPRINTF(stderr, "Success : %d threads launching simultaneously starpu_init\n", NUM_THREADS);
  51. FPRINTF(stderr, "Total: %f secs\n", timing/1000000);
  52. FPRINTF(stderr, "Per task: %f usecs\n", timing/NUM_THREADS);
  53. starpu_shutdown();
  54. return EXIT_SUCCESS;
  55. }