-
Notifications
You must be signed in to change notification settings - Fork 0
/
vec_mat_mul.cpp
45 lines (44 loc) · 984 Bytes
/
vec_mat_mul.cpp
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
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <omp.h>
#define MAX 10
using namespace std;
int main()
{
int vec[MAX], mat[MAX][MAX], res[MAX];
srand(time(NULL));
#pragma omp parallel for
for(int i=0; i<MAX; i++)
vec[i] = rand()%100;
cout<<"\nVector:"<<endl;
for(int i=0; i<MAX; i++)
cout<<vec[i]<<" ";
for(int i=0; i<MAX; i++)
{
#pragma omp parallel for
for(int j=0; j<MAX; j++)
mat[i][j] = rand()%100;
}
cout<<"\nMatrix:"<<endl;
for(int i=0; i<MAX; i++)
{
for(int j=0; j<MAX; j++)
cout<<mat[i][j]<<"\t";
cout<<endl;
}
#pragma omp parallel for
for(int i=0; i<MAX; i++)
res[i] = 0;
for(int i=0; i<MAX; i++)
{
#pragma omp parallel for
for(int j=0; j<MAX; j++)
res[i] += mat[i][j]*vec[j];
}
cout<<"Result:"<<endl;
for(int i=0; i<MAX; i++)
cout<<res[i]<<" ";
cout<<endl;
return 0;
}