pborawski

omp plik1.c

Nov 12th, 2012
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.24 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/wait.h>
  6. #include "errno.h"
  7. #include <string.h>
  8. #include <omp.h>
  9. #include <time.h>
  10.  
  11. int i, n = 9;
  12.  
  13. int main(int argc, char* argv[])
  14. {
  15.     //zadanie 1
  16.     //#pragma omp parallel
  17.     //{
  18.     //  if(omp_get_thread_num() == 0)
  19.     //  {
  20.     //          printf("watek 1\n");
  21.     //  }
  22.     //  printf("Region kodu wykonuje watek %d \n", omp_get_thread_num());
  23.     //}
  24.     // omp_get_thread_num() - zwraca nr watku ktory wykonuje zadanie
  25.     //zadanie 2
  26.  
  27.     double time_omp1 = omp_get_wtime(); // funkcja zwraca czas
  28.     double time_time1 = time(NULL); // funkcja zwraca czas
  29.    
  30.     // dyrektyw single powoduje wykonanie kawalka kodu na jednym rdzeniu
  31.     // bez tej dyrektywy printf wyswietli sie dwa razy
  32.     #pragma omp parallel default(none) shared(n) private(i)
  33.     {
  34.         #pragma omp single
  35.         printf("Dzialam na jednym procku\n");
  36.  
  37.         #pragma omp for
  38.         for(i = 0;i < n; i++)
  39.             printf("Przebieg %d wykonuje watek %d\n", i, omp_get_thread_num());
  40.  
  41.     }
  42.     double time_omp2 = omp_get_wtime();
  43.     double time_time2 = time(NULL);
  44.  
  45.     printf("Czas wykonania funkcja time(NULL) : %f\n",time_time2 - time_time1);
  46.     printf("Czas wykonania funkcja omp_get_wtime() : %f\n", time_omp2 - time_omp1);
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment