OGS
ProcessLib::Assembly::ParallelVectorMatrixAssembler Class Reference

Detailed Description

Definition at line 13 of file ParallelVectorMatrixAssembler.h.

#include <ParallelVectorMatrixAssembler.h>

Collaboration diagram for ProcessLib::Assembly::ParallelVectorMatrixAssembler:
[legend]

Public Member Functions

 ParallelVectorMatrixAssembler (AbstractJacobianAssembler &jacobian_assembler)
void assembleWithJacobian (BaseLib::PolymorphicRandomAccessContainerView< LocalAssemblerInterface > const &local_assemblers, std::vector< std::size_t > const *const active_elements, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, const double t, double const dt, std::vector< GlobalVector * > const &xs, std::vector< GlobalVector * > const &x_prevs, int const process_id, GlobalVector &b, GlobalMatrix &Jac)
void assemble (BaseLib::PolymorphicRandomAccessContainerView< LocalAssemblerInterface > const &local_assemblers, std::vector< std::size_t > const *const active_elements, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, const double t, double const dt, std::vector< GlobalVector * > const &xs, std::vector< GlobalVector * > const &x_prevs, int const process_id, GlobalMatrix &M, GlobalMatrix &K, GlobalVector &b)

Private Attributes

AbstractJacobianAssemblerjacobian_assembler_
LocalMatrixOutput local_matrix_output_
GlobalMatrixOutput global_matrix_output_
int const num_threads_

Constructor & Destructor Documentation

◆ ParallelVectorMatrixAssembler()

ProcessLib::Assembly::ParallelVectorMatrixAssembler::ParallelVectorMatrixAssembler ( AbstractJacobianAssembler & jacobian_assembler)
explicit

Definition at line 230 of file ParallelVectorMatrixAssembler.cpp.

232 : jacobian_assembler_{jacobian_assembler},
234{
235 INFO("Threads used for ParallelVectorMatrixAssembler: {}.", num_threads_);
236}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
int getNumberOfAssemblyThreads()

References INFO(), jacobian_assembler_, and num_threads_.

Member Function Documentation

◆ assemble()

void ProcessLib::Assembly::ParallelVectorMatrixAssembler::assemble ( BaseLib::PolymorphicRandomAccessContainerView< LocalAssemblerInterface > const & local_assemblers,
std::vector< std::size_t > const *const active_elements,
std::vector< NumLib::LocalToGlobalIndexMap const * > const & dof_tables,
const double t,
double const dt,
std::vector< GlobalVector * > const & xs,
std::vector< GlobalVector * > const & x_prevs,
int const process_id,
GlobalMatrix & M,
GlobalMatrix & K,
GlobalVector & b )

Definition at line 238 of file ParallelVectorMatrixAssembler.cpp.

246{
247 // checks //////////////////////////////////////////////////////////////////
248 if (dof_tables.size() != xs.size())
249 {
250 OGS_FATAL("Different number of DOF tables and solution vectors.");
251 }
252
253 std::size_t const number_of_processes = xs.size();
254
255 // algorithm ///////////////////////////////////////////////////////////////
256
257 auto stats = CumulativeStats<MultiStats<2>>::create(num_threads_);
258
259 ThreadException exception;
260#pragma omp parallel num_threads(num_threads_)
261 {
262#ifdef _OPENMP
263#pragma omp single nowait
264 {
265 INFO("Number of threads: {}", omp_get_num_threads());
266 }
267#endif
268
269 // temporary data only stored here in order to avoid frequent memory
270 // reallocations.
271 std::vector<double> local_M_data;
272 std::vector<double> local_K_data;
273 std::vector<double> local_b_data;
274
275 // copy to avoid concurrent access
276 auto const jac_asm = jacobian_assembler_.copy();
277
278 auto stats_this_thread = stats->clone();
279 MultiMatrixElementCache<2> cache{M, K, b, stats_this_thread->data,
281
282 auto local_matrix_output = [&](std::ptrdiff_t element_id)
283 {
284 local_matrix_output_(t, process_id, element_id, local_M_data,
285 local_K_data, local_b_data);
286 };
287
288 // Monolithic scheme
289 if (number_of_processes == 1)
290 {
291 assert(process_id == 0);
292 auto const& dof_table = *dof_tables[0];
293 auto const& x = *xs[0];
294 auto const& x_prev = *x_prevs[0];
295
296 runAssembly(local_assemblers, active_elements, exception,
297 local_matrix_output,
298 [&](auto element_id, auto& loc_asm)
299 {
300 assembleOneElement(element_id, loc_asm, dof_table,
301 t, dt, x, x_prev, local_M_data,
302 local_K_data, local_b_data,
303 cache);
304 });
305 }
306 else // Staggered scheme
307 {
308 runAssembly(local_assemblers, active_elements, exception,
309 local_matrix_output,
310 [&](auto element_id, auto& loc_asm)
311 {
313 element_id, loc_asm, dof_tables, t, dt, xs,
314 x_prevs, process_id, local_M_data, local_K_data,
315 local_b_data, cache);
316 });
317 }
318 }
319
320 global_matrix_output_(t, process_id, M, K, b);
321 exception.rethrow();
322}
#define OGS_FATAL(...)
Definition Error.h:19
void assembleOneElement(const std::size_t mesh_item_id, ProcessLib::LocalAssemblerInterface &local_assembler, const NumLib::LocalToGlobalIndexMap &dof_table, const double t, const double dt, const GlobalVector &x, const GlobalVector &x_prev, std::vector< double > &local_M_data, std::vector< double > &local_K_data, std::vector< double > &local_b_data, ProcessLib::Assembly::MultiMatrixElementCache< 2 > &cache)
void runAssembly(BaseLib::PolymorphicRandomAccessContainerView< ProcessLib::LocalAssemblerInterface > const &local_assemblers, std::vector< std::size_t > const *const active_elements, ThreadException &exception, auto local_matrix_output, auto assemble)
void assembleForStaggeredSchemeOneElement(const std::size_t mesh_item_id, ProcessLib::LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, const double t, const double dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, std::vector< double > &local_M_data, std::vector< double > &local_K_data, std::vector< double > &local_b_data, ProcessLib::Assembly::MultiMatrixElementCache< 2 > &cache)

References global_matrix_output_, INFO(), jacobian_assembler_, local_matrix_output_, num_threads_, OGS_FATAL, and ThreadException::rethrow().

◆ assembleWithJacobian()

void ProcessLib::Assembly::ParallelVectorMatrixAssembler::assembleWithJacobian ( BaseLib::PolymorphicRandomAccessContainerView< LocalAssemblerInterface > const & local_assemblers,
std::vector< std::size_t > const *const active_elements,
std::vector< NumLib::LocalToGlobalIndexMap const * > const & dof_tables,
const double t,
double const dt,
std::vector< GlobalVector * > const & xs,
std::vector< GlobalVector * > const & x_prevs,
int const process_id,
GlobalVector & b,
GlobalMatrix & Jac )

Definition at line 324 of file ParallelVectorMatrixAssembler.cpp.

332{
333 // checks //////////////////////////////////////////////////////////////////
334 if (dof_tables.size() != xs.size())
335 {
336 OGS_FATAL("Different number of DOF tables and solution vectors.");
337 }
338
339 std::size_t const number_of_processes = xs.size();
340 // algorithm ///////////////////////////////////////////////////////////////
341
342 auto stats = CumulativeStats<MultiStats<1>>::create(num_threads_);
343
344 ThreadException exception;
345#pragma omp parallel num_threads(num_threads_)
346 {
347#ifdef _OPENMP
348#pragma omp single nowait
349 {
350 INFO("Number of threads: {}", omp_get_num_threads());
351 }
352#endif
353
354 // temporary data only stored here in order to avoid frequent memory
355 // reallocations.
356 std::vector<double> local_b_data;
357 std::vector<double> local_Jac_data;
358
359 // copy to avoid concurrent access
360 auto const jac_asm = jacobian_assembler_.copy();
361 auto stats_this_thread = stats->clone();
362
363 MultiMatrixElementCache<1> cache{b, Jac, stats_this_thread->data,
365
366 auto local_matrix_output = [&](std::ptrdiff_t element_id)
367 {
368 local_matrix_output_(t, process_id, element_id, local_b_data,
369 local_Jac_data);
370 };
371
372 // Monolithic scheme
373 if (number_of_processes == 1)
374 {
375 assert(process_id == 0);
376 auto const& dof_table = *dof_tables[0];
377 auto const& x = *xs[0];
378 auto const& x_prev = *x_prevs[0];
379
381 local_assemblers, active_elements, exception,
382 local_matrix_output,
383 [&](auto element_id, auto& loc_asm)
384 {
386 element_id, loc_asm, dof_table, t, dt, x, x_prev,
387 local_b_data, local_Jac_data, *jac_asm, cache);
388 });
389 }
390 else // Staggered scheme
391 {
393 local_assemblers, active_elements, exception,
394 local_matrix_output,
395 [&](auto element_id, auto& loc_asm)
396 {
398 element_id, loc_asm, dof_tables, t, dt, xs, x_prevs,
399 process_id, local_b_data, local_Jac_data, *jac_asm,
400 cache);
401 });
402 }
403 }
404
405 stats->print();
406
407 global_matrix_output_(t, process_id, b, Jac);
408 exception.rethrow();
409}
void assembleWithJacobianForStaggeredSchemeOneElement(const std::size_t mesh_item_id, ProcessLib::LocalAssemblerInterface &local_assembler, std::vector< NumLib::LocalToGlobalIndexMap const * > const &dof_tables, const double t, const double dt, std::vector< GlobalVector * > const &x, std::vector< GlobalVector * > const &x_prev, int const process_id, std::vector< double > &local_b_data, std::vector< double > &local_Jac_data, ProcessLib::AbstractJacobianAssembler &jacobian_assembler, ProcessLib::Assembly::MultiMatrixElementCache< 1 > &cache)
void assembleWithJacobianOneElement(const std::size_t mesh_item_id, ProcessLib::LocalAssemblerInterface &local_assembler, const NumLib::LocalToGlobalIndexMap &dof_table, const double t, const double dt, const GlobalVector &x, const GlobalVector &x_prev, std::vector< double > &local_b_data, std::vector< double > &local_Jac_data, ProcessLib::AbstractJacobianAssembler &jacobian_assembler, ProcessLib::Assembly::MultiMatrixElementCache< 1 > &cache)

References global_matrix_output_, INFO(), jacobian_assembler_, local_matrix_output_, num_threads_, OGS_FATAL, and ThreadException::rethrow().

Member Data Documentation

◆ global_matrix_output_

GlobalMatrixOutput ProcessLib::Assembly::ParallelVectorMatrixAssembler::global_matrix_output_
private

Definition at line 40 of file ParallelVectorMatrixAssembler.h.

Referenced by assemble(), and assembleWithJacobian().

◆ jacobian_assembler_

AbstractJacobianAssembler& ProcessLib::Assembly::ParallelVectorMatrixAssembler::jacobian_assembler_
private

◆ local_matrix_output_

LocalMatrixOutput ProcessLib::Assembly::ParallelVectorMatrixAssembler::local_matrix_output_
private

Definition at line 39 of file ParallelVectorMatrixAssembler.h.

Referenced by assemble(), and assembleWithJacobian().

◆ num_threads_

int const ProcessLib::Assembly::ParallelVectorMatrixAssembler::num_threads_
private

The documentation for this class was generated from the following files: