Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <windows.h>
- #include <stdio.h>
- #include <iostream>
- #include <ctime>
- using namespace std;
- #define beg 10.0
- #define end 20.0
- #define NTh 4//количество потоков
- #define NRec 1000.0//количество прямоугольников
- double Sum = 0;
- double x=beg+((end - beg) / (2*NRec));
- void WINAPI ThreadProc()
- {
- for (double i = 0; i < NRec / NTh; i++)
- {
- Sum += (x * x -x -5 )*((end - beg) / NRec);
- x += (end - beg) / NRec;
- }
- }
- int main(int argc, char* argv[])
- {
- setlocale(LC_CTYPE, "rus");
- HANDLE Thread[NTh];
- double start_time = clock();
- for (int i = 0; i < NTh; i++)
- Thread[i] = CreateThread(0, 0, (LPTHREAD_START_ROUTINE)ThreadProc, 0, 0, 0);
- WaitForMultipleObjects(NTh, Thread, TRUE, INFINITE);
- double finish_time = clock();
- cout << "number rectangles: " << NRec << endl;
- cout << "number threads: " << NTh<< endl;
- cout << "time: " << (finish_time - start_time) / 1000 << endl;
- cout << "result : " << Sum << endl;
- cout << "error: " << Sum/(6400/3.) << endl;
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement