From 8a1522b4c1939a0e0b2f35e7ca1ecda0e7aa4350 Mon Sep 17 00:00:00 2001 From: superwhiskers Date: Mon, 17 Jun 2024 11:56:18 -0400 Subject: [PATCH] actually undo formatting changes in Coo.cpp --- resolve/matrix/Coo.cpp | 107 ++++++++--------------------------------- 1 file changed, 19 insertions(+), 88 deletions(-) diff --git a/resolve/matrix/Coo.cpp b/resolve/matrix/Coo.cpp index e0fd29a78..a0ea657c8 100644 --- a/resolve/matrix/Coo.cpp +++ b/resolve/matrix/Coo.cpp @@ -1,13 +1,12 @@ #include // <-- includes memcpy #include -#include -#include +#include #include #include "Coo.hpp" -namespace ReSolve +namespace ReSolve { using out = io::Logger; @@ -18,15 +17,15 @@ namespace ReSolve matrix::Coo::Coo(index_type n, index_type m, index_type nnz) : Sparse(n, m, nnz) { } - - matrix::Coo::Coo(index_type n, - index_type m, + + matrix::Coo::Coo(index_type n, + index_type m, index_type nnz, bool symmetric, bool expanded) : Sparse(n, m, nnz, symmetric, expanded) { } - + matrix::Coo::~Coo() { } @@ -91,7 +90,7 @@ namespace ReSolve if (((memspaceIn == memory::DEVICE)) && ((memspaceOut == memory::DEVICE))){ control = 3;} if (memspaceOut == memory::HOST) { - //check if cpu data allocated + //check if cpu data allocated if ((h_row_data_ == nullptr) != (h_col_data_ == nullptr)) { out::error() << "In Coo::updateData one of host row or column data is null!\n"; } @@ -151,7 +150,7 @@ namespace ReSolve return -1; } return 0; - } + } int matrix::Coo::updateData(index_type* row_data, index_type* col_data, real_type* val_data, index_type new_nnz, memory::MemorySpace memspaceIn, memory::MemorySpace memspaceOut) { @@ -159,7 +158,7 @@ namespace ReSolve this->nnz_ = new_nnz; int i = this->updateData(row_data, col_data, val_data, memspaceIn, memspaceOut); return i; - } + } int matrix::Coo::allocateMatrixData(memory::MemorySpace memspace) { @@ -169,20 +168,20 @@ namespace ReSolve if (memspace == memory::HOST) { this->h_row_data_ = new index_type[nnz_current]; - std::fill(h_row_data_, h_row_data_ + nnz_current, 0); + std::fill(h_row_data_, h_row_data_ + nnz_current, 0); this->h_col_data_ = new index_type[nnz_current]; - std::fill(h_col_data_, h_col_data_ + nnz_current, 0); + std::fill(h_col_data_, h_col_data_ + nnz_current, 0); this->h_val_data_ = new real_type[nnz_current]; - std::fill(h_val_data_, h_val_data_ + nnz_current, 0.0); + std::fill(h_val_data_, h_val_data_ + nnz_current, 0.0); owns_cpu_data_ = true; owns_cpu_vals_ = true; return 0; } if (memspace == memory::DEVICE) { - mem_.allocateArrayOnDevice(&d_row_data_, nnz_current); - mem_.allocateArrayOnDevice(&d_col_data_, nnz_current); - mem_.allocateArrayOnDevice(&d_val_data_, nnz_current); + mem_.allocateArrayOnDevice(&d_row_data_, nnz_current); + mem_.allocateArrayOnDevice(&d_col_data_, nnz_current); + mem_.allocateArrayOnDevice(&d_val_data_, nnz_current); owns_gpu_data_ = true; owns_gpu_vals_ = true; return 0; @@ -206,12 +205,12 @@ namespace ReSolve out::error() << "In Coo::copyData one of host row or column data is null!\n"; } if ((h_row_data_ == nullptr) && (h_col_data_ == nullptr)) { - h_row_data_ = new index_type[nnz_current]; - h_col_data_ = new index_type[nnz_current]; + h_row_data_ = new index_type[nnz_current]; + h_col_data_ = new index_type[nnz_current]; owns_cpu_data_ = true; } if (h_val_data_ == nullptr) { - h_val_data_ = new real_type[nnz_current]; + h_val_data_ = new real_type[nnz_current]; owns_cpu_vals_ = true; } mem_.copyArrayDeviceToHost(h_row_data_, d_row_data_, nnz_current); @@ -247,7 +246,7 @@ namespace ReSolve /** * @brief Prints matrix data. - * + * * @param out - Output stream where the matrix data is printed */ void matrix::Coo::print(std::ostream& out) @@ -259,72 +258,4 @@ namespace ReSolve << h_val_data_[i] << "\n"; } } - - int matrix::Coo::expand() - { - if (is_symmetric_ && !is_expanded_) { - index_type* rows = getRowData(memory::HOST); - index_type* columns = getColData(memory::HOST); - real_type* values = getValues(memory::HOST); - - if (rows == nullptr || columns == nullptr || values == nullptr) { - return 0; - } - - // NOTE: this is predicated on the same define as that which disables - // assert(3), to avoid record-keeping where it is not necessary -#ifndef NDEBUG - index_type n_diagonal = 0; -#endif - - // NOTE: so because most of the code here uses new/delete and there's no - // realloc(3) equivalent for that memory management scheme, we - // have to manually new/memcpy/delete, unfortunately - index_type* new_rows = new index_type[nnz_expanded_]; - index_type* new_columns = new index_type[nnz_expanded_]; - real_type* new_values = new real_type[nnz_expanded_]; - - index_type j = 0; - for (index_type i = 0; i < nnz_; i++) { - new_rows[j] = rows[i]; - new_columns[j] = columns[i]; - new_values[j] = values[i]; - - j++; - -#ifndef NDEBUG - if (rows[i] == columns[i]) { - n_diagonal++; - } else { -#else - if (rows[i] != columns[i]) { -#endif - new_rows[j] = columns[i]; - new_columns[j] = rows[i]; - new_values[j] = values[i]; - - j++; - } - } - - // NOTE: the effectiveness of this is probably questionable given that - // it occurs after we've already risked writing out-of-bounds, but - // i guess if that worked or we've over-allocated, this will catch - // something (in debug builds/release builds with asserts enabled) - assert(nnz_expanded_ == ((2 * nnz_) - n_diagonal)); - - if (destroyMatrixData(memory::HOST) != 0 || - setMatrixData(new_rows, new_columns, new_values, memory::HOST) != 0) { - // TODO: make fallible - assert(false && "invalid state after coo matrix expansion"); - return -1; - } - - setNnz(nnz_expanded_); - setExpanded(true); - owns_cpu_data_ = owns_cpu_vals_ = true; - } - - return 0; - } } // namespace ReSolve