]> https://gitweb.dealii.org/ - dealii.git/commitdiff
add thread mutex to const functions which use mutable variables
authorDenis Davydov <davydden@gmail.com>
Tue, 26 Sep 2017 14:00:32 +0000 (16:00 +0200)
committerDenis Davydov <davydden@gmail.com>
Wed, 27 Sep 2017 07:15:00 +0000 (09:15 +0200)
include/deal.II/lac/lapack_full_matrix.h
source/lac/lapack_full_matrix.cc

index 593794810bed34be22ba76c5a97b89d01e42c5cf..6bf20a3a8f52c4f09857c867373336b8b10a09c5 100644 (file)
@@ -22,6 +22,7 @@
 #include <deal.II/base/table.h>
 #include <deal.II/lac/lapack_support.h>
 #include <deal.II/lac/vector_memory.h>
+#include <deal.II/base/thread_management.h>
 
 #include <memory>
 #include <vector>
@@ -672,6 +673,11 @@ private:
    */
   mutable std::vector<number> work;
 
+  /**
+   * Integer working array used for some LAPACK functions.
+   */
+  mutable std::vector<int> iwork;
+
   /**
    * The vector storing the permutations applied for pivoting in the LU-
    * factorization.
@@ -717,6 +723,11 @@ private:
    * <i>USV<sup>T</sup></i>.
    */
   std::shared_ptr<LAPACKFullMatrix<number> > svd_vt;
+
+  /**
+   * Thread mutex.
+   */
+  mutable Threads::Mutex mutex;
 };
 
 
index 763daac138aa40bab95e6293fdab2cd7eb29e51b..28961749ad4224237143e13233d570ed8ba9f1f2 100644 (file)
@@ -178,6 +178,8 @@ LAPACKFullMatrix<number>::vmult (
   const Vector<number> &v,
   const bool            adding) const
 {
+  Threads::Mutex::ScopedLock lock (mutex);
+
   const int mm = this->n_rows();
   const int nn = this->n_cols();
   const number alpha = 1.;
@@ -236,6 +238,8 @@ LAPACKFullMatrix<number>::Tvmult (
   const Vector<number> &v,
   const bool            adding) const
 {
+  Threads::Mutex::ScopedLock lock (mutex);
+
   const int mm = this->n_rows();
   const int nn = this->n_cols();
   const number alpha = 1.;
@@ -560,6 +564,8 @@ number LAPACKFullMatrix<number>::frobenius_norm() const
 template <typename number>
 number LAPACKFullMatrix<number>::norm(const char type) const
 {
+  Threads::Mutex::ScopedLock lock (mutex);
+
   Assert (state == LAPACKSupport::matrix ||
           state == LAPACKSupport::inverse_matrix,
           ExcMessage("norms can be called in matrix state only."));
@@ -567,15 +573,14 @@ number LAPACKFullMatrix<number>::norm(const char type) const
   const int N = this->n_cols();
   const int M = this->n_rows();
   const number *values = &this->values[0];
-  std::vector<number> w;
   if (property == symmetric)
     {
       const int lda = std::max(1,N);
       const int lwork = (type == 'I' || type == 'O') ?
                         std::max(1,N) :
                         0;
-      w.resize(lwork);
-      return lansy (&type, &LAPACKSupport::L, &N, values, &lda, &w[0]);
+      work.resize(lwork);
+      return lansy (&type, &LAPACKSupport::L, &N, values, &lda, &work[0]);
     }
   else
     {
@@ -583,8 +588,8 @@ number LAPACKFullMatrix<number>::norm(const char type) const
       const int lwork = (type == 'I') ?
                         std::max(1,M) :
                         0;
-      w.resize(lwork);
-      return lange (&type, &M, &N, values, &lda, &w[0]);
+      work.resize(lwork);
+      return lange (&type, &M, &N, values, &lda, &work[0]);
     }
 }
 
@@ -619,6 +624,7 @@ template <typename number>
 number
 LAPACKFullMatrix<number>::reciprocal_condition_number(const number a_norm) const
 {
+  Threads::Mutex::ScopedLock lock (mutex);
   Assert(state == cholesky, ExcState(state));
   number rcond = 0.;
 
@@ -626,13 +632,13 @@ LAPACKFullMatrix<number>::reciprocal_condition_number(const number a_norm) const
   const number *values = &this->values[0];
   int info = 0;
   const int lda = std::max(1,N);
-  std::vector<number> w(3*N);
-  std::vector<int> iw(N);
+  work.resize(3*N);
+  iwork.resize(N);
 
   // use the same uplo as in Cholesky
   pocon (&LAPACKSupport::L, &N, values, &lda,
          &a_norm, &rcond,
-         &w[0], &iw[0], &info);
+         &work[0], &iwork[0], &info);
 
   Assert(info >= 0, ExcInternalError());
 
@@ -1002,7 +1008,7 @@ LAPACKFullMatrix<number>::compute_generalized_eigenvalues_symmetric(
   const char *const uplo(&U);
   const char *const range(&V);
   const int *const  dummy(&one);
-  std::vector<int> iwork(static_cast<size_type> (5*nn));
+  iwork.resize(static_cast<size_type> (5*nn));
   std::vector<int> ifail(static_cast<size_type> (nn));
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.