From 5cdcff04b6f98f4be9d43ec3c1905626f65b0567 Mon Sep 17 00:00:00 2001 From: wolf Date: Mon, 31 Jan 2000 16:23:40 +0000 Subject: [PATCH] Multithreadify the computation of the inverses. git-svn-id: https://svn.dealii.org/trunk@2296 0785d39b-7218-0410-832d-ea1e28bc413d --- .../lac/include/lac/sparse_matrix.templates.h | 2 +- deal.II/lac/include/lac/sparse_vanka.h | 14 ++++ .../lac/include/lac/sparse_vanka.templates.h | 77 ++++++++++++++++++- 3 files changed, 91 insertions(+), 2 deletions(-) diff --git a/deal.II/lac/include/lac/sparse_matrix.templates.h b/deal.II/lac/include/lac/sparse_matrix.templates.h index b0223fa581..803f39efce 100644 --- a/deal.II/lac/include/lac/sparse_matrix.templates.h +++ b/deal.II/lac/include/lac/sparse_matrix.templates.h @@ -248,7 +248,7 @@ SparseMatrix::vmult (Vector& dst, const Vector& mem_fun_data[i].arg3 = n_rows * i / n_threads; mem_fun_data[i].arg4 = n_rows * (i+1) / n_threads; - thread_manager.spawn (&mem_fun_data[i],THR_SCOPE_SYSTEM | THR_DETACHED); + thread_manager.spawn (&mem_fun_data[i], THR_SCOPE_SYSTEM | THR_DETACHED); }; // ... and wait until they're finished diff --git a/deal.II/lac/include/lac/sparse_vanka.h b/deal.II/lac/include/lac/sparse_vanka.h index c33ae98435..1793b35563 100644 --- a/deal.II/lac/include/lac/sparse_vanka.h +++ b/deal.II/lac/include/lac/sparse_vanka.h @@ -205,6 +205,20 @@ class SparseVanka */ void compute_inverses (); + /** + * Compute the inverses at + * positions in the range + * #[begin,end)#. In + * non-multithreaded mode, + * #compute_inverses()# calls + * this function with the whole + * range, but in multithreaded + * mode, several copies of this + * function are spawned. + */ + void compute_inverses (const unsigned int begin, + const unsigned int end); + /** * Compute the inverse of the * block located at position diff --git a/deal.II/lac/include/lac/sparse_vanka.templates.h b/deal.II/lac/include/lac/sparse_vanka.templates.h index 71f97593ca..02d4e00099 100644 --- a/deal.II/lac/include/lac/sparse_vanka.templates.h +++ b/deal.II/lac/include/lac/sparse_vanka.templates.h @@ -6,6 +6,11 @@ #include #include +#ifdef DEAL_II_USE_MT +# include +# include +#endif + #include @@ -46,11 +51,81 @@ template void SparseVanka::compute_inverses () { +#ifdef DEAL_II_USE_MT + const unsigned int n_threads = 4; + const unsigned int n_inverses = count (selected.begin(), + selected.end(), + true); + + const unsigned int n_inverses_per_thread = max(n_inverses / n_threads, + 1U); + + // set up start and end index for + // each of the threads. note that + // we have to work somewhat to get + // this appropriate, since the + // indices for which inverses have + // to be computed may not be evenly + // distributed in the vector. as an + // extreme example consider + // numbering of DoFs by component, + // then all indices for which we + // have to do work will be + // consecutive, with other + // consecutive regions where we do + // not have to do something + typedef ThreadManager::Mem_Fun_Data2,unsigned int,unsigned int> MemFunData; + vector mem_fun_data (n_threads, + MemFunData(this, + 0, 0, + &compute_inverses)); + + unsigned int c = 0; + unsigned int thread = 0; + mem_fun_data[0].arg1 = 0; + + for (unsigned int i=0; (im()) && (thread+1m(); + + // Now spawn the threads + ThreadManager thread_manager; + for (unsigned int i=0; im()); +#endif +}; + + + +template +void +SparseVanka::compute_inverses (const unsigned int begin, + const unsigned int end) +{ + // set-up the map that will be used + // by the functions which we call + // below. map local_index; // traverse all rows of the matrix // which are selected - for (unsigned int row=0; row< matrix->m() ; ++row) + for (unsigned int row=begin; row