Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <omp.h>
- #include <math.h>
- //#include "pomiar_czasu.h"
- double function (double x)
- {
- return (5*x)/(sqrt(x));
- }
- double x1 = 10, x2 = 100, dx, calka = 0;
- int i, n = 1000000;
- int main(void)
- {
- printf("\n ********************************************************* \n ");
- /*printf("\nPodaj x1\n");
- scanf("%f", &x1);
- printf("\nPodaj x2\n");
- scanf("%f", &x2);
- printf("\nPodaj dokladnosc\n");
- scanf("%d", &n);*/
- double start_time = omp_get_wtime();
- dx = (x2-x1) / (double) n;
- //printf("\nSekwencyjnie\n");
- printf("\nParallel - 4 \n");
- #pragma omp parallel for reduction (+: calka) num_threads(4)
- for (i = 1; i < n; ++i) {
- calka += function(x1+i * dx);
- }
- calka += (function(x1) + function(x2)) / 2;
- calka *= dx;
- double time = omp_get_wtime() - start_time;
- printf("\nCalka wynosi: %lf\n", calka);
- printf("\nCzas wynosi: %lf\n", time);
- printf("\n ********************************************************** \n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement