From 6524a345d85998029946df1bff9464ebad241536 Mon Sep 17 00:00:00 2001 From: Vicente Mataix Ferrandiz Date: Tue, 12 Mar 2024 16:22:43 +0100 Subject: [PATCH] Revert "More replacement" This reverts commit 4ea0d8cb11caaf27d05683bf5be2ea8b36a3a9d4. --- .../sparse_matrix_multiplication_utility.h | 38 +++++++++---------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/kratos/utilities/sparse_matrix_multiplication_utility.h b/kratos/utilities/sparse_matrix_multiplication_utility.h index 46ad126ffb42..5034134816a9 100644 --- a/kratos/utilities/sparse_matrix_multiplication_utility.h +++ b/kratos/utilities/sparse_matrix_multiplication_utility.h @@ -272,11 +272,11 @@ class SparseMatrixMultiplicationUtility const double* values_b = B.value_data().begin(); // Definition of TLS - struct TLS_max { + struct TLS { IndexType my_max = 0; }; - const IndexType max_row_width = IndexPartition(nrows).for_each>(TLS_max(), [&](IndexType i, TLS_max& rTLS) { + const IndexType max_row_width = IndexPartition(nrows).for_each>(TLS(), [&](IndexType i, TLS& rTLS) { const IndexType row_beg = index1_a[i]; const IndexType row_end = index1_a[i+1]; @@ -307,27 +307,25 @@ class SparseMatrixMultiplicationUtility IndexType* c_ptr = new IndexType[nrows + 1]; c_ptr[0] = 0; - // Definition of TLS - struct TLS_col { - TLS_col(std::vector>& rTmpCol) - { - #ifdef _OPENMP - const int tid = omp_get_thread_num(); - #else - const int tid = 0; - #endif - t_col = &rTmpCol[tid][0]; - } - IndexType* t_col; - }; + // TODO: Replace with block_for_each + #pragma omp parallel + { + #ifdef _OPENMP + const int tid = omp_get_thread_num(); + #else + const int tid = 0; + #endif - IndexPartition(nrows).for_each(TLS_col(tmp_col), [&](IndexType i, TLS_col& rTLS) { + IndexType* t_col = &tmp_col[tid][0]; - const IndexType row_beg = index1_a[i]; - const IndexType row_end = index1_a[i+1]; + #pragma omp for + for(int i = 0; i < static_cast(nrows); ++i) { + const IndexType row_beg = index1_a[i]; + const IndexType row_end = index1_a[i+1]; - c_ptr[i+1] = ProdRowWidth( index2_a + row_beg, index2_a + row_end, index1_b, index2_b, rTLS.t_col, rTLS.t_col + max_row_width, rTLS.t_col + 2 * max_row_width ); - }); + c_ptr[i+1] = ProdRowWidth( index2_a + row_beg, index2_a + row_end, index1_b, index2_b, t_col, t_col + max_row_width, t_col + 2 * max_row_width ); + } + } // We initialize the sparse matrix std::partial_sum(c_ptr, c_ptr + nrows + 1, c_ptr);