Created
December 19, 2018 17:47
-
-
Save agalakhov/c5d025b890be5bc20c86cf27b903beff to your computer and use it in GitHub Desktop.
This file contains 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 <iostream> | |
#include <omp.h> | |
#include "tbb/task_scheduler_init.h" | |
#include "tbb/blocked_range.h" | |
#include "tbb/parallel_for.h" | |
using namespace std; | |
using namespace tbb; | |
void L_matrix(int ** A, int n, int * B, int * C) | |
{ | |
parallel_for( | |
blocked_range<int>(0, n), | |
[=](const blocked_range<int>& r) | |
{ | |
for (int i = r.begin(); i != r.end(); i++) | |
{ | |
C[i] = 0; | |
for (int j = 0; j < n; ++j) | |
{ | |
C[i] += A[i][j] * B[j]; | |
} | |
} | |
} | |
); | |
} | |
void matrix(int** A, int n, int* B, int* C) | |
{ | |
# pragma omp parallel for | |
for (int i = 0; i < n; i++) | |
{ | |
int Sum = 0; | |
for (int j = 0; j < n; j++) | |
{ | |
Sum += A[i][j] * B[i]; | |
} | |
C[i] = Sum; | |
} | |
} | |
int main() | |
{ | |
srand(time(NULL)); | |
int n = 5; | |
int** A = new int* [n]; | |
int* B = new int [n]; | |
for (int i = 0; i < n; i++) | |
{ | |
A[i] = new int[n]; | |
for (int j = 0; j < n; j++) | |
{ | |
A[i][j] = rand() % 9 + 1; | |
B[i] = rand() % 9 + 1; | |
} | |
} | |
cout << "sequential task:"; | |
cout << endl; | |
/* | |
int * C = new int[n]; | |
for (int i = 0; i < n; i++) | |
{ | |
C[i] = 0; | |
} | |
matrix(A, n, B, C); | |
for (int i = 0; i < n; i++) | |
{ | |
cout << C[i] << " "; | |
} | |
cout << endl; */ | |
cout << "L-function task:"; | |
cout << endl; | |
int * V = new int[n]; | |
L_matrix(A, n, B, V); | |
for (int i = 0; i < n; i++) | |
{ | |
cout << V[i] << " "; | |
} | |
cout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment