OGS
ProcessLib::Assembly::ParallelVectorMatrixAssembler Class Reference

Detailed Description

Definition at line 20 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 &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, GlobalMatrix &Jac)
 

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

Member Function Documentation

◆ assembleWithJacobian()

void ProcessLib::Assembly::ParallelVectorMatrixAssembler::assembleWithJacobian ( BaseLib::PolymorphicRandomAccessContainerView< LocalAssemblerInterface > const & local_assemblers,
std::vector< std::size_t > 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,
GlobalMatrix & Jac )

Definition at line 117 of file ParallelVectorMatrixAssembler.cpp.

125{
126 // checks //////////////////////////////////////////////////////////////////
127 if (process_id != 0)
128 {
129 OGS_FATAL("Process id is not 0 but {}", process_id);
130 }
131
132 if (dof_tables.size() != 1)
133 {
134 OGS_FATAL("More than 1 dof table");
135 }
136 auto const& dof_table = *(dof_tables.front());
137
138 if (xs.size() != 1)
139 {
140 OGS_FATAL("More than 1 solution vector");
141 }
142 auto const& x = *xs.front();
143
144 if (x_prevs.size() != 1)
145 {
146 OGS_FATAL("More than 1 x_prev vector");
147 }
148 auto const& x_prev = *x_prevs.front();
149
150 // algorithm ///////////////////////////////////////////////////////////////
151
153 ConcurrentMatrixView M_view(M);
154 ConcurrentMatrixView K_view(K);
155 ConcurrentMatrixView b_view(b);
156 ConcurrentMatrixView Jac_view(Jac);
157
158 ThreadException exception;
159 bool assembly_error = false;
160#pragma omp parallel num_threads(num_threads_)
161 {
162#ifdef _OPENMP
163#pragma omp single nowait
164 {
165 INFO("Number of threads: {}", omp_get_num_threads());
166 }
167#endif
168
169 // temporary data only stored here in order to avoid frequent memory
170 // reallocations.
171 std::vector<double> local_M_data;
172 std::vector<double> local_K_data;
173 std::vector<double> local_b_data;
174 std::vector<double> local_Jac_data;
175 std::vector<GlobalIndexType> indices;
176
177 // copy to avoid concurrent access
178 auto const jac_asm = jacobian_assembler_.copy();
179 auto stats_this_thread = stats->clone();
180
181 MultiMatrixElementCache cache{M_view, K_view, b_view, Jac_view,
182 stats_this_thread->data};
183
184 // TODO corner case: what if all elements on a submesh are deactivated?
185 if (active_elements.empty())
186 {
187 // due to MSVC++ error:
188 // error C3016: 'element_id': index variable in OpenMP 'for'
189 // statement must have signed integral type
190 std::ptrdiff_t const n_loc_asm =
191 static_cast<std::ptrdiff_t>(local_assemblers.size());
192
193#pragma omp for nowait
194 for (std::ptrdiff_t element_id = 0; element_id < n_loc_asm;
195 ++element_id)
196 {
197 if (assembly_error)
198 {
199 continue;
200 }
201 auto& loc_asm = local_assemblers[element_id];
202
203 try
204 {
206 element_id, loc_asm, dof_table, t, dt, x, x_prev,
207 local_M_data, local_K_data, local_b_data,
208 local_Jac_data, indices, *jac_asm, cache);
209 }
210 catch (...)
211 {
212 exception.capture();
213 assembly_error = true;
214 continue;
215 }
216
217 local_matrix_output_(t, process_id, element_id, local_M_data,
218 local_K_data, local_b_data,
219 &local_Jac_data);
220 }
221 }
222 else
223 {
224 // due to MSVC++ error:
225 // error C3016: 'i': index variable in OpenMP 'for' statement must
226 // have signed integral type
227 std::ptrdiff_t const n_act_elem =
228 static_cast<std::ptrdiff_t>(active_elements.size());
229
230#pragma omp for nowait
231 for (std::ptrdiff_t i = 0; i < n_act_elem; ++i)
232 {
233 if (assembly_error)
234 {
235 continue;
236 }
237
238 auto const element_id = active_elements[i];
239 auto& loc_asm = local_assemblers[element_id];
240
241 try
242 {
244 element_id, loc_asm, dof_table, t, dt, x, x_prev,
245 local_M_data, local_K_data, local_b_data,
246 local_Jac_data, indices, *jac_asm, cache);
247 }
248 catch (...)
249 {
250 exception.capture();
251 assembly_error = true;
252 continue;
253 }
254
255 local_matrix_output_(t, process_id, element_id, local_M_data,
256 local_K_data, local_b_data,
257 &local_Jac_data);
258 }
259 }
260 } // OpenMP parallel section
261
262 stats->print();
263
264 global_matrix_output_(t, process_id, M, K, b, &Jac);
265 exception.rethrow();
266}
#define OGS_FATAL(...)
Definition Error.h:26
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
virtual std::unique_ptr< AbstractJacobianAssembler > copy() const =0
static std::shared_ptr< CumulativeStats< Data > > create()
ConcurrentMatrixView(GlobalVector &) -> ConcurrentMatrixView< 1 >
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_M_data, std::vector< double > &local_K_data, std::vector< double > &local_b_data, std::vector< double > &local_Jac_data, std::vector< GlobalIndexType > &indices, ProcessLib::AbstractJacobianAssembler &jacobian_assembler, ProcessLib::Assembly::MultiMatrixElementCache &cache)

References ThreadException::capture(), ProcessLib::AbstractJacobianAssembler::copy(), ProcessLib::Assembly::CumulativeStats< Data >::create(), global_matrix_output_, INFO(), jacobian_assembler_, local_matrix_output_, OGS_FATAL, and ThreadException::rethrow().

Referenced by ProcessLib::AssemblyMixin< Process >::assembleWithJacobian(), and ProcessLib::ThermoRichardsFlow::ThermoRichardsFlowProcess::assembleWithJacobianConcreteProcess().

Member Data Documentation

◆ global_matrix_output_

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

Definition at line 38 of file ParallelVectorMatrixAssembler.h.

Referenced by assembleWithJacobian().

◆ jacobian_assembler_

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

Definition at line 36 of file ParallelVectorMatrixAssembler.h.

Referenced by assembleWithJacobian().

◆ local_matrix_output_

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

Definition at line 37 of file ParallelVectorMatrixAssembler.h.

Referenced by assembleWithJacobian().

◆ num_threads_

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

Definition at line 40 of file ParallelVectorMatrixAssembler.h.


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