Guest User

Untitled

a guest
Apr 22nd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. /*version thread */
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4. #include <pthread.h>
  5. #include <math.h>
  6.  
  7. #define LIMITE 1000000000
  8. void* maFonction(void* data);
  9.  
  10. double tab[4];
  11.  
  12. int main()
  13. {
  14. printf("VERSION MULTI THREAD avec n=1000000000\n\n");
  15. printf("");
  16.  
  17. pthread_t thread0;// On crée un thread
  18. pthread_t thread1;// On crée un thread
  19. pthread_t thread2;// On crée un thread
  20. pthread_t thread3;// On crée un thread
  21.  
  22. pthread_create(&thread0, NULL, maFonction, (void*)0);// Permet d'exécuter le fonction maFonction en parallèle
  23. pthread_create(&thread1, NULL, maFonction, (void*)1);// Permet d'exécuter le fonction maFonction en parallèle
  24. pthread_create(&thread2, NULL, maFonction, (void*)2);// Permet d'exécuter le fonction maFonction en parallèle
  25. pthread_create(&thread3, NULL, maFonction, (void*)3);// Permet d'exécuter le fonction maFonction en parallèle
  26.  
  27. // Attend la fin des thread créés
  28. pthread_join(thread0, NULL);
  29. pthread_join(thread1, NULL);
  30. pthread_join(thread2, NULL);
  31. pthread_join(thread3, NULL);
  32.  
  33. printf("La constante d'euler: %.10f\n\n", tab[0]+tab[1]+tab[2]+tab[3]-log(LIMITE)); return 0;
  34. }
  35.  
  36.  
  37. void* maFonction(void* data){
  38. double i,tmp,somme=0;
  39. int coef=(int)data;
  40. i=1+coef;
  41.  
  42. while(i<LIMITE){
  43. tmp=(double)1/i;
  44. somme=somme+tmp;
  45. i+=4;
  46. }
  47. tab[coef]=somme;
  48.  
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment