-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix (2).cpp
More file actions
181 lines (158 loc) · 3.58 KB
/
matrix (2).cpp
File metadata and controls
181 lines (158 loc) · 3.58 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*#include <cstdlib>
#include <ctime>
#include <iostream>
using namespace std;
#define MATRIX_DIM 2048
int main(int argc, char **argv)
{
int i, j;
double** m1 = new double*[MATRIX_DIM];
for (int i = 0; i < MATRIX_DIM; ++i)
m1[i] = new double[MATRIX_DIM];
for(i=0;i<MATRIX_DIM;i++)
{
for(j=0;j<MATRIX_DIM;j++)
{
m1[i][j]=9.5;
}
}
for(i=0;i<MATRIX_DIM;i++)
{
for(j=0;j<MATRIX_DIM;j++)
{
cout<<m1[i][j];
}
cout<<endl;
}
cout<<m1[2047][2047];
for (int i = 0; i < MATRIX_DIM; ++i)
delete [] m1[i];
delete [] m1;
int i, c;
char *big_massive = new char[1073741824];
srand((unsigned)time(0));
for(;;)
{
i = (rand()%1073741824)+1;
big_massive[i]=55;
cout<<big_massive[i]<<endl;
}
cin>>c;
delete big_massive;
return 0;
}*/
// #include <iostream>
// #include <thread>
//
// //This function will be called from a thread
//
// void call_from_thread() {
// std::cout << "Hello, World" << std::endl;
// }
//
// int main() {
// //Launch a thread
// std::thread t1(call_from_thread);
// //Join the thread with the main thread
// t1.join();
//
// return 0;
// }
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
const int VECTOR_DIM = 2048;
void vector_matrix_mult()
{
register int i, j, k;
using namespace boost::numeric::ublas;
matrix<int> m(VECTOR_DIM, VECTOR_DIM);
vector<int> v_in(VECTOR_DIM);
vector<int> v_out(VECTOR_DIM);
for(i = 0; i < VECTOR_DIM; ++i) {
for(j = 0; j < VECTOR_DIM; ++j) {
m(i, j) = i + j;
}
v_in(i) = i;
v_out(i) = 0;
}
clock_t startTime, endTime;
for(;;)
{
startTime = clock();
for (i = 0; i < VECTOR_DIM ; ++ i)
{
for ( j = 0; j < VECTOR_DIM; ++ j)
{
v_out(i) = v_out(i) + v_in(j)* m(i,j);
}
}
//v_out = prod(v_in, m);
endTime = clock();
std::cout << double(endTime - startTime) << std::endl;
}
//std::cout << v_in << std::endl;
//std::cout << m << std::endl;
//std::cout << v_out << std::endl;
std::cin >> k;
}
//
//
//
//
//#include <cstdlib>
//#include <ctime>
//#include <iostream>
//#include <boost/numeric/ublas/matrix.hpp>
//#include <boost/numeric/ublas/io.hpp>
//const int VECTOR_DIM = 2048;
//
//int Matrix_Mult()
//{
// int i, j, k;
// using namespace boost::numeric::ublas;
// matrix<double> m_out(VECTOR_DIM, VECTOR_DIM);
// matrix<double> m_1(VECTOR_DIM, VECTOR_DIM);
// matrix<double> m_2(VECTOR_DIM, VECTOR_DIM);
//
// for(i = 0; i < VECTOR_DIM; ++i)
// {
// for(j = 0; j < VECTOR_DIM; ++j)
// {
// m_1(i, j) = i + j;
// m_2(i, j) = i + j;
// m_out(i, j) = 0;
// }
// }
//
// clock_t startTime, endTime;
// startTime = clock();
//
//
// for (i = 0; i < VECTOR_DIM ; ++ i)
// {
// for ( j = 0; j < VECTOR_DIM; ++ j)
// {
// for ( k = 0; k < VECTOR_DIM; ++ k)
// {
// m_out(i,j) = m_out(i,j) + m_1(i,k)* m_2(k,j);
// }
// }
// }
//
// //m_out = prod(m_1, m_2);
//
// endTime = clock();
// std::cout << double(endTime - startTime) << std::endl;
// //std::cout << m_1 << std::endl;
// //std::cout << m_2 << std::endl;
// //std::cout << m_out << std::endl;
// std::cin >> k;
//}
int main()
{
vector_matrix_mult();
return 0;
}