Skip to content

Commit

Permalink
Add scoped_trace and fix omp kernel.
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikvn committed Feb 27, 2022
1 parent acd5d7c commit 089cdc0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 4 additions & 4 deletions omp/matrix/csr_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,11 @@ void calculate_nonzeros_per_row_in_index_set(
auto row_subset_begin = row_index_set.get_subsets_begin();
auto row_subset_end = row_index_set.get_subsets_end();
auto src_ptrs = source->get_const_row_ptrs();
#pragma omp parallel for
size_type res_row = 0;
for (size_type set = 0; set < num_row_subsets; ++set) {
for (size_type row = row_subset_begin[set]; row < row_subset_end[set];
++row) {
row_nnz->get_data()[row - row_subset_begin[set]] =
zero<IndexType>();
row_nnz->get_data()[res_row] = zero<IndexType>();
Array<IndexType> l_idxs(
exec,
static_cast<size_type>(src_ptrs[row + 1] - src_ptrs[row]));
Expand All @@ -776,9 +775,10 @@ void calculate_nonzeros_per_row_in_index_set(
++nnz) {
auto l_idx = l_idxs.get_const_data()[nnz];
if (l_idx != invalid_index<IndexType>()) {
row_nnz->get_data()[row - row_subset_begin[set]]++;
row_nnz->get_data()[res_row]++;
}
}
res_row++;
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions reference/test/matrix/csr_kernels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,27 +1699,31 @@ TYPED_TEST(Csr, CanGetSubmatrix2)
this->exec);
ASSERT_EQ(mat->get_num_stored_elements(), 23);
{
SCOPED_TRACE("Left top corner: Square 2x2");
auto sub_mat1 = mat->create_submatrix(gko::span(0, 2), gko::span(0, 2));
auto ref1 =
gko::initialize<Mtx>({I<T>{1.0, 3.0}, I<T>{1.0, 0.0}}, this->exec);

GKO_EXPECT_MTX_NEAR(sub_mat1.get(), ref1.get(), 0.0);
}
{
SCOPED_TRACE("Left boundary: Square 2x2");
auto sub_mat2 = mat->create_submatrix(gko::span(2, 4), gko::span(0, 2));
auto ref2 =
gko::initialize<Mtx>({I<T>{0.0, 3.0}, I<T>{0.0, -1.0}}, this->exec);

GKO_EXPECT_MTX_NEAR(sub_mat2.get(), ref2.get(), 0.0);
}
{
SCOPED_TRACE("Right boundary: Square 2x2");
auto sub_mat3 = mat->create_submatrix(gko::span(0, 2), gko::span(3, 5));
auto ref3 =
gko::initialize<Mtx>({I<T>{0.0, 2.0}, I<T>{7.5, 3.0}}, this->exec);

GKO_EXPECT_MTX_NEAR(sub_mat3.get(), ref3.get(), 0.0);
}
{
SCOPED_TRACE("Non-square 5x2");
auto sub_mat4 = mat->create_submatrix(gko::span(1, 6), gko::span(2, 4));
/*
4.5, 7.5
Expand Down Expand Up @@ -1779,6 +1783,7 @@ TYPED_TEST(Csr, CanGetSubmatrixWithIndexSet)
this->exec);
ASSERT_EQ(mat->get_num_stored_elements(), 23);
{
SCOPED_TRACE("Small square 2x2");
auto row_set = gko::IndexSet<index_type>(this->exec, {0, 1});
auto col_set = gko::IndexSet<index_type>(this->exec, {0, 1});
auto sub_mat1 = mat->create_submatrix(row_set, col_set);
Expand All @@ -1789,6 +1794,7 @@ TYPED_TEST(Csr, CanGetSubmatrixWithIndexSet)
}

{
SCOPED_TRACE("Non-square 4x2");
auto row_set = gko::IndexSet<index_type>(this->exec, {1, 2, 3, 4});
auto col_set = gko::IndexSet<index_type>(this->exec, {1, 3});
auto sub_mat1 = mat->create_submatrix(row_set, col_set);
Expand All @@ -1800,6 +1806,7 @@ TYPED_TEST(Csr, CanGetSubmatrixWithIndexSet)
}

{
SCOPED_TRACE("Square 3x3");
auto row_set = gko::IndexSet<index_type>(this->exec, {1, 3, 4});
auto col_set = gko::IndexSet<index_type>(this->exec, {1, 3, 0});
auto sub_mat1 = mat->create_submatrix(row_set, col_set);
Expand All @@ -1811,6 +1818,7 @@ TYPED_TEST(Csr, CanGetSubmatrixWithIndexSet)
}

{
SCOPED_TRACE("Square 4x4");
auto row_set = gko::IndexSet<index_type>(this->exec, {1, 4, 5, 6});
auto col_set = gko::IndexSet<index_type>(this->exec, {4, 3, 0, 1});
auto sub_mat1 = mat->create_submatrix(row_set, col_set);
Expand Down

0 comments on commit 089cdc0

Please sign in to comment.