Facebook
From Aqua Mockingjay, 6 Years ago, written in Plain Text.
This paste is a reply to Untitled from Walloping Bison - go back
Embed
Viewing differences between Untitled and Re: Untitled
#include 
#include 
#include 

long long num_steps = 1000000000;
10000000;
double step;

int main(int argc, char* argv[])
{
        clock_t start, stop;
        volatile double x;
        double pi, sum = 0.0, tab[40];
        
tab[50];
        
int i;
i, j;
        step = 1. / (double)num_steps;
        start = clock();
#pragma omp parallel
        { int id = omp_get_thread_num();
        tab[id] = 0;
#pragma omp 
omp_set_num_threads(4);
        
for reduction(+:sum)
        for (i 
(j = 0; j < 39; j++)                //do mierzenia czasu dostępu do pamięci < num_steps; i++)
długości lini
        {
                sum = 0;
                start = clock();
        #pragma omp parallel
                { int id = omp_get_thread_num();
                tab[j+id] = 0;
#pragma omp for schedule(dynamic, 10000)
                for (i = 0; i < num_steps; i++)
                {
                        
x = (i + .5)*step;
                tab[id]                         tab[j+id] += 4.0 / (1. + x*x);
                }
        #pragma atomic
                sum += tab[j+id];
                }

                pi = sum*step;
                stop = clock();

                printf("Wartosc liczby PI wynosi %15.12f\n", pi);
                printf("Czas przetwarzania iteraccji %d wynosi %f sekund\n", j, ((double)(stop - start) / 1000.0));
        }
#pragma atomic
        sum += tab[id];
        }

        pi = sum*step;
        stop = clock();

        printf("Wartosc liczby PI wynosi %15.12fn", pi);
        printf("Czas przetwarzania wynosi %f sekundn", ((double)(stop - start) / 1000.0));
        return 0;
}