Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

generalize cholesky_serial code #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apps/choleskey/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
project(choleskey_stdpar LANGUAGES CXX)
project(cholesky_stdpar LANGUAGES CXX)

add_executable(choleskey_serial choleskey_serial.cpp)
add_executable(cholesky_serial cholesky_serial.cpp)
target_include_directories(
choleskey_serial
cholesky_serial
PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/../../include
${ARGPARSE_INCLUDE_DIR} ${MDSPAN_INCLUDE_DIR})
target_link_libraries(choleskey_serial hpcpp-core)
target_link_libraries(cholesky_serial hpcpp-core)

add_executable(choleskey_stdpar choleskey_stdpar.cpp)
target_link_libraries(choleskey_stdpar stdexec hpcpp-core)
Expand Down
127 changes: 0 additions & 127 deletions apps/choleskey/choleskey_serial.cpp

This file was deleted.

62 changes: 33 additions & 29 deletions apps/choleskey/matrixutil.hpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
#pragma once

#include <iostream>
#include <vector>

// generate positive definition matrix
template <typename T>
using Matrix = std::vector<std::vector<T>>;

template <typename T>
std::vector<T> generate_pascal_matrix(const int n) {
Matrix<T> matrix(n, std::vector<T>(n, static_cast<T>(0)));

for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i == 0 || j == 0) {
matrix[i][j] = static_cast<T>(1);
} else {
matrix[i][j] = matrix[i][j - 1] + matrix[i - 1][j];
}
}
}

std::vector<T> flattenedVector;
for (const auto& row : matrix) {
flattenedVector.insert(flattenedVector.end(), row.begin(), row.end());
}
return std::move(flattenedVector);
}
#include "argparse/argparse.hpp"
#include "commons.hpp"

// parameters define
struct args_params_t : public argparse::Args {
bool& results = kwarg("results", "print generated results (default: false)").set_default(true);
std::uint64_t& nd = kwarg("nd", "Number of input(positive definition) matrix dimension(<=18)").set_default(10);
std::uint64_t& np = kwarg("np", "Number of partitions").set_default(4);
bool& help = flag("h, help", "print help");
bool& time = kwarg("t, time", "print time").set_default(true);
std::string& input_file = kwarg("input_file", "path to input file").set_default("");
};

// Function to read data from a text file and store it in a vector
template <typename T>
std::vector<T> readDataFromFile(const std::string& filename) {
std::vector<T> data;

// Open the file
std::ifstream file(filename);

// Check if the file is open successfully
if (!file.is_open()) {
fmt::print("Failed to open the file: {}\n", filename);
return data; // Return an empty vector in case of failure
}

std::string line;
while (std::getline(file, line)) {
// to parse each line into doubles and store them in the vector
T value;
std::istringstream iss(line);
while (iss >> value) {
data.push_back(value);
}
}

// Close the file
file.close();

return data;
}