From: Wolfgang Bangerth Date: Thu, 11 May 2000 13:03:45 +0000 (+0000) Subject: Assemble matrix and rhs in parallel. X-Git-Tag: v8.0.0~20565 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=59204cb0101123e341cc3bda020472289b5ad60c;p=dealii.git Assemble matrix and rhs in parallel. git-svn-id: https://svn.dealii.org/trunk@2840 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/examples/step-9/step-9.cc b/deal.II/examples/step-9/step-9.cc index 7de8c2edf7..9b56013479 100644 --- a/deal.II/examples/step-9/step-9.cc +++ b/deal.II/examples/step-9/step-9.cc @@ -25,6 +25,11 @@ #include #include +#ifdef DEAL_II_USE_MT +# include +# include +#endif + #include #include @@ -43,6 +48,9 @@ class AdvectionProblem private: void setup_system (); void assemble_system (); + void assemble_system_interval (const DoFHandler::active_cell_iterator &begin, + const DoFHandler::active_cell_iterator &begin); + void solve (); void refine_grid (); void output_results (const unsigned int cycle) const; @@ -59,6 +67,10 @@ class AdvectionProblem Vector solution; Vector system_rhs; + +#ifdef DEAL_II_USE_MT + ACE_Thread_Mutex assembler_lock; +#endif }; @@ -255,6 +267,39 @@ void AdvectionProblem::setup_system () template void AdvectionProblem::assemble_system () +{ +#ifdef DEAL_II_USE_MT + const unsigned int n_threads = multithread_info.n_default_threads; + ACE_Thread_Manager thread_manager; + + // define starting and end point + // for each thread + typedef typename DoFHandler::active_cell_iterator active_cell_iterator; + vector > + thread_ranges = Threads::split_range (dof_handler.begin_active (), + dof_handler.end (), + n_threads); + + for (unsigned int thread=0; thread::assemble_system_interval) + .collect_args (this, + thread_ranges[thread].first, + thread_ranges[thread].second)); + thread_manager.wait (); +#else + assemble_system_interval (dof_handler.begin_active(), + dof_handler.end()); +#endif +}; + + + +template +void +AdvectionProblem:: +assemble_system_interval (const DoFHandler::active_cell_iterator &begin, + const DoFHandler::active_cell_iterator &end) { AdvectionField advection_field; RightHandSide right_hand_side; @@ -288,9 +333,8 @@ void AdvectionProblem::assemble_system () vector face_boundary_values (n_face_q_points); vector > face_advection_directions (n_face_q_points); - DoFHandler::active_cell_iterator cell = dof_handler.begin_active(), - endc = dof_handler.end(); - for (; cell!=endc; ++cell) + DoFHandler::active_cell_iterator cell; + for (cell=begin; cell!=end; ++cell) { cell_matrix.clear (); cell_rhs.clear (); @@ -368,6 +412,9 @@ void AdvectionProblem::assemble_system () cell->get_dof_indices (local_dof_indices); +#ifdef DEAL_II_USE_MT + assembler_lock.acquire (); +#endif for (unsigned int i=0; i::assemble_system () system_rhs(local_dof_indices[i]) += cell_rhs(i); }; +#ifdef DEAL_II_USE_MT + assembler_lock.release (); +#endif }; hanging_node_constraints.condense (system_matrix);