#include <iostream>
#include <stdio.h>
#include <omp.h>
#define N 1000
using namespace std;
struct Compare { int val; int index; };
#pragma omp declare reduction(maximum: int : struct Compare : omp_out = omp_in.val > omp_out.val ? omp_in : omp_out))
void selectionsort(int* arr, int size)
{
for (int i = size - 1; i > 0; --i)
{
struct Compare max;
max.val = arr[i];
max.index = i;
#pragma omp parallel reduction(maximum:max)
for (int j = i - 1; j >= 0; --j)
{
if (arr[j] > max.val)
{
max.val = arr[j];
max.index = j;
}
}
int tmp = arr[i];
arr[i] = max.val;
arr[max.index] = tmp;
}
}
int main()
{
int x[10] = { 8,7,9,1,2,5,4,3,0,6 };
selectionsort(x, 10);
for (int i = 0; i < 10; i++)
printf("%dn", x[i]);
return 0;
}