multithreaded_init.c 1013 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include <sys/time.h>
  2. #include <stdio.h>
  3. #include <pthread.h>
  4. #include <starpu.h>
  5. #define NUM_THREADS 5
  6. void *launch_starpu(void *id)
  7. {
  8. starpu_init(NULL);
  9. return NULL;
  10. }
  11. int main(int argc, char **argv)
  12. {
  13. unsigned i;
  14. double timing;
  15. struct timeval start;
  16. struct timeval end;
  17. pthread_t threads[NUM_THREADS];
  18. gettimeofday(&start, NULL);
  19. for (i = 0; i < NUM_THREADS; ++i)
  20. {
  21. int ret = pthread_create(&threads[i], NULL, launch_starpu, NULL);
  22. STARPU_ASSERT(ret == 0);
  23. }
  24. for (i = 0; i < NUM_THREADS; ++i)
  25. {
  26. int ret = pthread_join(threads[i], NULL);
  27. STARPU_ASSERT(ret == 0);
  28. }
  29. gettimeofday(&end, NULL);
  30. timing = (double)((end.tv_sec - start.tv_sec)*1000000 + (end.tv_usec - start.tv_usec));
  31. fprintf(stderr, "Success : %d threads launching simultaneously starpu_init\n", NUM_THREADS);
  32. fprintf(stderr, "Total: %lf secs\n", timing/1000000);
  33. fprintf(stderr, "Per task: %lf usecs\n", timing/NUM_THREADS);
  34. starpu_shutdown();
  35. return 0;
  36. }