multithreaded_init.c 1.8 KB

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