Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <omp.h>
- #include "pomiar_czasu.h"
- double funkcja(double x)
- {
- return (4*(1/(1 + x*x)));
- }
- int main(int argc, char *argv[])
- {
- #ifdef _OPENMP
- printf("Kompilator rozpoznaje dyrektywy OpenMP\n");
- #endif
- const int N = 100000000;
- double xp = 0;
- double xk = 1;
- double dx;
- double suma = 0;
- int i;
- inicjuj_czas();
- #pragma omp parallel num_threads(1) firstprivate(xk, xp) private (dx, i) shared (suma)
- {
- dx = (xk - xp)/ N;
- #pragma omp for reduction (+: suma)
- for(i = 0; i < N; i++)
- {
- suma += funkcja(xp + i * dx) * dx;
- }
- }
- drukuj_czas();
- printf("wynik = %f\n", suma);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement