From: turcksin Date: Thu, 10 Oct 2013 16:56:19 +0000 (+0000) Subject: Use WorkStream instead of Thread in DerivativeApproximation::approximate_derivative. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5fb2f7ed7f1185ed6981c187aceffb3df057283d;p=dealii-svn.git Use WorkStream instead of Thread in DerivativeApproximation::approximate_derivative. git-svn-id: https://svn.dealii.org/trunk@31195 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/numerics/derivative_approximation.h b/deal.II/include/deal.II/numerics/derivative_approximation.h index 34ebddb381..3fd49856c4 100644 --- a/deal.II/include/deal.II/numerics/derivative_approximation.h +++ b/deal.II/include/deal.II/numerics/derivative_approximation.h @@ -665,21 +665,19 @@ private: /** * Compute the derivative - * approximation on the cells in - * the range given by the third - * parameter. + * approximation on a given cell. * Fill the @p derivative_norm vector with * the norm of the computed derivative - * tensors on each cell. + * tensors on the cell. */ template class DH, class InputVector, int spacedim> static void - approximate (const Mapping &mapping, + approximate (const typename DH::active_cell_iterator &cell, + const Mapping &mapping, const DH &dof, const InputVector &solution, const unsigned int component, - const IndexInterval &index_interval, Vector &derivative_norm); /** diff --git a/deal.II/source/numerics/derivative_approximation.cc b/deal.II/source/numerics/derivative_approximation.cc index ce8f37fde0..397e688c60 100644 --- a/deal.II/source/numerics/derivative_approximation.cc +++ b/deal.II/source/numerics/derivative_approximation.cc @@ -15,8 +15,8 @@ // --------------------------------------------------------------------- #include -#include #include +#include #include #include #include @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -64,6 +65,27 @@ const UpdateFlags DerivativeApproximation::ThirdDerivative::update_flags = +// Dummy structures and dummy function used for WorkStream +namespace internal +{ + namespace Assembler + { + struct Scratch + { + Scratch() {} + }; + + struct CopyData + { + CopyData() {} + }; + + void copier(CopyData const &) {} + } +} + + + template template inline @@ -626,30 +648,25 @@ approximate_derivative (const Mapping &mapping, Assert (component < dof_handler.get_fe().n_components(), ExcIndexRange (component, 0, dof_handler.get_fe().n_components())); - const unsigned int n_threads = multithread_info.n_threads(); - std::vector index_intervals - = Threads::split_interval (0, dof_handler.get_tria().n_active_cells(), - n_threads); - - typedef void (*FunPtr) (const Mapping &, - const DH &, - const InputVector &, - const unsigned int , - const IndexInterval &, - Vector &); - FunPtr fun_ptr = &DerivativeApproximation:: - template approximate; - -//TODO: Use WorkStream here - Threads::TaskGroup<> tasks; - for (unsigned int i=0; i::active_cell_iterator> CellFilter; + + // There is no need for a copier because there is no conflict between threads + // to write in derivative_norm. Scratch and CopyData are also useless. + WorkStream::run(CellFilter(IteratorFilters::LocallyOwnedCell(),dof_handler.begin_active()), + CellFilter(IteratorFilters::LocallyOwnedCell(),dof_handler.end()), + static_cast::active_cell_iterator const&, + internal::Assembler::Scratch const&,internal::Assembler::CopyData &)> > + (std_cxx1x::bind(DerivativeApproximation::template approximate, + std_cxx1x::_1, + std_cxx1x::cref(mapping), + std_cxx1x::cref(dof_handler), + std_cxx1x::cref(solution),component, + std_cxx1x::ref(derivative_norm))), + static_cast > + (internal::Assembler::copier),internal::Assembler::Scratch (), + internal::Assembler::CopyData ()); } @@ -657,48 +674,31 @@ approximate_derivative (const Mapping &mapping, template class DH, class InputVector, int spacedim> void -DerivativeApproximation::approximate (const Mapping &mapping, - const DH &dof_handler, - const InputVector &solution, - const unsigned int component, - const IndexInterval &index_interval, - Vector &derivative_norm) +DerivativeApproximation::approximate (const typename DH::active_cell_iterator &cell, + const Mapping &mapping, + const DH &dof_handler, + const InputVector &solution, + const unsigned int component, + Vector &derivative_norm) { // iterators over all cells and the // respective entries in the output // vector: - Vector::iterator - derivative_norm_on_this_cell - = derivative_norm.begin() + index_interval.first; - - typename DH::active_cell_iterator cell, endc; - cell = endc = dof_handler.begin_active(); - // (static_cast to avoid warnings - // about unsigned int always >=0) - std::advance (cell, static_cast(index_interval.first)); - std::advance (endc, static_cast(index_interval.second)); - - for (; cell!=endc; ++cell, ++derivative_norm_on_this_cell) - if (cell->is_locally_owned()) - { - typename DerivativeDescription::Derivative derivative; - // call the function doing the actual - // work on this cell - DerivativeApproximation:: - template approximate_cell - (mapping, - dof_handler, - solution, - component, - cell, - derivative); - // evaluate the norm and fill the vector - *derivative_norm_on_this_cell - = DerivativeDescription::derivative_norm (derivative); - } + Vector::iterator derivative_norm_on_this_cell = derivative_norm.begin() + + std::distance(dof_handler.begin_active(),cell); + + typename DerivativeDescription::Derivative derivative; + // call the function doing the actual + // work on this cell + DerivativeApproximation::template approximate_cell + (mapping,dof_handler,solution,component,cell,derivative); + // evaluate the norm and fill the vector + *derivative_norm_on_this_cell + = DerivativeDescription::derivative_norm (derivative); } + template class DH, class InputVector, int spacedim> void