11 std::chrono::steady_clock::time_point gen_start_time =
12 std::chrono::steady_clock::now();
19 std::random_device rd;
20 std::mt19937 gen(rd());
21 std::uniform_int_distribution<int> distribution(1, 100);
26 A[i][j] = distribution(gen);
27 B[i][j] = distribution(gen);
31 std::chrono::steady_clock::time_point start_time_mtx =
32 std::chrono::steady_clock::now();
35 std::chrono::steady_clock::time_point start_time_std_mtx =
36 std::chrono::steady_clock::now();
64 std::chrono::steady_clock::time_point end_time =
65 std::chrono::steady_clock::now();
67 std::cout <<
"Generating random matrices (VECTORS) - Time elapsed: "
68 << std::chrono::duration_cast<std::chrono::milliseconds>(
69 start_time_mtx - gen_start_time)
71 <<
" ms" << std::endl;
73 std::cout <<
"SIMD - Time elapsed: "
74 << std::chrono::duration_cast<std::chrono::milliseconds>(
75 start_time_std_mtx - start_time_mtx)
77 <<
" ms" << std::endl;
79 std::cout <<
"NAIVE - Time elapsed: "
80 << std::chrono::duration_cast<std::chrono::milliseconds>(
81 end_time - start_time_std_mtx)
83 <<
" ms" << std::endl;
89 std::chrono::steady_clock::time_point gen_start_time =
90 std::chrono::steady_clock::now();
100 std::random_device rd;
101 std::mt19937 gen(rd());
102 std::uniform_real_distribution<float> distribution(1.0, 100.0);
107 A[i][j] = distribution(gen);
108 B[i][j] = distribution(gen);
112 std::chrono::steady_clock::time_point start_time_mtx =
113 std::chrono::steady_clock::now();
116 std::chrono::steady_clock::time_point start_time_std_mtx =
117 std::chrono::steady_clock::now();
145 std::chrono::steady_clock::time_point end_time =
146 std::chrono::steady_clock::now();
148 std::cout <<
"Generating random matrices (VECTORS, FLOATS) - Time elapsed: "
149 << std::chrono::duration_cast<std::chrono::milliseconds>(
150 start_time_mtx - gen_start_time)
152 <<
" ms" << std::endl;
154 std::cout <<
"SIMD - Time elapsed: "
155 << std::chrono::duration_cast<std::chrono::milliseconds>(
156 start_time_std_mtx - start_time_mtx)
158 <<
" ms" << std::endl;
160 std::cout <<
"NAIVE - Time elapsed: "
161 << std::chrono::duration_cast<std::chrono::milliseconds>(
162 end_time - start_time_std_mtx)
164 <<
" ms" << std::endl;
170 std::chrono::steady_clock::time_point gen_start_time =
171 std::chrono::steady_clock::now();
181 std::random_device rd;
182 std::mt19937 gen(rd());
183 std::uniform_real_distribution<double> distribution(1.0, 100.0);
188 A[i][j] = distribution(gen);
189 B[i][j] = distribution(gen);
193 std::chrono::steady_clock::time_point start_time_mtx =
194 std::chrono::steady_clock::now();
197 std::chrono::steady_clock::time_point start_time_std_mtx =
198 std::chrono::steady_clock::now();
226 std::chrono::steady_clock::time_point end_time =
227 std::chrono::steady_clock::now();
230 <<
"Generating random matrices (VECTORS, DOUBLES) - Time elapsed: "
231 << std::chrono::duration_cast<std::chrono::milliseconds>(
232 start_time_mtx - gen_start_time)
234 <<
" ms" << std::endl;
236 std::cout <<
"SIMD - Time elapsed: "
237 << std::chrono::duration_cast<std::chrono::milliseconds>(
238 start_time_std_mtx - start_time_mtx)
240 <<
" ms" << std::endl;
242 std::cout <<
"NAIVE - Time elapsed: "
243 << std::chrono::duration_cast<std::chrono::milliseconds>(
244 end_time - start_time_std_mtx)
246 <<
" ms" << std::endl;
252 std::chrono::steady_clock::time_point gen_start_time =
253 std::chrono::steady_clock::now();
265 std::random_device rd;
266 std::mt19937 gen(rd());
267 std::uniform_int_distribution<int> distribution(1, 100);
277 std::chrono::steady_clock::time_point start_time_mtx =
278 std::chrono::steady_clock::now();
281 std::chrono::steady_clock::time_point start_time_std_mtx =
282 std::chrono::steady_clock::now();
286 std::chrono::steady_clock::time_point end_time =
287 std::chrono::steady_clock::now();
289 std::cout <<
"Generating random matrices (ARRAYS, INT) - Time elapsed: "
290 << std::chrono::duration_cast<std::chrono::milliseconds>(
291 start_time_mtx - gen_start_time)
293 <<
" ms" << std::endl;
295 std::cout <<
"SIMD - Time elapsed: "
296 << std::chrono::duration_cast<std::chrono::milliseconds>(
297 start_time_std_mtx - start_time_mtx)
299 <<
" ms" << std::endl;
301 std::cout <<
"NAIVE - Time elapsed: "
302 << std::chrono::duration_cast<std::chrono::milliseconds>(
303 end_time - start_time_std_mtx)
305 <<
" ms" << std::endl;
313 std::random_device rd;
314 std::mt19937 gen(rd());
315 std::uniform_real_distribution<float> distribution(1.0, 100.0);
317 for (std::size_t i = 0; i <
rows; ++i) {
318 for (std::size_t j = 0; j <
cols; ++j) {
319 matrix[i *
cols + j] = distribution(gen);
325 for (std::size_t i = 0; i <
rows; ++i) {
326 for (std::size_t j = 0; j <
cols; ++j) {
327 std::cout << matrix[i *
cols + j] <<
" ";
329 std::cout << std::endl;
336 std::chrono::steady_clock::time_point gen_start_time =
337 std::chrono::steady_clock::now();
346 std::chrono::steady_clock::time_point mtx_start_time =
347 std::chrono::steady_clock::now();
352 std::chrono::steady_clock::time_point end_time =
353 std::chrono::steady_clock::now();
365 std::cout <<
"Generating random matrices (ARRAYS) - Time elapsed: "
366 << std::chrono::duration_cast<std::chrono::milliseconds>(
367 mtx_start_time - gen_start_time)
369 <<
" ms" << std::endl;
371 std::cout <<
"mtx add using Fortran subroutine & flattened matrices: "
372 << std::chrono::duration_cast<std::chrono::milliseconds>(
373 end_time - mtx_start_time)
375 <<
" ms" << std::endl;
Mtx class offers matrix arithmetic operations. Some methods are element-wise while others make use of...
User API for OpenGPMP LINEAR ALGEBRA MODULE.
void print_matrix(const float *matrix, std::size_t rows, std::size_t cols)
void fill_matrix_random(float *matrix, std::size_t rows, std::size_t cols)