Skip to content

Commit

Permalink
#EDITS: updates to linalg module and file seperation
Browse files Browse the repository at this point in the history
  • Loading branch information
akielaries committed Feb 18, 2024
1 parent e3e3af5 commit eb62e0e
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ if(LCOV)
COMMAND ${CMAKE_COMMAND} -E cmake_echo_color --cyan --bold "[Generating Coverage Reports]"
COMMAND lcov --directory .. --capture --output-file lcov.info --rc geninfo_unexecuted_blocks=1 #--ignore-errors mismatch,mismatch
COMMAND lcov --remove lcov.info "*c++*" "*11*" "*/googletest/*" "*/gtest*" "/usr/*" "/src" "/build" -o lcov.info --ignore-errors unused
#COMMAND mv lcov.info ../../.coverage
COMMAND mv lcov.info ../../.coverage
)
endif()
else()
Expand Down
74 changes: 74 additions & 0 deletions tests/linalg/t_matrix_arr_f90.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*************************************************************************
* Testing Mtx class operations
************************************************************************/
#include "../../include/linalg/mtx.hpp"
#include "../../include/linalg/mtx_tmpl.hpp"
#include "t_matrix.hpp"
#include <chrono>
#include <cmath>
#include <cstdint>
#include <gtest/gtest.h>
#include <iostream>
#include <limits.h>
#include <string>
#include <vector>

using namespace gpmp;
#define TEST_COUT std::cerr << "\033[32m[ ] [ INFO ] \033[0m"

namespace {

TEST(MatrixArrayTestI32, AdditionPerformanceComparisonF90) {
int mtx_size = 1024;
TEST_COUT << "Matrix size : " << mtx_size << std::endl;
// define input matrices A and B
int *A = new int[mtx_size * mtx_size];
int *B = new int[mtx_size * mtx_size];
int *expected = new int[mtx_size * mtx_size];
int *result = new int[mtx_size * mtx_size];

// initialize random number generator
std::random_device rd;
std::mt19937 gen(rd());
std::uniform_int_distribution<int> distribution(1, 100);

// populate matrices A and B with random values
for (int i = 0; i < mtx_size; ++i) {
for (int j = 0; j < mtx_size; ++j) {
A[i * mtx_size + j] = distribution(gen);
B[i * mtx_size + j] = distribution(gen);
}
}

gpmp::linalg::Mtx mtx;
auto start_std = std::chrono::high_resolution_clock::now();

// expected result using the naive implementation
mtx.std_mtx_add(A, B, expected, mtx_size, mtx_size);

auto end_std = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed_seconds_std = end_std - start_std;

auto start_intrin = std::chrono::high_resolution_clock::now();

// result using the intrinsics implementation
mtx.mtx_add_f90(A, B, result, mtx_size, mtx_size);
auto end_intrin = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> elapsed_seconds_intrin =
end_intrin - start_intrin;

TEST_COUT << "INTRINSIC Matrix Addition Time : "
<< elapsed_seconds_intrin.count() << " seconds" << std::endl;
TEST_COUT << "STANDARD Matrix Addition Time : "
<< elapsed_seconds_std.count() << " seconds" << std::endl;

// compare the results
ASSERT_TRUE(mtx_verif(expected, result, mtx_size, mtx_size));
delete[] A;
delete[] B;
delete[] expected;
delete[] result;
}


}

0 comments on commit eb62e0e

Please sign in to comment.