-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_parallel.cpp
More file actions
96 lines (85 loc) · 1.89 KB
/
simple_parallel.cpp
File metadata and controls
96 lines (85 loc) · 1.89 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <complex>
#include <ctime>
#include <fstream>
#include <iomanip>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <thread>
using namespace std;
#ifdef FIL
#include <fstream>
std::ifstream cin("inputMatrix2.txt");
std::ofstream cout("output2.txt");
#else
#include <iostream>
using std::cin;
using std::cout;
#endif
long long int mult(long long int* a,long long int *b,long long int n){
long long int sum = 0;
for (int i = 0; i < n; ++i)
{
sum+=a[i]*b[i];
}
return sum;
}
void thread_rcm(long long int* a,long long int *b, long long int **c, int i, int j,long long int n){
c[i][j] = mult(a,b,n);
}
int main(int argc, char* argv[])
{
long long int n;
cin >> n;
long long int* a[n];
long long int* b[n];
long long int **c = new long long int *[n];
std::thread *compute[n];
for(int i = 0; i < n; i++){
a[i] = new long long int[n];
b[i] = new long long int[n];
c[i] = new long long int[n];
compute[i] = new thread[n];
for(int j = 0; j < n; j++){
cin >> a[i][j];
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cin >> b[j][i];
}
}
int count = 0;
for(int i = 0; i < n; i++){
for (int j = 0; j < n; j++)
{
compute[i][j] = thread(thread_rcm,a[i],b[j],c,i,j,n);
}
}
for(int i = 0; i < n; i++){
for (int j = 0; j < n; j++)
{
compute[i][j].join();
}
}
for(int i = 0; i < n; i++){
for(int j = 0; j < n; j++){
cout << c[i][j] <<" ";
}
cout <<endl;
}
return 0;
}