Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sections.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- #include <iostream>
- #include <omp.h>
- using namespace std;
- void bubbleSort(int arr[], int n) {
- bool swapped = true;
- int j = 0;
- int tmp;
- while (swapped) {
- swapped = false;
- j++;
- for (int i = 0; i < n - j; i++) {
- if (arr[i] > arr[i + 1]) {
- tmp = arr[i];
- arr[i] = arr[i + 1];
- arr[i + 1] = tmp;
- swapped = true;
- }
- }
- }
- }
- int main()
- {
- int tab1[10], tab2[10], tab3[10], tab4[10];
- int k = 10;
- for (int i = 0; i < 10; i++) {
- tab1[i] = k - i;
- tab2[i] = k * i - i;
- tab3[i] = tab2[i] - tab1[i] - i;
- tab4[i] = tab1[i] * tab2[i] * tab3[i] - tab1[i] - tab2[i] - tab3[i];
- }
- cout << "########################PRZED ZROWNOLEGLENIEM######################## " << endl;
- for (int i = 0; i < 10; i++) {
- cout << "tab1[" << i << "] = " << tab1[i];
- cout << " tab2[" << i << "] = " << tab2[i];
- cout << " tab3[" << i << "] = " << tab3[i];
- cout << " tab4[" << i << "] = " << tab4[i] << endl;
- }
- #pragma omp parallel sections
- {
- #pragma omp section
- {
- #pragma omp critical
- {
- cout << "########################" << endl;
- cout << "NR WATKU OD TAB1 = " << omp_get_thread_num() << endl;
- }
- bubbleSort(tab1, 10);
- }
- #pragma omp section
- {
- #pragma omp critical
- {
- cout << "NR WATKU OD TAB2 = " <<omp_get_thread_num() << endl;
- }
- bubbleSort(tab2, 10);
- }
- #pragma omp section
- {
- #pragma omp critical
- {
- cout << "NR WATKU OD TAB3 = " <<omp_get_thread_num() << endl;
- }
- bubbleSort(tab3, 10);
- }
- #pragma omp section
- {
- #pragma omp critical
- {
- cout << "NR WATKU OD TAB4 = " <<omp_get_thread_num() << endl;
- cout << "########################" << endl;
- }
- bubbleSort(tab4, 10);
- }
- }
- cout << "########################PO ZROWNOLEGLENIU########################" << endl;
- for (int i = 0; i < 10; i++) {
- cout << "tab1[" << i << "] = " << tab1[i];
- cout << " tab2[" << i << "] = " << tab2[i];
- cout << " tab3[" << i << "] = " << tab3[i];
- cout << " tab4[" << i << "] = " << tab4[i] << endl;
- }
- getchar();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement