Skip to content

Commit

Permalink
Add appropriate matrix benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
GabTux committed Mar 22, 2024
1 parent 041f56e commit 8610d56
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 60 deletions.
12 changes: 7 additions & 5 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,16 @@ function(get_matrix_data FILE_URL FILE_NAME)
file(REMOVE_RECURSE ${CMAKE_CURRENT_BINARY_DIR}/${FILE_NAME}/)
endfunction()

get_matrix_data("http://sparse-files.engr.tamu.edu/MM/Schenk_AFE/af_shell10.tar.gz" "af_shell10")
get_matrix_data("https://suitesparse-collection-website.herokuapp.com/MM/vanHeukelum/cage15.tar.gz" "cage15")
get_matrix_data("https://suitesparse-collection-website.herokuapp.com/MM/Lee/fem_hifreq_circuit.tar.gz" "fem_hifreq_circuit")
get_matrix_data("https://suitesparse-collection-website.herokuapp.com/MM/MAWI/mawi_201512020330.tar.gz" "mawi_201512020330")
get_matrix_data("https://suitesparse-collection-website.herokuapp.com/MM/LAW/uk-2005.tar.gz" "uk-2005")
get_matrix_data("https://suitesparse-collection-website.herokuapp.com/MM/Dziekonski/dielFilterV3clx.tar.gz" "dielFilterV3clx")
get_matrix_data("https://suitesparse-collection-website.herokuapp.com/MM/Janna/Queen_4147.tar.gz" "Queen_4147")




# also possible to use CPMAddPackage, but it will not remove the archive after extraction
#CPMAddPackage("http://sparse-files.engr.tamu.edu/MM/Schenk_AFE/af_shell10.tar.gz")
#CPMAddPackage("https://suitesparse-collection-website.herokuapp.com/MM/vanHeukelum/cage15.tar.gz")
#CPMAddPackage("https://suitesparse-collection-website.herokuapp.com/MM/Lee/fem_hifreq_circuit.tar.gz")

# ---- Create binary ----
file(GLOB sources CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/source/*.cpp)
Expand Down
72 changes: 26 additions & 46 deletions benchmark/source/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,23 @@ class HeapStringVectorFixture : public RandomStringVectorFixture<Prepended, Stri
};

enum Matrices {
af_shell10,
cage15,
fem_hifreq_circuit,
mawi_201512020330,
uk_2005,
dielFilterV3clx,
Queen_4147
};

consteval static const char * get_filename(const Matrices Matrix) {
switch (Matrix) {
case mawi_201512020330: return "mawi_201512020330.mtx";
case uk_2005: return "uk-2005.mtx";
case dielFilterV3clx: return "dielFilterV3clx.mtx";
case Queen_4147: return "Queen_4147.mtx";
default: static_assert(true, "Unknown matrix");

}
}

template <typename ValueType>
struct matrix_element_t {
uint32_t row, col;
Expand All @@ -288,17 +300,13 @@ struct matrix_element_t {
}
};

using matrix_element_double = matrix_element_t<double>;
using matrix_element_complex = matrix_element_t<std::complex<double>>;

template <Matrices Matrix, bool Complex>
class SparseMatrixAoSVectorFixture : public VectorFixture<std::conditional_t<Complex, matrix_element_complex, matrix_element_double>> {
using ValueType = std::conditional_t<Complex, std::complex<double>, double>;
template <Matrices Matrix, typename Type>
class SparseMatrixAoSVectorFixture : public VectorFixture<Type> {
public:
SparseMatrixAoSVectorFixture() :
file_(get_filename()) {
file_(get_filename(Matrix)) {
if (!file_.is_open())
throw std::runtime_error(std::string("Error opening matrix file: ") +get_filename());
throw std::runtime_error(std::string("Error opening matrix file: ") +get_filename(Matrix));
read_to_memory();
}

Expand All @@ -316,41 +324,25 @@ class SparseMatrixAoSVectorFixture : public VectorFixture<std::conditional_t<Com
}

private:
consteval static const char * get_filename() {
switch (Matrix) {
case af_shell10:
return "af_shell10.mtx";
case cage15:
return "cage15.mtx";
case fem_hifreq_circuit:
return "fem_hifreq_circuit.mtx";
default:
throw std::runtime_error("Unknown matrix");
}
}

void read_to_memory() {
fast_matrix_market::read_matrix_market_triplet(file_, nrows_, ncols_, rows_, cols_, values_);
}

using ValueType = std::type_identity_t<decltype(std::declval<Type>().value)>;
std::fstream file_;
std::size_t nrows_{}, ncols_{};
std::vector<uint32_t> rows_, cols_;
std::vector<ValueType> values_{};
};

auto c_comp = [](const std::complex<double>& a, const std::complex<double>& b) {
return true;
};

template <Matrices Matrix, bool Complex>
class SparseMatrixSoAVectorFixture : public VectorFixture<std::conditional_t<Complex, std::complex<double>, double>> {
using ValueType = std::conditional_t<Complex, std::complex<double>, double>;
template <Matrices Matrix, typename Type>
class SparseMatrixSoAVectorFixture : public VectorFixture<Type> {
public:
SparseMatrixSoAVectorFixture() :
file_(get_filename()) {
file_(get_filename(Matrix)) {
if (!file_.is_open())
throw std::runtime_error(std::string("Error opening matrix file: ") +get_filename());
throw std::runtime_error(std::string("Error opening matrix file: ") +get_filename(Matrix));
read_to_memory();
}

Expand All @@ -365,24 +357,12 @@ class SparseMatrixSoAVectorFixture : public VectorFixture<std::conditional_t<Com
}

void deallocate() override {
std::vector<ValueType>().swap(this->data_);
std::vector<Type>().swap(this->data_);
std::vector<uint32_t>().swap(this->rows_);
std::vector<uint32_t>().swap(this->cols_);
}

protected:
consteval static const char * get_filename() {
switch (Matrix) {
case af_shell10:
return "af_shell10.mtx";
case cage15:
return "cage15.mtx";
case fem_hifreq_circuit:
return "fem_hifreq_circuit.mtx";
default:
throw std::runtime_error("Unknown matrix");
}
}

void read_to_memory() {
fast_matrix_market::read_matrix_market_triplet(file_, nrows_, ncols_, rows_orig_, cols_orig_, values_orig_);
Expand All @@ -391,5 +371,5 @@ class SparseMatrixSoAVectorFixture : public VectorFixture<std::conditional_t<Com
std::fstream file_;
std::size_t nrows_{}, ncols_{};
std::vector<uint32_t> rows_orig_, cols_orig_, rows_, cols_;
std::vector<ValueType> values_orig_;
std::vector<Type> values_orig_{};
};
21 changes: 12 additions & 9 deletions benchmark/source/ppqsort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,19 @@ register_string_benchmark(sort_signature, sort_name, OrganPipe, prepended, true,
register_string_benchmark(sort_signature, sort_name, Rotated, prepended, true, prepare_code) \
register_string_benchmark(sort_signature, sort_name, Heap, prepended, true, prepare_code)

#define matrix_benchmark_AoS(sort_signature, sort_name, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixAoS, af_shell10, false, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixAoS, cage15, false, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixAoS, fem_hifreq_circuit, true, prepare_code)

#define matrix_benchmark_SoA(sort_signature, sort_name, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixSoA, af_shell10, false, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixSoA, cage15, false, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixSoA, fem_hifreq_circuit, true, prepare_code)
#define matrix_benchmark_AoS(sort_signature, sort_name, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixAoS, mawi_201512020330, matrix_element_t<int>, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixAoS, uk_2005, matrix_element_t<uint8_t>, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixAoS, dielFilterV3clx, matrix_element_t<std::complex<double>>, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixAoS, Queen_4147, matrix_element_t<double>, prepare_code)


#define matrix_benchmark_SoA(sort_signature, sort_name, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixSoA, mawi_201512020330, int, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixSoA, uk_2005, uint8_t, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixSoA, dielFilterV3clx, std::complex<double>, prepare_code) \
register_matrix_benchmark(sort_signature, sort_name, SparseMatrixSoA, Queen_4147, double, prepare_code)

#define prepare_adversary(Size) \
int candidate = 0; \
Expand Down Expand Up @@ -239,7 +243,6 @@ complete_benchmark_set_aq(aqsort::sort(data_.size(), &cmp, &sw), aqsort,
auto sw = [&](std::size_t i, std::size_t j) { std::swap(data_[i], data_[j]); };
auto cmp = [&](std::size_t i, std::size_t j) { return data_[i] < data_[j]; }
);

complete_benchmark_set(mpqsort::sort(mpqsort::execution::par, data_.begin(), data_.end()), mpqsort_par, "");
complete_benchmark_set(ips4o::parallel::sort(data_.begin(), data_.end()), ips4o, "");

Expand Down

0 comments on commit 8610d56

Please sign in to comment.