From ef3b5bd25a5648f43894d746cf2c96a38ca3c30e Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Tue, 9 Jul 2013 14:45:02 +0000 Subject: [PATCH] More minimizing. git-svn-id: https://svn.dealii.org/trunk@29957 0785d39b-7218-0410-832d-ea1e28bc413d --- tests/base/work_stream_03.cc | 158 +++++++++++++++-------------------- 1 file changed, 67 insertions(+), 91 deletions(-) diff --git a/tests/base/work_stream_03.cc b/tests/base/work_stream_03.cc index 0dfb8655c3..eec7d02992 100644 --- a/tests/base/work_stream_03.cc +++ b/tests/base/work_stream_03.cc @@ -11,7 +11,6 @@ // //---------------------------- work_stream_03.cc --------------------------- - // Moritz originally implemented thread local scratch objects for // WorkStream in r24748 but it led to failures in the testsuite. what // exactly went on was a mystery and this test is a first step in @@ -29,9 +28,6 @@ #include #include #include -#include -#include -#include #include #include @@ -40,145 +36,125 @@ char logname[] = "work_stream_03/output"; - - -template -double value (const Point &p) -{ - double val = 0; - for (unsigned int d=0; d + double + value(const Point &p) + { + double val = 0; + for (unsigned int d = 0; d < dim; ++d) + for (unsigned int i = 0; i <= 1; ++i) + val += std::pow(p[d], 1. * i); + return val; + } namespace { - template - struct Scratch - { - Scratch (const FiniteElement &fe, - const Quadrature &quadrature) - : - fe_collection (fe), - quadrature_collection (quadrature), - x_fe_values (fe_collection, - quadrature_collection, - update_q_points), - rhs_values(quadrature_collection.size()) - {} - - Scratch (const Scratch &data) - : - fe_collection (data.fe_collection), - quadrature_collection (data.quadrature_collection), - x_fe_values (fe_collection, - quadrature_collection, - update_q_points), - rhs_values (data.rhs_values) - {} - - const FiniteElement &fe_collection; - const Quadrature &quadrature_collection; - - FEValues x_fe_values; - - std::vector rhs_values; - }; + template + struct Scratch + { + Scratch(const FiniteElement &fe, const Quadrature &quadrature) : + fe_collection(fe), quadrature_collection(quadrature), x_fe_values( + fe_collection, quadrature_collection, update_q_points), rhs_values( + quadrature_collection.size()) + { + } + + Scratch(const Scratch &data) : + fe_collection(data.fe_collection), quadrature_collection( + data.quadrature_collection), x_fe_values(fe_collection, + quadrature_collection, update_q_points), rhs_values( + data.rhs_values) + { + } + + const FiniteElement &fe_collection; + const Quadrature &quadrature_collection; + + FEValues x_fe_values; + std::vector rhs_values; + }; struct CopyData { - std::vector cell_rhs; + std::vector cell_rhs; }; } -void zero_subrange (const unsigned int begin, - const unsigned int end, - std::vector &dst) +void +zero_subrange(const unsigned int begin, const unsigned int end, + std::vector &dst) { - for (unsigned int i=begin; i +template void - mass_assembler(const CellIterator &cell, Scratch &data, - CopyData ©_data) + mass_assembler(const typename Triangulation::active_cell_iterator &cell, + Scratch &data, CopyData ©_data) { data.x_fe_values.reinit(cell); - const Point q=data.x_fe_values.quadrature_point(0); + const Point q = data.x_fe_values.quadrature_point(0); // this appears to be the key: the following line overwrites some of the memory // in which we store the quadrature point location. if the line is moved down, // the comparison in the if() always succeeds... - parallel::apply_to_subranges - (0U, copy_data.cell_rhs.size(), - std_cxx1x::bind(&zero_subrange, - std_cxx1x::_1, std_cxx1x::_2, std_cxx1x::ref(copy_data.cell_rhs)), - 1); + parallel::apply_to_subranges(0U, copy_data.cell_rhs.size(), + std_cxx1x::bind(&zero_subrange, std_cxx1x::_1, std_cxx1x::_2, + std_cxx1x::ref(copy_data.cell_rhs)), 1); - std::cout << (q != data.x_fe_values.quadrature_point(0) ? '.' : '*') << std::flush; + std::cout << (q != data.x_fe_values.quadrature_point(0) ? '.' : '*') + << std::flush; copy_data.cell_rhs[0] = value(data.x_fe_values.quadrature_point(0)); } - -void copy_local_to_global (const CopyData &data, - double *sum) +void +copy_local_to_global(const CopyData &data, double *sum) { *sum += data.cell_rhs[0]; } - -void do_project () +void +do_project() { static const int dim = 3; - Triangulation triangulation; + Triangulation < dim > triangulation; GridGenerator::hyper_cube (triangulation); - triangulation.refine_global (2); - - FE_Nothing<3> fe; - DoFHandler dof_handler(triangulation); - dof_handler.distribute_dofs (fe); + triangulation.refine_global(2); - QMidpoint q; + FE_Nothing < dim > fe; + QMidpoint < dim > q; - for (unsigned int i=0; i<12; ++i) + for (unsigned int i = 0; i < 12; ++i) { std::vector tmp; double sum = 0; - Scratch assembler_data (dof_handler.get_fe(), q); + Scratch assembler_data(fe, q); CopyData copy_data; - copy_data.cell_rhs.resize (8); - dealii::WorkStream::run (dof_handler.begin_active(), - dof_handler.end(), - &mass_assembler::active_cell_iterator>, - std_cxx1x::bind(& - copy_local_to_global, - std_cxx1x::_1, &sum), - assembler_data, - copy_data, - 8, - 1); - printf ("\nCheck: %5.3f\n", sum); + copy_data.cell_rhs.resize(8); + WorkStream::run(triangulation.begin_active(), triangulation.end(), + &mass_assembler, + std_cxx1x::bind(©_local_to_global, std_cxx1x::_1, &sum), + assembler_data, copy_data, 8, 1); + printf("\nCheck: %5.3f\n", sum); deallog << sum << std::endl; } } -int main () +int main() { std::ofstream logfile(logname); - deallog << std::setprecision (3); + deallog << std::setprecision(3); deallog.attach(logfile); deallog.depth_console(0); deallog.threshold_double(1.e-10); - do_project (); + do_project(); } -- 2.39.5