From 6fc99aa366d09c76cfecaaa8e18e4ab58c844f2b Mon Sep 17 00:00:00 2001 From: Martin Kronbichler Date: Tue, 29 Oct 2013 17:14:34 +0000 Subject: [PATCH] Use a pointer to DataOut class in std::bind as this is the usual way of doing. This avoids calling a copy constructor of DataOut on every item WorkStream creates on certain compilers git-svn-id: https://svn.dealii.org/trunk@31484 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/include/deal.II/base/work_stream.h | 321 +++++++------------ deal.II/source/numerics/data_out.cc | 2 +- deal.II/source/numerics/data_out_faces.cc | 2 +- deal.II/source/numerics/data_out_rotation.cc | 2 +- 4 files changed, 120 insertions(+), 207 deletions(-) diff --git a/deal.II/include/deal.II/base/work_stream.h b/deal.II/include/deal.II/base/work_stream.h index 7c61f42113..be3a6bd410 100644 --- a/deal.II/include/deal.II/base/work_stream.h +++ b/deal.II/include/deal.II/base/work_stream.h @@ -146,8 +146,7 @@ namespace WorkStream // and that is available also as a fall-back whenever via boost or similar /** - * A class that creates a sequence of - * items from a range of iterators. + * A class that creates a sequence of items from a range of iterators. */ template copier; }; @@ -750,58 +741,35 @@ namespace WorkStream /** - * This is the main function of the - * WorkStream concept, doing work as - * described in the introduction to this - * namespace. + * This is the main function of the WorkStream concept, doing work as + * described in the introduction to this namespace. * - * This is the function that can be used - * for worker and copier objects that are - * either pointers to non-member - * functions or objects that allow to be - * called with an operator(), for example - * objects created by std::bind. + * This is the function that can be used for worker and copier objects that + * are either pointers to non-member functions or objects that allow to be + * called with an operator(), for example objects created by std::bind. * - * The argument passed as @p end must be - * convertible to the same type as - * @p begin, but doesn't have to be of the - * same type itself. This allows to write - * code like - * WorkStream().run(dof_handler.begin_active(), - * dof_handler.end(), ... where - * the first is of type - * DoFHandler::active_cell_iterator - * whereas the second is of type + * The argument passed as @p end must be convertible to the same type as @p + * begin, but doesn't have to be of the same type itself. This allows to + * write code like WorkStream().run(dof_handler.begin_active(), + * dof_handler.end(), ... where the first is of type + * DoFHandler::active_cell_iterator whereas the second is of type * DoFHandler::raw_cell_iterator. * - * The two data types - * ScratchData and - * CopyData need to have a - * working copy - * constructor. ScratchData - * is only used in the - * worker function, while - * CopyData is the object - * passed from the worker - * to the copier. + * The two data types ScratchData and CopyData need to + * have a working copy constructor. ScratchData is only used in the + * worker function, while CopyData is the object passed + * from the worker to the copier. * - * The @p queue_length argument indicates - * the number of items that can be live - * at any given time. Each item consists - * of @p chunk_size elements of the input - * stream that will be worked on by the - * worker and copier functions one after - * the other on the same thread. + * The @p queue_length argument indicates the number of items that can be + * live at any given time. Each item consists of @p chunk_size elements of + * the input stream that will be worked on by the worker and copier + * functions one after the other on the same thread. * - * @note If your data objects are large, - * or their constructors are expensive, - * it is helpful to keep in mind - * that queue_length - * copies of the ScratchData - * object and - * queue_length*chunk_size - * copies of the CopyData - * object are generated. + * @note If your data objects are large, or their constructors are + * expensive, it is helpful to keep in mind that queue_length + * copies of the ScratchData object and + * queue_length*chunk_size copies of the CopyData object + * are generated. */ template >(worker)) - worker (i, scratch_data, copy_data); - if (static_cast > - (copier)) - copier (copy_data); + // need to check if the function is not the zero function. To + // check zero-ness, create a C++ function out of it and check that + if (static_cast& >(worker)) + worker (i, scratch_data, copy_data); + if (static_cast& > + (copier)) + copier (copy_data); } } #ifdef DEAL_II_WITH_THREADS @@ -886,66 +854,42 @@ namespace WorkStream /** - * This is the main function of the - * WorkStream concept, doing work as - * described in the introduction to this - * namespace. + * This is the main function of the WorkStream concept, doing work as + * described in the introduction to this namespace. * - * This is the function that can be used - * for worker and copier objects that are - * either pointers to non-member - * functions or objects that allow to be - * called with an operator(), for example - * objects created by std::bind. + * This is the function that can be used for worker and copier objects that + * are either pointers to non-member functions or objects that allow to be + * called with an operator(), for example objects created by std::bind. * - * The argument passed as @p end must be - * convertible to the same type as - * @p begin, but doesn't have to be of the - * same type itself. This allows to write - * code like - * WorkStream().run(dof_handler.begin_active(), - * dof_handler.end(), ... where - * the first is of type - * DoFHandler::active_cell_iterator - * whereas the second is of type + * The argument passed as @p end must be convertible to the same type as @p + * begin, but doesn't have to be of the same type itself. This allows to + * write code like WorkStream().run(dof_handler.begin_active(), + * dof_handler.end(), ... where the first is of type + * DoFHandler::active_cell_iterator whereas the second is of type * DoFHandler::raw_cell_iterator. * - * The two data types - * ScratchData and - * CopyData need to have a - * working copy - * constructor. ScratchData - * is only used in the - * worker function, while - * CopyData is the object - * passed from the worker - * to the copier. + * The two data types ScratchData and CopyData need to + * have a working copy constructor. ScratchData is only used in the + * worker function, while CopyData is the object passed + * from the worker to the copier. * - * The @p get_conflict_indices argument, is a function - * that given an iterator computes the conflict indices - * necessary for the graph_coloring. Graph coloring is - * necessary to be able to copy the data in parallel. If - * the number of elements in some colors is less than - * @p chunk_size time multithread_info.n_threads(), - * these elements are aggregated and copied serially. + * The @p get_conflict_indices argument, is a function that given an + * iterator computes the conflict indices necessary for the + * graph_coloring. Graph coloring is necessary to be able to copy the data + * in parallel. If the number of elements in some colors is less than @p + * chunk_size time multithread_info.n_threads(), these elements are + * aggregated and copied serially. * - * The @p queue_length argument indicates - * the number of items that can be live - * at any given time. Each item consists - * of @p chunk_size elements of the input - * stream that will be worked on by the - * worker and copier functions one after - * the other on the same thread. + * The @p queue_length argument indicates the number of items that can be + * live at any given time. Each item consists of @p chunk_size elements of + * the input stream that will be worked on by the worker and copier + * functions one after the other on the same thread. * - * @note If your data objects are large, - * or their constructors are expensive, - * it is helpful to keep in mind - * that queue_length - * copies of the ScratchData - * object and - * queue_length*chunk_size - * copies of the CopyData - * object are generated. + * @note If your data objects are large, or their constructors are + * expensive, it is helpful to keep in mind that queue_length + * copies of the ScratchData object and + * queue_length*chunk_size copies of the CopyData object + * are generated. */ template >(worker)) + CopyData &)>& >(worker)) worker (i, scratch_data, copy_data); - if (static_cast > + if (static_cast& > (copier)) copier (copy_data); } @@ -1076,44 +1020,29 @@ namespace WorkStream /** - * This is the main function of the - * WorkStream concept, doing work as - * described in the introduction to this - * namespace. + * This is the main function of the WorkStream concept, doing work as + * described in the introduction to this namespace. * - * This is the function that can be - * used for worker and copier functions + * This is the function that can be used for worker and copier functions * that are member functions of a class. * - * The argument passed as @p end must be - * convertible to the same type as - * @p begin, but doesn't have to be of the - * same type itself. This allows to write - * code like - * WorkStream().run(dof_handler.begin_active(), - * dof_handler.end(), ... where - * the first is of type - * DoFHandler::active_cell_iterator - * whereas the second is of type + * The argument passed as @p end must be convertible to the same type as @p + * begin, but doesn't have to be of the same type itself. This allows to + * write code like WorkStream().run(dof_handler.begin_active(), + * dof_handler.end(), ... where the first is of type + * DoFHandler::active_cell_iterator whereas the second is of type * DoFHandler::raw_cell_iterator. * - * The @p queue_length argument indicates - * the number of items that can be live - * at any given time. Each item consists - * of @p chunk_size elements of the input - * stream that will be worked on by the - * worker and copier functions one after - * the other on the same thread. + * The @p queue_length argument indicates the number of items that can be + * live at any given time. Each item consists of @p chunk_size elements of + * the input stream that will be worked on by the worker and copier + * functions one after the other on the same thread. * - * @note If your data objects are large, - * or their constructors are expensive, - * it is helpful to keep in mind - * that queue_length - * copies of the ScratchData - * object and - * queue_length*chunk_size - * copies of the CopyData - * object are generated. + * @note If your data objects are large, or their constructors are + * expensive, it is helpful to keep in mind that queue_length + * copies of the ScratchData object and + * queue_length*chunk_size copies of the CopyData object + * are generated. */ template WorkStream().run(dof_handler.begin_active(), - * dof_handler.end(), ... where - * the first is of type - * DoFHandler::active_cell_iterator - * whereas the second is of type + * The argument passed as @p end must be convertible to the same type as @p + * begin, but doesn't have to be of the same type itself. This allows to + * write code like WorkStream().run(dof_handler.begin_active(), + * dof_handler.end(), ... where the first is of type + * DoFHandler::active_cell_iterator whereas the second is of type * DoFHandler::raw_cell_iterator. * - * The @p get_conflict_indices argument, is a function - * that given an iterator computes the conflict indices - * necessary for the graph_coloring. Graph coloring is - * necessary to be able to copy the data in parallel. If - * the number of elements in some colors is less than - * @p chunk_size time multithread_info.n_threads(), - * these elements are aggregated and copied serially. + * The @p get_conflict_indices argument, is a function that given an + * iterator computes the conflict indices necessary for the + * graph_coloring. Graph coloring is necessary to be able to copy the data + * in parallel. If the number of elements in some colors is less than @p + * chunk_size time multithread_info.n_threads(), these elements are + * aggregated and copied serially. * - * The @p queue_length argument indicates - * the number of items that can be live - * at any given time. Each item consists - * of @p chunk_size elements of the input - * stream that will be worked on by the - * worker and copier functions one after - * the other on the same thread. + * The @p queue_length argument indicates the number of items that can be + * live at any given time. Each item consists of @p chunk_size elements of + * the input stream that will be worked on by the worker and copier + * functions one after the other on the same thread. * - * @note If your data objects are large, - * or their constructors are expensive, - * it is helpful to keep in mind - * that queue_length - * copies of the ScratchData - * object and - * queue_length*chunk_size - * copies of the CopyData - * object are generated. + * @note If your data objects are large, or their constructors are + * expensive, it is helpful to keep in mind that queue_length + * copies of the ScratchData object and + * queue_length*chunk_size copies of the CopyData object + * are generated. */ template ::build_patches (const Mapping::build_one_patch, - *this, std_cxx1x::_1, std_cxx1x::_2, std_cxx1x::_3, + this, std_cxx1x::_1, std_cxx1x::_2, std_cxx1x::_3, curved_cell_region,std_cxx1x::ref(this->patches)), std_cxx1x::bind(&internal::DataOut::copy, std_cxx1x::_1), diff --git a/deal.II/source/numerics/data_out_faces.cc b/deal.II/source/numerics/data_out_faces.cc index 4dd1ccec43..9f26567228 100644 --- a/deal.II/source/numerics/data_out_faces.cc +++ b/deal.II/source/numerics/data_out_faces.cc @@ -332,7 +332,7 @@ void DataOutFaces::build_patches (const Mapping &mapping, WorkStream::run (&all_faces[0], &all_faces[0]+all_faces.size(), std_cxx1x::bind(&DataOutFaces::build_one_patch, - *this, std_cxx1x::_1, std_cxx1x::_2, std_cxx1x::_3), + this, std_cxx1x::_1, std_cxx1x::_2, std_cxx1x::_3), std_cxx1x::bind(&internal::DataOutFaces:: append_patch_to_list, std_cxx1x::_1, std_cxx1x::ref(this->patches)), diff --git a/deal.II/source/numerics/data_out_rotation.cc b/deal.II/source/numerics/data_out_rotation.cc index 5593d7a792..5082a83008 100644 --- a/deal.II/source/numerics/data_out_rotation.cc +++ b/deal.II/source/numerics/data_out_rotation.cc @@ -474,7 +474,7 @@ void DataOutRotation::build_patches (const unsigned int n_patches_per_ci WorkStream::run (&all_cells[0], &all_cells[0]+all_cells.size(), std_cxx1x::bind(&DataOutRotation::build_one_patch, - *this, std_cxx1x::_1, std_cxx1x::_2, std_cxx1x::_3), + this, std_cxx1x::_1, std_cxx1x::_2, std_cxx1x::_3), std_cxx1x::bind(&internal::DataOutRotation ::append_patch_to_list, std_cxx1x::_1, std_cxx1x::ref(this->patches)), -- 2.39.5