From 86f3b6c694a5269ce3b0aafce71380a74723ebf5 Mon Sep 17 00:00:00 2001 From: Dmitri Naumov Date: Tue, 13 Aug 2024 16:18:52 +0200 Subject: [PATCH] [PL] Extract runAssembly function --- .../ParallelVectorMatrixAssembler.cpp | 84 +++++-------------- 1 file changed, 22 insertions(+), 62 deletions(-) diff --git a/ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp b/ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp index c649e5ce3e6..a78a8e7aa6c 100644 --- a/ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp +++ b/ProcessLib/Assembly/ParallelVectorMatrixAssembler.cpp @@ -134,66 +134,18 @@ collectActiveLocalAssemblers( return create_ids_asm_pairs(active_elements); } -void runAssemblyForEachLocalAssembler( +void runAssembly( std::vector>> const& ids_local_assemblers, - NumLib::LocalToGlobalIndexMap const& dof_table, double const t, - double const dt, GlobalVector const& x, GlobalVector const& x_prev, - std::vector& local_b_data, std::vector& local_Jac_data, - ProcessLib::AbstractJacobianAssembler& jac_asm, ThreadException& exception, - ProcessLib::Assembly::MultiMatrixElementCache& cache, - auto local_matrix_output) + ThreadException& exception, + auto local_matrix_output, + auto assemble) { - // due to MSVC++ error: - // error C3016: 'element_id': index variable in OpenMP 'for' - // statement must have signed integral type std::ptrdiff_t n_elements = static_cast(ids_local_assemblers.size()); -#pragma omp for nowait - for (std::ptrdiff_t i = 0; i < n_elements; ++i) - { - if (exception) - { - continue; - } - auto [element_id, loc_asm] = ids_local_assemblers[i]; - - try - { - assembleWithJacobianOneElement(element_id, loc_asm, dof_table, t, - dt, x, x_prev, local_b_data, - local_Jac_data, jac_asm, cache); - } - catch (...) - { - exception.capture(); - continue; - } - - local_matrix_output(element_id); - } -} -void runStaggeredAssemblyForEachLocalAssembler( - std::vector>> const& - ids_local_assemblers, - std::vector const& dof_tables, - double const t, double const dt, std::vector const& x, - std::vector const& x_prev, int const process_id, - std::vector& local_b_data, std::vector& local_Jac_data, - ProcessLib::AbstractJacobianAssembler& jac_asm, ThreadException& exception, - ProcessLib::Assembly::MultiMatrixElementCache& cache, - auto local_matrix_output) -{ - // due to MSVC++ error: - // error C3016: 'element_id': index variable in OpenMP 'for' - // statement must have signed integral type - std::ptrdiff_t n_elements = - static_cast(ids_local_assemblers.size()); #pragma omp for nowait for (std::ptrdiff_t i = 0; i < n_elements; ++i) { @@ -205,9 +157,7 @@ void runStaggeredAssemblyForEachLocalAssembler( try { - assembleWithJacobianForStaggeredSchemeOneElement( - element_id, loc_asm, dof_tables, t, dt, x, x_prev, process_id, - local_b_data, local_Jac_data, jac_asm, cache); + assemble(element_id, loc_asm); } catch (...) { @@ -335,18 +285,28 @@ void ParallelVectorMatrixAssembler::assembleWithJacobian( auto const& x = *xs[0]; auto const& x_prev = *x_prevs[0]; - runAssemblyForEachLocalAssembler( + runAssembly( collectActiveLocalAssemblers(local_assemblers, active_elements), - dof_table, t, dt, x, x_prev, local_b_data, local_Jac_data, - *jac_asm, exception, cache, local_matrix_output); + exception, local_matrix_output, + [&](auto element_id, auto& loc_asm) + { + assembleWithJacobianOneElement( + element_id, loc_asm, dof_table, t, dt, x, x_prev, + local_b_data, local_Jac_data, *jac_asm, cache); + }); } else // Staggered scheme { - runStaggeredAssemblyForEachLocalAssembler( + runAssembly( collectActiveLocalAssemblers(local_assemblers, active_elements), - dof_tables, t, dt, xs, x_prevs, process_id, local_b_data, - local_Jac_data, *jac_asm, exception, cache, - local_matrix_output); + exception, local_matrix_output, + [&](auto element_id, auto& loc_asm) + { + assembleWithJacobianForStaggeredSchemeOneElement( + element_id, loc_asm, dof_tables, t, dt, xs, x_prevs, + process_id, local_b_data, local_Jac_data, *jac_asm, + cache); + }); } }