Skip to content

Fix a hang in write_matrix_market_csc #76

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

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
12 changes: 7 additions & 5 deletions include/fast_matrix_market/formatters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,11 +280,13 @@ namespace fast_matrix_market {
};

chunk next_chunk(const write_options& options) {
auto num_columns = (int64_t)(((double)options.chunk_size_values / nnz_per_column) + 1);

num_columns = std::min(num_columns, (int64_t)(ptr_end - ptr_iter));
PTR_ITER ptr_chunk_end = ptr_iter + num_columns;

PTR_ITER ptr_chunk_end = ptr_end;
// we split data into chunks only if nnz_per_column is greater than 0
if (nnz_per_column > 0.) {
auto num_columns = (int64_t) (((double) options.chunk_size_values / nnz_per_column) + 1);
num_columns = std::min(num_columns, (int64_t) (ptr_end - ptr_iter));
ptr_chunk_end = ptr_iter + num_columns;
}
chunk c(line_formatter,
ptr_begin, ptr_iter, ptr_chunk_end,
ind_begin,
Expand Down
16 changes: 10 additions & 6 deletions tests/csc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@
*/
template <typename IT, typename VT>
void construct_csc(csc_matrix<IT, VT>& ret, triplet_matrix<IT, VT>& triplet, int num_elements, int ncols = 1000) {
if (num_elements < ncols) {
ncols = num_elements;
}
ret.nrows = num_elements;
ret.ncols = ncols;

Expand Down Expand Up @@ -83,8 +80,8 @@ class CSCTest : public ::testing::Test {
public:
using Mat = csc_matrix<int64_t, T>;

void load(int nnz, int chunk_size, int p) {
construct_csc(mat, triplet, nnz);
void load(int nnz, int chunk_size, int p, int ncols) {
construct_csc(mat, triplet, nnz, ncols);

roptions.chunk_size_bytes = chunk_size;
woptions.chunk_size_values = chunk_size;
Expand All @@ -108,10 +105,17 @@ TYPED_TEST(CSCTest, Generated) {
for (int nnz : {0, 10, 1000}) {
for (int chunk_size : {1, 15, 203, 1 << 10, 1 << 20}) {
for (int p : {1, 4}) {
this->load(nnz, chunk_size, p);
// test on a csc matrix with ncols = nnz
this->load(nnz, chunk_size, p, nnz);

auto b = read_mtx<ReadMat>(write_mtx(this->mat, this->woptions), this->roptions);
EXPECT_EQ(this->triplet, b);

// test on a csc matrix with a fixed number of columns = 500
this->load(nnz, chunk_size, p, 500);

b = read_mtx<ReadMat>(write_mtx(this->mat, this->woptions), this->roptions);
EXPECT_EQ(this->triplet, b);
}
}
}
Expand Down