Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // całkaPoj.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <omp.h>
- #include <iostream>
- #include <math.h>
- #include<stdlib.h>
- #include <time.h>
- using namespace std;
- double calka=0, czesccalki=0; //poczatkow wartosci
- int i, j; //iteratory
- double xp = 0; // przedzialy
- double xk = 2;
- double h = (xk - xp) / 1000; //krok, wysokość prostokąta
- double f(double x, int iterator)
- {
- return sin(iterator*x) / (1+iterator); //wzor na calke
- }
- clock_t start;
- int main()
- {
- //omp_set_nested(1);
- start = clock();
- #pragma omp parallel for private(i,j,calka) shared(h) num_threads(4)
- for (i = 1; i< 100 ; i++)
- {
- calka = 0.0;
- #pragma omp parallel for reduction (+:czesccalki)
- for (j = 1; j < 1000; j++)
- {
- czesccalki = f(xp + (j*h), i)*h;
- calka += czesccalki;
- }
- printf("dla k %d calka: %f \n", i, calka);
- }
- printf("Czas obliczania calki= %lu ms \n\n", clock() - start);
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement