Skip to content

Commit

Permalink
CategoricalMatrix A.Tb reproducibility. (#348)
Browse files Browse the repository at this point in the history
* transpose matmul categorical bit reproducibility

* Remove reproducibility test

* Drop redundant atomic

* changelog

---------

Co-authored-by: Marc-Antoine Schmidt <[email protected]>
  • Loading branch information
adityagoel4512 and MarcAntoineSchmidtQC authored Feb 28, 2024
1 parent 0f2e648 commit 4ac3dc3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ Unreleased

- Added cython compiler directive legacy_implicit_noexcept = True to fix performance regression with cython 3.


**Other changes:**

- Refactored the pre-commit hooks to use ruff.
- Refactored CategoricalMatrix's transpose_matvec to be deterministic when using OpenMP.

3.1.13 - 2023-10-17
-------------------
Expand Down
25 changes: 15 additions & 10 deletions src/tabmat/ext/cat_split_helpers-tmpl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <vector>

#include <omp.h>

<%def name="transpose_matvec(dropfirst)">
template <typename Int, typename F>
Expand All @@ -10,24 +10,29 @@ void _transpose_matvec_${dropfirst}(
F* res,
Int res_size
) {
#pragma omp parallel
int num_threads = omp_get_max_threads();
std::vector<F> all_res(num_threads * res_size, 0.0);
#pragma omp parallel shared(all_res)
{
std::vector<F> restemp(res_size, 0.0);
#pragma omp for
int tid = omp_get_thread_num();
F* res_slice = &all_res[tid * res_size];
#pragma omp for
for (Py_ssize_t i = 0; i < n_rows; i++) {
% if dropfirst == 'all_rows_drop_first':
Py_ssize_t col_idx = indices[i] - 1;
if (col_idx != -1) {
restemp[col_idx] += other[i];
res_slice[col_idx] += other[i];
}
% else:
restemp[indices[i]] += other[i];
res_slice[indices[i]] += other[i];
% endif
}
for (Py_ssize_t i = 0; i < res_size; i++) {
# pragma omp atomic
res[i] += restemp[i];
}
#pragma omp for
for (Py_ssize_t i = 0; i < res_size; ++i) {
for (int tid = 0; tid < num_threads; ++tid) {
res[i] += all_res[tid * res_size + i];
}
}
}
}
</%def>
Expand Down

0 comments on commit 4ac3dc3

Please sign in to comment.