-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.cc
More file actions
72 lines (65 loc) · 1.76 KB
/
example.cc
File metadata and controls
72 lines (65 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Paralelismo local calculando celda por celda de una matriz con hilos
*/
#include <iostream>
#include <vector>
#include <chrono>
#include "Threadpool.h"
using namespace std;
const int n = 3;
int multiplicacion(const int A[n][n], const int B[n][n], int i, int j){
int resultado = 0;
for(int k=0;k<n;k++)
resultado += A[i][k]*B[k][j];
return resultado;
}
int* multiplicacionf(const int A[n][n], const int B[n][n],int* C, int i){
for(int j=0;j<n;j++){
for(int k=0;k<n;k++)
C[j] += A[i][k]*B[k][j];
}
return C;
}
int main()
{
int A[n][n] = {{1,2,3}, // 1 2 3 1 2 3 6 12 18
{2,3,4}, // 2 3 4 X 1 2 3 = 9 18 27
{3,4,5}}; // 3 4 5 1 2 3 12 24 36
int B[n][n] = {{1,2,3},
{1,2,3},
{1,2,3}};
// cout <<thread::hardware_concurrency() << endl;
ThreadPool pool(thread::hardware_concurrency());
/*
vector<future<int>> results;
for(int i = 0; i < n;i++){
for(int j = 0;j<n;j++){
// cout<<i<<j<<endl;
results.emplace_back(
pool.enqueue([A,B,i,j] {
return multiplicacion(A,B,i,j);
})
);
}
}
for(auto && result: results){
int resultados = result.get();
cout << resultados << ' '<<*&resultados<<' ';
}
*/
int matrizresult[n][n];
int* col;
vector<future<int*>> results;
for(int i = 0; i < n;i++){
results.emplace_back(
pool.enqueue([A,B,i,col] {
return multiplicacionf(A,B, col, i);
})
);
}
for(auto && result: results){
int* resultados = result.get();
cout << resultados <<' ';
}
return 0;
}