Skip to content

Commit

Permalink
Stripped out the OpenMP SIMD macros as they're not worth the effort.
Browse files Browse the repository at this point in the history
In dense scenarios, the compiler already autovectorizes properly (based on some
godbolt testing), so the SIMD pragmas have no effect.

Admittedly, they are useful for forcing vectorization in sparse cases, as the
compiler can't prove that the indices don't alias. But in those cases, the
execution time is likely dominated by memory lookups when the indices don't
refer to the same cache line... which they won't, in typical sparse data.

In light of this, we remove these macros to reduce the risk of incorrectness
and the amount of testing we have to do. We don't even OpenMP tests anyway.
  • Loading branch information
LTLA committed Sep 2, 2024
1 parent 31dfd14 commit 676a333
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 39 deletions.
15 changes: 0 additions & 15 deletions include/tatami_mult/dense_column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ void dense_column_vector(const tatami::Matrix<Value_, Index_>& matrix, const Rig
for (Index_ c = 0; c < NC; ++c) {
auto ptr = ext->fetch(buffer.data());
Output_ mult = rhs[c];
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ r = 0; r < length; ++r) {
optr[r] += mult * ptr[r];
}
Expand All @@ -54,9 +51,6 @@ void dense_column_vectors(const tatami::Matrix<Value_, Index_>& matrix, const st
for (size_t j = 0; j < num_rhs; ++j) {
auto optr = stores[j].data();
Output_ mult = rhs[j][c];
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ r = 0; r < length; ++r) {
optr[r] += mult * ptr[r];
}
Expand Down Expand Up @@ -92,9 +86,6 @@ void dense_column_tatami_dense(const tatami::Matrix<Value_, Index_>& matrix, con
for (RightIndex_ j = 0; j < rhs_col; ++j) {
auto optr = stores[j].data();
Output_ mult = rptr[j];
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ r = 0; r < length; ++r) {
optr[r] += mult * ptr[r];
}
Expand Down Expand Up @@ -145,9 +136,6 @@ void dense_column_tatami_sparse(const tatami::Matrix<Value_, Index_>& matrix, co
auto optr = stores[j].data();
if (k < range.number && j == range.index[k]) {
Output_ mult = range.value[k];
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ r = 0; r < length; ++r) {
optr[r] += mult * ptr[r];
}
Expand All @@ -165,9 +153,6 @@ void dense_column_tatami_sparse(const tatami::Matrix<Value_, Index_>& matrix, co
for (RightIndex_ k = 0; k < range.number; ++k) {
auto optr = stores[range.index[k]].data();
Output_ mult = range.value[k];
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ r = 0; r < length; ++r) {
optr[r] += mult * ptr[r];
}
Expand Down
24 changes: 0 additions & 24 deletions include/tatami_mult/sparse_column.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,20 @@ namespace internal {

template<typename Value_, typename Index_, typename Output_>
void sparse_multiply_add(const tatami::SparseRange<Value_, Index_>& range, Index_ start, Output_ mult, Output_* optr) {
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ r = 0; r < range.number; ++r) {
optr[range.index[r] - start] += mult * range.value[r];
}
}

template<typename Value_, typename Index_>
void expand_sparse_range(const tatami::SparseRange<Value_, Index_>& range, Index_ start, std::vector<Value_>& expanded) {
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ k = 0; k < range.number; ++k) {
expanded[range.index[k] - start] = range.value[k];
}
}

template<typename Value_, typename Index_>
void reset_expanded_sparse_range(const tatami::SparseRange<Value_, Index_>& range, Index_ start, std::vector<Value_>& expanded) {
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ k = 0; k < range.number; ++k) {
expanded[range.index[k] - start] = 0;
}
Expand Down Expand Up @@ -68,9 +59,6 @@ void sparse_column_vector(const tatami::Matrix<Value_, Index_>& matrix, const Ri
expanded.resize(length);
expand_sparse_range(range, start, expanded);

#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ r = 0; r < length; ++r) {
optr[r] += expanded[r] * mult;
}
Expand Down Expand Up @@ -119,9 +107,6 @@ void sparse_column_vectors(const tatami::Matrix<Value_, Index_>& matrix, const s
has_expanded = true;
}

#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ r = 0; r < length; ++r) {
optr[r] += expanded[r] * mult;
}
Expand Down Expand Up @@ -183,9 +168,6 @@ void sparse_column_tatami_dense(const tatami::Matrix<Value_, Index_>& matrix, co
has_expanded = true;
}

#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ r = 0; r < length; ++r) {
optr[r] += expanded[r] * mult;
}
Expand Down Expand Up @@ -257,9 +239,6 @@ void sparse_column_tatami_sparse(const tatami::Matrix<Value_, Index_>& matrix, c
auto optr = stores[j].data();
if (rhs_k < rhs_range.number && j == rhs_range.index[rhs_k]) {
Output_ mult = rhs_range.value[rhs_k];
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ k = 0; k < range.number; ++k) {
optr[range.index[k] - start] += mult * range.value[k];
}
Expand All @@ -277,9 +256,6 @@ void sparse_column_tatami_sparse(const tatami::Matrix<Value_, Index_>& matrix, c
for (RightIndex_ rhs_k = 0; rhs_k < rhs_range.number; ++rhs_k) {
auto optr = stores[rhs_range.index[rhs_k]].data();
Output_ mult = rhs_range.value[rhs_k];
#ifdef _OPENMP
#pragma omp simd
#endif
for (Index_ k = 0; k < range.number; ++k) {
optr[range.index[k] - start] += mult * range.value[k];
}
Expand Down

0 comments on commit 676a333

Please sign in to comment.