multithreaded_init.c 1.7 KB

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