pastebin

Paste Search Dynamic
Recent pastes
struct Compare
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <omp.h>
  4. #define N 1000
  5. using namespace std;
  6.  
  7.  
  8. struct Compare { int val; int index; };
  9. #pragma omp declare reduction(maximum: int : struct Compare : omp_out = omp_in.val > omp_out.val ? omp_in : omp_out))
  10. void selectionsort(int* arr, int size)
  11. {
  12.     for (int i = size - 1; i > 0; --i)
  13.     {
  14.         struct Compare max;
  15.         max.val = arr[i];
  16.         max.index = i;
  17. #pragma omp parallel reduction(maximum:max)
  18.         for (int j = i - 1; j >= 0; --j)
  19.         {
  20.             if (arr[j] > max.val)
  21.             {
  22.                 max.val = arr[j];
  23.                 max.index = j;
  24.             }
  25.         }
  26.         int tmp = arr[i];
  27.         arr[i] = max.val;
  28.         arr[max.index] = tmp;
  29.     }
  30. }
  31.  
  32. int main()
  33. {
  34.     int x[10] = { 8,7,9,1,2,5,4,3,0,6 };
  35.     selectionsort(x, 10);
  36.  
  37.     for (int i = 0; i < 10; i++)
  38.         printf("%dn", x[i]);
  39.     return 0;
  40. }
Parsed in 0.016 seconds