From: richter Date: Fri, 11 Feb 2000 13:27:47 +0000 (+0000) Subject: enable multithreading X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=894dae1f2389006570f6d9403da86026d522ae31;p=dealii-svn.git enable multithreading git-svn-id: https://svn.dealii.org/trunk@2388 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/source/numerics/data_out.cc b/deal.II/deal.II/source/numerics/data_out.cc index 5fc709eac6..65c8e67ca1 100644 --- a/deal.II/deal.II/source/numerics/data_out.cc +++ b/deal.II/deal.II/source/numerics/data_out.cc @@ -11,6 +11,9 @@ #include #include +#ifdef DEAL_II_USE_MT +#include +#endif template DataOut_DoFData::DataEntry::DataEntry (const Vector *data, @@ -19,24 +22,17 @@ DataOut_DoFData::DataEntry::DataEntry (const Vector *data, names(names) {}; - - - template DataOut_DoFData::DataOut_DoFData () : dofs(0) {}; - - template DataOut_DoFData::~DataOut_DoFData () { clear (); }; - - template void DataOut_DoFData::attach_dof_handler (const DoFHandler &d) { @@ -51,8 +47,6 @@ void DataOut_DoFData::attach_dof_handler (const DoFHandler &d) dofs->subscribe (); }; - - template void DataOut_DoFData::add_data_vector (const Vector &vec, const vector &names) @@ -144,92 +138,59 @@ DataOut_DoFData::get_patches () const }; - - - - template -void DataOut::build_patches (const unsigned int n_subdivisions) +void * DataOut::build_some_patches (Data data) { - Assert (dofs != 0, ExcNoDoFHandlerSelected()); - - const unsigned int n_components = dofs->get_fe().n_components(); - const unsigned int n_datasets = dof_data.size() * n_components + - cell_data.size(); - - // clear the patches array - if (true) - { - vector > dummy; - patches.swap (dummy); - }; + QTrapez<1> q_trapez; + QIterated patch_points (q_trapez, data.n_subdivisions); + FEValues fe_patch_values(dofs->get_fe(), + patch_points, + update_default); - // first count the cells we want to - // create patches of and make sure - // there is enough memory for that - unsigned int n_patches = 0; - for (DoFHandler::cell_iterator cell=first_cell(); - cell != dofs->end(); - cell = next_cell(cell)) - ++n_patches; - - - // before we start the loop: - // create a quadrature rule that - // actually has the points on this - // patch, and an object that - // extracts the data on each - // cell to these points - QTrapez<1> q_trapez; - QIterated patch_points (q_trapez, n_subdivisions); - FEValues fe_patch_values (dofs->get_fe(), - patch_points, - update_default); const unsigned int n_q_points = patch_points.n_quadrature_points; - vector patch_values (n_q_points); - vector > patch_values_system (n_q_points, - Vector(n_components)); - DataOutBase::Patch default_patch; - default_patch.n_subdivisions = n_subdivisions; - default_patch.data.reinit (n_datasets, n_q_points); - patches.insert (patches.end(), n_patches, default_patch); + unsigned int cell_number = 0; + vector >::iterator patch = patches.begin(); + DoFHandler::cell_iterator cell=first_cell(); - // now loop over all cells and + // get first cell in this thread + for (unsigned int i=0;i >::iterator patch = patches.begin(); - unsigned int cell_number = 0; - for (DoFHandler::cell_iterator cell=first_cell(); - cell != dofs->end(); cell=next_cell(cell), ++patch, ++cell_number) + for (;cell != dofs->end();) { Assert (patch != patches.end(), ExcInternalError()); for (unsigned int vertex=0; vertex::vertices_per_cell; ++vertex) patch->vertices[vertex] = cell->vertex(vertex); - - if (n_datasets > 0) + + if (data.n_datasets > 0) { fe_patch_values.reinit (cell); // first fill dof_data for (unsigned int dataset=0; datasetdata(dataset,q) = patch_values[q]; + patch->data(dataset,q) = data.patch_values[q]; } else // system of components { fe_patch_values.get_function_values (*dof_data[dataset].data, - patch_values_system); - for (unsigned int component=0; componentdata(dataset*n_components+component,q) = patch_values_system[q](component); + patch->data(dataset*data.n_components+component,q) = + data.patch_values_system[q](component); }; }; @@ -238,10 +199,115 @@ void DataOut::build_patches (const unsigned int n_subdivisions) { const double value = (*cell_data[dataset].data)(cell_number); for (unsigned int q=0; qdata(dataset+dof_data.size()*n_components,q) = value; + patch->data(dataset+dof_data.size()*data.n_components,q) = + value; }; }; + // next cell (patch) in this thread + for (unsigned int i=0;((iend())); + ++i,++patch,++cell_number,cell=next_cell(cell)); + + }; + + return 0; +} + + + + +template +void DataOut::build_patches (const unsigned int n_subdivisions, + const unsigned int n_threads_) +{ + unsigned int n_threads = n_threads_; + + Assert (dofs != 0, ExcNoDoFHandlerSelected()); + + // if not in multithread mode + // set nr of threads to one +#ifndef DEAL_II_USE_MT + n_threads = 1; +#endif + + + // before we start the loop: + // create a quadrature rule that + // actually has the points on this + // patch + QTrapez<1> q_trapez; + QIterated patch_points (q_trapez, n_subdivisions); + + const unsigned int n_q_points = patch_points.n_quadrature_points; + const unsigned int n_components = dofs->get_fe().n_components(); + const unsigned int n_datasets = dof_data.size() * n_components + + cell_data.size(); + + // clear the patches array + if (true) + { + vector > dummy; + patches.swap (dummy); }; + + // first count the cells we want to + // create patches of and make sure + // there is enough memory for that + unsigned int n_patches = 0; + for (DoFHandler::cell_iterator cell=first_cell(); + cell != dofs->end(); + cell = next_cell(cell)) + ++n_patches; + + vector thread_data(n_threads); + + // init data for the threads + for (unsigned int i=0;i default_patch; + default_patch.n_subdivisions = n_subdivisions; + default_patch.data.reinit (n_datasets, n_q_points); + patches.insert (patches.end(), n_patches, default_patch); + +#ifdef DEAL_II_USE_MT + + ThreadManager thread_manager; + + typedef ThreadManager::Mem_Fun_Data1 + , Data > MemFunData; + + // One struct of this type for every thread + vector mem_fun_data (n_threads, + MemFunData (this, + thread_data[0], + &DataOut::build_some_patches)); + + // get start cells for each thread + for (unsigned int l=0;l