Advertisement
Guest User

Untitled

a guest
Dec 13th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.17 KB | None | 0 0
  1. // sections.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <omp.h>
  7.  
  8. using namespace std;
  9.  
  10. void bubbleSort(int arr[], int n) {
  11.     bool swapped = true;
  12.     int j = 0;
  13.     int tmp;
  14.     while (swapped) {
  15.         swapped = false;
  16.         j++;
  17.         for (int i = 0; i < n - j; i++) {
  18.             if (arr[i] > arr[i + 1]) {
  19.                 tmp = arr[i];
  20.                 arr[i] = arr[i + 1];
  21.                 arr[i + 1] = tmp;
  22.                 swapped = true;
  23.             }
  24.         }
  25.     }
  26. }
  27.  
  28. int main()
  29. {
  30.     int tab1[10], tab2[10], tab3[10], tab4[10];
  31.     int k = 10;
  32.  
  33.     for (int i = 0; i < 10; i++) {
  34.         tab1[i] = k - i;
  35.         tab2[i] = k * i - i;
  36.         tab3[i] = tab2[i] - tab1[i] - i;
  37.         tab4[i] = tab1[i] * tab2[i] * tab3[i] - tab1[i] - tab2[i] - tab3[i];
  38.     }
  39.  
  40.     cout << "########################PRZED ZROWNOLEGLENIEM######################## " << endl;
  41.     for (int i = 0; i < 10; i++) {
  42.         cout << "tab1[" << i << "] = " << tab1[i];
  43.         cout << " tab2[" << i << "] = " << tab2[i];
  44.         cout << " tab3[" << i << "] = " << tab3[i];
  45.         cout << " tab4[" << i << "] = " << tab4[i] << endl;
  46.     }
  47.  
  48.  
  49. #pragma omp parallel sections
  50.     {
  51.         #pragma omp section
  52.         {
  53.             #pragma omp critical
  54.                 {  
  55.                     cout << "########################" << endl;
  56.                     cout << "NR WATKU OD TAB1 = " << omp_get_thread_num() << endl;
  57.                 }
  58.             bubbleSort(tab1, 10);
  59.         }
  60.         #pragma omp section
  61.         {
  62.             #pragma omp critical
  63.                 {
  64.                     cout << "NR WATKU OD TAB2 = " <<omp_get_thread_num() << endl;
  65.                 }
  66.             bubbleSort(tab2, 10);
  67.         }
  68.         #pragma omp section
  69.         {
  70.             #pragma omp critical
  71.                 {
  72.                     cout << "NR WATKU OD TAB3 = " <<omp_get_thread_num() << endl;
  73.                 }
  74.             bubbleSort(tab3, 10);
  75.         }
  76.         #pragma omp section
  77.         {
  78.             #pragma omp critical
  79.                 {
  80.                     cout << "NR WATKU OD TAB4 = " <<omp_get_thread_num() << endl;
  81.                     cout << "########################" << endl;
  82.                 }
  83.             bubbleSort(tab4, 10);
  84.         }
  85.     }
  86.  
  87.     cout << "########################PO ZROWNOLEGLENIU########################" << endl;
  88.     for (int i = 0; i < 10; i++) {
  89.         cout << "tab1[" << i << "] = " << tab1[i];
  90.         cout << " tab2[" << i << "] = " << tab2[i];
  91.         cout << " tab3[" << i << "] = " << tab3[i];
  92.         cout << " tab4[" << i << "] = " << tab4[i] << endl;
  93.     }
  94.     getchar();
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement