Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <time.h>
- #include <omp.h>
- #include <iostream>
- #define _CRT_SECURE_NO_WARNINGS
- using namespace std;
- #define SIZE_DARR 100000000
- double arr[SIZE_DARR];
- void my_func(__int64 count) { // заполняет массив синусами
- for (__int64 i = 0; i < count; i++)
- arr[i] = asin((double)((i / count) % 100007));
- }
- int main() {
- setlocale(LC_CTYPE, "rus"); // кириллизация
- double a, b, result = 0, h;
- clock_t t_start, time;
- __int64 n = 1000;
- cout << "Введите a: "; cin >> a;
- cout << "\nВведите b: "; cin >> b;
- my_func(1000000);
- h = (b - a) / n;
- omp_set_dynamic(0);
- cout << "proc = " << omp_get_num_procs() << "\n";
- cout << "threads = " << omp_get_num_threads() << "\n";
- for (int flow = 1; flow <= 8; flow++) {// количество потоков
- cout << "\n\nflow = " << flow << "\n_______________" << "\n_______________";
- for (int count = 100; count < 1000000; count *= 10) { // гранулярность задачи 100-1000000
- t_start = clock();
- # pragma omp parallel for reduction(+:result) num_threads(flow)
- for (int iCount = 0; iCount < count; iCount++) { // повтор count раз
- result = 0;
- for (int i = 1; i < n; i++) { // нахождение интеграла
- result += asin((a + i * h) - h / 2);
- }
- result *= h;
- }
- time = clock() - t_start;
- cout << "\ncount = " << count;
- cout << "\ntime = " << time << " мс.\n____________\n";
- }
- }
- system("pause");
- return 0;
- }
- /*int main() {
- setlocale(LC_CTYPE, "rus"); // кириллизация
- double a, b, result = 0, h;
- clock_t t_start, time;
- __int64 n = 100000;
- cout << "Введите a: "; cin >> a;
- cout << "\nВведите b: "; cin >> b;
- my_func(100000);
- h = (b - a) / n;
- omp_set_dynamic(0);
- //omp_set_num_threads(1);
- int count = 100;
- for (int flow = 1; flow < 8; flow++) {
- t_start = clock();
- cout << "\nflow = " << flow << "\n_______________\n________________";
- for (int j = 0; j <= count; j++) {
- #pragma omp parallel for reduction(+:result) num_threads(flow)// firstprivate(a)
- for (int i = 1; i < n; i++) {
- result += asin((a + i * h) - h / 2);
- }
- result *= h;
- }
- time = clock() - t_start;
- cout << "\nres = " << result;
- cout << "\ntime = " << time << " мс.\n______________________\n";
- count *= 10;
- }
- system("pause");
- return 0;
- }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement