Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/wait.h>
- #include "errno.h"
- #include <string.h>
- #include <omp.h>
- #include <time.h>
- int i, n = 9;
- int main(int argc, char* argv[])
- {
- //zadanie 1
- //#pragma omp parallel
- //{
- // if(omp_get_thread_num() == 0)
- // {
- // printf("watek 1\n");
- // }
- // printf("Region kodu wykonuje watek %d \n", omp_get_thread_num());
- //}
- // omp_get_thread_num() - zwraca nr watku ktory wykonuje zadanie
- //zadanie 2
- double time_omp1 = omp_get_wtime(); // funkcja zwraca czas
- double time_time1 = time(NULL); // funkcja zwraca czas
- // dyrektyw single powoduje wykonanie kawalka kodu na jednym rdzeniu
- // bez tej dyrektywy printf wyswietli sie dwa razy
- #pragma omp parallel default(none) shared(n) private(i)
- {
- #pragma omp single
- printf("Dzialam na jednym procku\n");
- #pragma omp for
- for(i = 0;i < n; i++)
- printf("Przebieg %d wykonuje watek %d\n", i, omp_get_thread_num());
- }
- double time_omp2 = omp_get_wtime();
- double time_time2 = time(NULL);
- printf("Czas wykonania funkcja time(NULL) : %f\n",time_time2 - time_time1);
- printf("Czas wykonania funkcja omp_get_wtime() : %f\n", time_omp2 - time_omp1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment