Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math.h>
- #include <time.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <windows.h>
- #include <iostream>
- using namespace std;
- void fillarray(int* pole ,int size)
- {
- srand(time(NULL));
- cout << "naplneni pole" << endl;
- for(int i=0; i< size ; i++ )
- {
- pole[i] = rand() % 50 ;
- }
- }
- void printarray( int *pole ,int size)
- {
- for(int i=0; i< size; i++ )
- {
- cout << pole[i] << " ";
- }
- cout << endl;
- }
- int kolik_ms(LPFILETIME pred, LPFILETIME po)
- {
- hyper pred64b = pred->dwHighDateTime;
- pred64b = (pred64b << 32) | pred->dwLowDateTime;
- hyper po64b = po->dwHighDateTime;
- po64b = (po64b << 32) | po->dwLowDateTime;
- return (int) ((po64b - pred64b) / 10000);
- }
- void insertsort(int pole[], int size)
- {
- for(int i=0 ;i <size ;i++ )
- {
- int j = i + 1 ;
- int tmp = pole[j];
- while( j > 0 && tmp > pole[j-1])
- {
- pole[j] = pole[j-1];
- j--;
- }
- pole[j] = tmp;
- }
- }
- struct struktura{
- int *pole;
- int velikost;
- };
- DWORD WINAPI vlakno(LPVOID pom)
- {
- struktura *tmp = (struktura *)pom;
- insertsort(tmp->pole, tmp->velikost);
- return 0;
- }
- int main (){
- cout << " kolik nahodnych cisel chces vygenerovat ? " << endl;
- cout << " program seradi cisla od nejmensiho po nejvetsi a zmeri cas jaky mu to trvalo" << endl;
- int N;
- cin >> N;
- while (1)
- {
- cout << "kolik jader chces do algoritmu zapojit ? " << endl;
- cout << "maximalni pocet jader zjistis stlacenim ctr + alt + del " << endl;
- cout << "v kolonce historie vyuziti procesoru pocet grafu je pocet jader/vlaken " << endl;
- int volba1;
- cin >> volba1;
- int * pole = new int[N];
- FILETIME cas_pred, cas_po;
- fillarray(pole,N);
- switch(volba1)
- {
- case 1 :
- cout << "trideni pracuje" << endl;
- struktura * struct1 = new struktura;
- struct1->pole = pole ;
- struct1->velikost =N;
- GetSystemTimeAsFileTime (&cas_pred);
- HANDLE p1 = CreateThread(0, 0, vlakno, struct1, 0, 0);
- WaitForSingleObject(p1, INFINITE);
- GetSystemTimeAsFileTime (&cas_po);
- cout << "cas trideni s " << volba1 << " jadery a "<< N << " nahodnych cisel trva :" << kolik_ms(&cas_pred , &cas_po) << "ms " << endl << endl;
- break;
- }
- /*default:
- struktura * struct1 = new struktura;
- struct1->pole = pole ;
- struct1->velikost =N;
- GetSystemTimeAsFileTime (&cas_pred);
- HANDLE p1 = CreateThread(0, 0, vlakno, struct1, 0, 0);
- WaitForSingleObject(p1, INFINITE);
- GetSystemTimeAsFileTime (&cas_po);
- break;*/
- }
- //printarray(pole);
- //
- //struktura * struct1 = new struktura;
- //struct1->pole = pole ;
- //struct1->velikost =N/4;
- //struktura * struct2 = new struktura;
- //struct2->pole = pole + N/4;
- //struct2->velikost = N/4;
- //struktura * struct3 = new struktura;
- //struct3->pole = pole + N/2;
- //struct3->velikost = N/4;
- //struktura * struct4 = new struktura;
- //struct4->pole = pole + (3/4 * N);
- //struct4->velikost = N/4;
- //
- //cout << " s vlakny " << endl;
- //GetSystemTimeAsFileTime (&cas_pred);
- // HANDLE p1 = CreateThread(0, 0, vlakno, struct1, 0, 0);
- //HANDLE p2 = CreateThread(0, 0, vlakno, struct2, 0, 0);
- //HANDLE p3 = CreateThread(0, 0, vlakno, struct3, 0, 0);
- //HANDLE p4 = CreateThread(0, 0, vlakno, struct4, 0, 0);
- // WaitForSingleObject(p1, INFINITE);
- // WaitForSingleObject(p2, INFINITE);
- // WaitForSingleObject(p3, INFINITE);
- // WaitForSingleObject(p4, INFINITE);
- //GetSystemTimeAsFileTime (&cas_po);
- // // printarray(pole);
- //
- // cout << "cas vlakna " << N << " nahodnych cisel trva :" << kolik_ms(&cas_pred , &cas_po) << "ms " << endl;
- //
- //
- // GetSystemTimeAsFileTime (&cas_pred);
- //// printarray(pole2);
- //
- //// printarray(pole2);
- // GetSystemTimeAsFileTime (&cas_po);
- //
- // cout << "bez claken : " << N << " nahodnych cisel trva :" << kolik_ms(&cas_pred , &cas_po) << "ms " << endl;
- //
- system("pause") ;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement