hello-openmp.c 502 B

1234567891011121314151617181920212223
  1. #include <omp.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. /* src de l'exemple: http://igrida.gforge.inria.fr/tutorial.html */
  5. int main (int argc, char *argv[]) {
  6. int th_id, nthreads;
  7. #pragma omp parallel private(th_id)
  8. {
  9. th_id = omp_get_thread_num();
  10. printf("Hello World from thread %d\n", th_id);
  11. sleep(60);
  12. #pragma omp barrier
  13. if ( th_id == 0 ) {
  14. nthreads = omp_get_num_threads();
  15. printf("There are %d threads\n",nthreads);
  16. }
  17. }
  18. return EXIT_SUCCESS;
  19. }