From f764ca612c60c5b1bbde5b3b73b74ed92b09a2e7 Mon Sep 17 00:00:00 2001 From: wolf Date: Thu, 24 Feb 2000 13:13:32 +0000 Subject: [PATCH] Update to auto-detection of the number of CPUs in a system. git-svn-id: https://svn.dealii.org/trunk@2491 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/deal.II/include/numerics/data_out.h | 21 +++++--- .../include/numerics/error_estimator.h | 48 +++++++------------ .../deal.II/include/numerics/time_dependent.h | 9 ++-- deal.II/deal.II/source/numerics/data_out.cc | 18 ++++--- .../source/numerics/error_estimator.cc | 35 +++++++------- 5 files changed, 62 insertions(+), 69 deletions(-) diff --git a/deal.II/deal.II/include/numerics/data_out.h b/deal.II/deal.II/include/numerics/data_out.h index 237c187f06..e3a9329b07 100644 --- a/deal.II/deal.II/include/numerics/data_out.h +++ b/deal.II/deal.II/include/numerics/data_out.h @@ -17,6 +17,8 @@ #include #include #include +#include + /** @@ -391,13 +393,18 @@ class DataOut : public DataOut_DoFData * general documentation of this class * for further information. * - * The functions supports multithreading. + * The function supports + * multithreading, if deal.II is + * compiled in multithreading + * mode. The default number of + * threads to be used to build + * the patches is set to + * #multithread_info.n_default_threads#. */ virtual void build_patches (const unsigned int n_subdivisions = 1, - const unsigned int n_threads_ = 1); - + const unsigned int n_threads = multithread_info.n_default_threads); -/** + /** * Return the first cell which we * want output for. The default * implementation returns the first @@ -453,14 +460,14 @@ class DataOut : public DataOut_DoFData {} }; /** - * Builds every #n_threads's# + * Builds every #n_threads#'s * patch. This function may be - * called parallel. + * called in parallel. * If multithreading is not * used, the function is called * once and generates all patches. */ - void * DataOut::build_some_patches (Data data); + void DataOut::build_some_patches (Data data); }; diff --git a/deal.II/deal.II/include/numerics/error_estimator.h b/deal.II/deal.II/include/numerics/error_estimator.h index f2ab12e961..fe7070207c 100644 --- a/deal.II/deal.II/include/numerics/error_estimator.h +++ b/deal.II/deal.II/include/numerics/error_estimator.h @@ -16,25 +16,11 @@ #include #include +#include #include #include #include - // if multithreaded set number - // of threads to use. - // The default number of threads can - // be set during the compiling with - // the flag N_THREADS. -#ifdef DEAL_II_USE_MT - #ifndef N_THREADS - #define N_THREADS 4 - #endif -#else - #ifdef N_THREADS - #undef N_THREADS - #endif - #define N_THREADS 1 -#endif /** @@ -247,23 +233,25 @@ class KellyErrorEstimator * * The estimator supports * multithreading and splits the - * cells to #N_THREADS# (default) - * threads. The number of threads - * to be used in multithreaded - * mode can be set with the last - * parameter of the error - * estimator. Multithreading is - * only implemented in two and - * three dimensions. + * cells to + * #multithread_info.n_default_threads# + * (default) threads. The number + * of threads to be used in + * multithreaded mode can be set + * with the last parameter of the + * error estimator. + * Multithreading is only + * implemented in two and three + * dimensions. */ static void estimate (const DoFHandler &dof, const Quadrature &quadrature, const FunctionMap &neumann_bc, const Vector &solution, Vector &error, - const vector &component_mask_ = vector(), + const vector &component_mask = vector(), const Function *coefficients = 0, - unsigned int n_threads=N_THREADS); + unsigned int n_threads = multithread_info.n_default_threads); /** * Exception @@ -332,7 +320,7 @@ private: * is done by the C++ library and * has not to be handcoded, it * nevertheless seriously damages - * tha ability to efficiently run + * the ability to efficiently run * the functions of this class in * parallel, since they are quite * often blocked by these @@ -422,7 +410,7 @@ private: }; -/** + /** * Computates the error on all cells * of the domain with the number n, * satisfying @@ -458,9 +446,7 @@ private: * to avoid ending up with a function * of 500 lines of code. */ - - -static void integrate_over_regular_face (Data &data, + static void integrate_over_regular_face (Data &data, const unsigned int this_thread, const active_cell_iterator &cell, const unsigned int face_no, @@ -468,7 +454,7 @@ static void integrate_over_regular_face (Data &data, FEFaceValues &fe_face_values_neighbor); -/** + /** * The same applies as for the function * above, except that integration is * over face #face_no# of #cell#, where diff --git a/deal.II/deal.II/include/numerics/time_dependent.h b/deal.II/deal.II/include/numerics/time_dependent.h index a2f700ea55..25a4f39334 100644 --- a/deal.II/deal.II/include/numerics/time_dependent.h +++ b/deal.II/deal.II/include/numerics/time_dependent.h @@ -663,9 +663,11 @@ class TimeDependent * The parameter denotes the * number of threads that shall * be spawned in parallel. It - * defaults to only one thread, - * and the value is ignored if - * not in multithread mode. + * defaults to only one thread to + * avoid hidden synchronisation + * problems, and the value is + * ignored if not in multithread + * mode. */ virtual void end_sweep (const unsigned int n_threads = 1); @@ -728,6 +730,7 @@ class TimeDependent }; + /** * Base class for a time step in time dependent problems. This class provides * barely more than the basic framework, defining the necessary virtual diff --git a/deal.II/deal.II/source/numerics/data_out.cc b/deal.II/deal.II/source/numerics/data_out.cc index 3974a81bed..55a14aeb39 100644 --- a/deal.II/deal.II/source/numerics/data_out.cc +++ b/deal.II/deal.II/source/numerics/data_out.cc @@ -146,6 +146,7 @@ vector DataOut_DoFData::get_dataset_names () const }; + template const vector > & DataOut_DoFData::get_patches () const @@ -154,8 +155,9 @@ DataOut_DoFData::get_patches () const }; + template -void * DataOut::build_some_patches (Data data) +void DataOut::build_some_patches (Data data) { QTrapez<1> q_trapez; QIterated patch_points (q_trapez, data.n_subdivisions); @@ -224,8 +226,6 @@ void * DataOut::build_some_patches (Data data) ++i,++patch,++cell_number,cell=next_cell(cell)); }; - - return 0; } @@ -233,14 +233,12 @@ 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; +#ifdef DEAL_II_USE_MT + const unsigned int n_threads = n_threads_; +#else + const unsigned int n_threads = 1; #endif @@ -301,7 +299,7 @@ void DataOut::build_patches (const unsigned int n_subdivisions, ThreadManager thread_manager; typedef ThreadManager::Mem_Fun_Data1 - , Data > MemFunData; + , Data> MemFunData; // One struct of this type for every thread vector mem_fun_data (n_threads, diff --git a/deal.II/deal.II/source/numerics/error_estimator.cc b/deal.II/deal.II/source/numerics/error_estimator.cc index c8d794ab9a..e1aebd488a 100644 --- a/deal.II/deal.II/source/numerics/error_estimator.cc +++ b/deal.II/deal.II/source/numerics/error_estimator.cc @@ -340,10 +340,9 @@ DoFHandler::active_cell_iterator cell=data.dof.begin_active(); // be used, the threads would take widely // spread times to calculate their cells. for (unsigned int t=0;t::active_cell_iterator cell=data.dof.begin_active(); }; -if (cell->face(face_no)->has_children() == false) + if (cell->face(face_no)->has_children() == false) // if the face is a regular one, i.e. // either on the other side there is // nirvana (face is at boundary), or @@ -407,11 +406,13 @@ if (cell->face(face_no)->has_children() == false) }; // next cell in this thread - for (unsigned int t=0;((t void KellyErrorEstimator::estimate (const DoFHandler &dof, const Quadrature &quadrature, @@ -450,7 +451,7 @@ void KellyErrorEstimator::estimate (const DoFHandler &dof, // of the cell. // the values for all faces are set to // -10e20. It would cost a lot of time - // to syncronisise the initialisation + // to synchronise the initialisation // of the map in multithreaded mode. // negative value indicates that the // face is not calculated. @@ -460,7 +461,7 @@ void KellyErrorEstimator::estimate (const DoFHandler &dof, data.face_integrals[cell->face(face_no)]=-10e20; -// split all cells into threads + // split all cells into threads // if multithreading is used #ifdef DEAL_II_USE_MT @@ -478,17 +479,15 @@ void KellyErrorEstimator::estimate (const DoFHandler &dof, FunData (data,0,&KellyErrorEstimator::estimate_some)); -// get start cells for each thread + // get start cells for each thread for (unsigned int l=0;lat_boundary() == true) + if (face->at_boundary() == true) // neumann boundary face. compute // difference between normal // derivative and boundary function @@ -689,7 +688,7 @@ if (face->at_boundary() == true) }; -// now phi contains the following: + // now phi contains the following: // - for an internal face, phi=[a du/dn] // - for a neumann boundary face, // phi=a du/dn-g @@ -712,6 +711,7 @@ if (face->at_boundary() == true) }; + template void KellyErrorEstimator:: integrate_over_irregular_face (Data &data, @@ -800,7 +800,7 @@ integrate_over_irregular_face (Data &data, data.normal_vectors[this_thread]=fe_face_values.get_normal_vectors(); -for (unsigned int component=0; component