Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <time.h>
- #include <stdio.h>
- #include <omp.h>
- int main()
- {
- double startpr, endpr;
- omp_set_num_threads(1111);
- printf("There are %d processors on this machine\n", omp_get_num_procs());
- startpr = omp_get_wtime();
- const int n = 1e7; //количество случ. точек
- srand(time(NULL));
- int i;
- double x, y;
- int in_circle = 0;
- #pragma omp parallel for private(i, x, y) reduction (+:in_circle)
- for (i = 0; i < n; ++i)
- {
- x = 1.0*rand()/RAND_MAX;
- y = 1.0*rand()/RAND_MAX;
- if (x*x + y*y <= 1.0)
- ++in_circle;
- }
- endpr = omp_get_wtime();
- printf("%lf\n", 4.0*in_circle/n);
- printf("Calculating time: %lf sec\n", endpr - startpr);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement