Created
May 19, 2015 12:02
-
-
Save antonshilov/3a99fe6518a8bfbf579d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <time.h> | |
#include <windows.h> | |
#include <iostream> | |
#include <string> | |
using std::cout; | |
using std::cin; | |
using std::endl; | |
using std::string; | |
using std::to_string; | |
int main() | |
{ | |
srand(time(NULL)); | |
int size = 0; | |
cout << "Arr size: "; | |
cin >> size; | |
int* A = new int[size]; | |
for (int i = 0; i < size; i++) | |
A[i] = rand() % 100; | |
for (int i = 0; i < size; i++) | |
cout << A[i] << " "; | |
cout << endl; | |
string str; | |
DWORD StartTime = GetTickCount(); | |
#pragma omp parallel private(str) | |
{ | |
int i, j = 0; | |
#pragma omp for | |
for (i = 0; i < size - 1; i++) | |
{ | |
j = i; | |
if (j > 0) | |
if (A[j - 1] > A[j]) | |
continue; | |
if (A[j] > A[j + 1]) | |
{ | |
str = to_string(A[j]) + " "; | |
while (A[j] > A[j + 1]) | |
{ | |
str += to_string(A[j + 1]) + " "; | |
j++; | |
if (j == size - 1) | |
break; | |
} | |
#pragma omp critical (section1) | |
{ | |
cout << str << endl;//Можно заменить вывод, например в файл, или сохранять в памяти | |
} | |
} | |
} | |
} | |
DWORD EndTime = GetTickCount(); | |
DWORD ElapsedTime = EndTime - StartTime; | |
cout << "Exec time:" << ElapsedTime << " millisec" << endl; | |
system("pause"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment