From: Wolfgang Bangerth Date: Wed, 14 Nov 2001 18:01:04 +0000 (+0000) Subject: Provide external lock. X-Git-Tag: v8.0.0~18622 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=873d7c707eb53c292c2b0ca11f8aa7d79d1ee4f7;p=dealii.git Provide external lock. git-svn-id: https://svn.dealii.org/trunk@5206 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/sparse_direct.h b/deal.II/lac/include/lac/sparse_direct.h index 1d459d9934..494be4d3b5 100644 --- a/deal.II/lac/include/lac/sparse_direct.h +++ b/deal.II/lac/include/lac/sparse_direct.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include @@ -104,7 +105,20 @@ * active. You have to synchronise your calls to the functions * provided by this class using mutexes (see the @ref{Threads} * namespace for such classes) to avoid multiple active calls at the - * same time if you use multithreading. + * same time if you use multithreading. Since you may use this class + * in different parts of your program, and may not want to use a + * global variable for locking, this class has a lock as static member + * variable, which may be accessed using the + * @p{get_synchronisation_lock} function. Note however, that this + * class does not perform the synchronisation for you within its + * member functions. The reason is that you will usually want to + * synchronise over the calls to @p{initialize} and @p{factorize}, + * since there should probably not be a call to one of these function + * with another matrix between the calls for one matrix. (The author + * does not really know whether this is true, but it is probably safe + * to assume that.) Since such cross-function synchronisation can only + * be performed from outside, it is left to the user of this class to + * do so. * * @author Wolfgang Bangerth, 2000, 2001 */ @@ -211,6 +225,16 @@ class SparseDirectMA27 : public Subscriptor */ unsigned int memory_consumption () const; + /** + * Get a reference to the + * synchronisation lock which can + * be used for this class. See + * the general description of + * this class for more + * information. + */ + Threads::ThreadMutex & get_synchronisation_lock () const; + /** * Exception. */ @@ -341,6 +365,12 @@ class SparseDirectMA27 : public Subscriptor */ int IFLAG; + /** + * Mutex for synchronising access + * to this class. + */ + static Threads::ThreadMutex synchronisation_lock; + /** * Fill the @p{A} array from the * symmetric part of the given @@ -400,7 +430,20 @@ class SparseDirectMA27 : public Subscriptor * active. You have to synchronise your calls to the functions * provided by this class using mutexes (see the @ref{Threads} * namespace for such classes) to avoid multiple active calls at the - * same time if you use multithreading. + * same time if you use multithreading. Since you may use this class + * in different parts of your program, and may not want to use a + * global variable for locking, this class has a lock as static member + * variable, which may be accessed using the + * @p{get_synchronisation_lock} function. Note however, that this + * class does not perform the synchronisation for you within its + * member functions. The reason is that you will usually want to + * synchronise over the calls to @p{initialize} and @p{factorize}, + * since there should probably not be a call to one of these function + * with another matrix between the calls for one matrix. (The author + * does not really know whether this is true, but it is probably safe + * to assume that.) Since such cross-function synchronisation can only + * be performed from outside, it is left to the user of this class to + * do so. * * @author Wolfgang Bangerth, 2000, 2001 */ @@ -517,6 +560,16 @@ class SparseDirectMA47 : public Subscriptor */ unsigned int memory_consumption () const; + /** + * Get a reference to the + * synchronisation lock which can + * be used for this class. See + * the general description of + * this class for more + * information. + */ + Threads::ThreadMutex & get_synchronisation_lock () const; + /** * Exception. */ @@ -640,6 +693,12 @@ class SparseDirectMA47 : public Subscriptor std::vector KEEP; std::vector IW1; + /** + * Mutex for synchronising access + * to this class. + */ + static Threads::ThreadMutex synchronisation_lock; + /** * Fill the @p{A} array from the * symmetric part of the given diff --git a/deal.II/lac/source/sparse_direct.cc b/deal.II/lac/source/sparse_direct.cc index b91f9cf41a..822196c27c 100644 --- a/deal.II/lac/source/sparse_direct.cc +++ b/deal.II/lac/source/sparse_direct.cc @@ -195,6 +195,9 @@ namespace HSL /* -------------------------- MA27 ---------------------------- */ +Threads::ThreadMutex SparseDirectMA27::synchronisation_lock; + + SparseDirectMA27::SparseDirectMA27 (const double LIW_factor_1, const double LIW_factor_2, const double LA_factor, @@ -503,6 +506,14 @@ SparseDirectMA27::memory_consumption () const +Threads::ThreadMutex & +SparseDirectMA27::get_synchronisation_lock () const +{ + return synchronisation_lock; +}; + + + void SparseDirectMA27::fill_A (const SparseMatrix &matrix) { @@ -535,7 +546,7 @@ SparseDirectMA27::fill_A (const SparseMatrix &matrix) /* -------------------------- MA47 ---------------------------- */ - +Threads::ThreadMutex SparseDirectMA47::synchronisation_lock; SparseDirectMA47::SparseDirectMA47 (const double LIW_factor_1, @@ -832,6 +843,14 @@ SparseDirectMA47::memory_consumption () const +Threads::ThreadMutex & +SparseDirectMA47::get_synchronisation_lock () const +{ + return synchronisation_lock; +}; + + + void SparseDirectMA47::fill_A (const SparseMatrix &matrix) {