]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Support POSIX threads, as an alternative to ACE.
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 30 Apr 2002 08:30:07 +0000 (08:30 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 30 Apr 2002 08:30:07 +0000 (08:30 +0000)
git-svn-id: https://svn.dealii.org/trunk@5759 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/aclocal.m4
deal.II/base/include/base/config.h.in
deal.II/base/include/base/thread_management.h
deal.II/base/source/thread_management.cc
deal.II/common/Make.global_options.in
deal.II/configure
deal.II/configure.in
deal.II/doc/news/2002/c-3-3.html
deal.II/doc/news/news.html
deal.II/doc/readme.html

index 84868de57f7f1ce16acc23dafff31e7b8ecefc5b..600c85f92c4be6b727ae802bc8d22b61ed40eab3 100644 (file)
@@ -697,6 +697,7 @@ dnl compiler flags to use:
 dnl - Use the right -threads/-pthread/-mthread option
 dnl - Set preprocessor directives if necessary
 dnl - __USE_MALLOC tells gcc to use thread safe STL allocators
+dnl   (don't use this for gcc3.1 or later)
 dnl - _REENTRANT is a flag that is used in the standard UNIX
 dnl   headers to make reentrant functions (with suffix _r) declared
 dnl
@@ -718,8 +719,12 @@ AC_DEFUN(DEAL_II_SET_MULTITHREADING_FLAGS, dnl
       DEAL_II_GET_THREAD_FLAGS
       DEAL_II_THREAD_CPPFLAGS
   
-      CXXFLAGSG="$CXXFLAGSG -D__USE_MALLOC -D_REENTRANT"
-      CXXFLAGSO="$CXXFLAGSO -D__USE_MALLOC -D_REENTRANT"
+      CXXFLAGSG="$CXXFLAGSG -D_REENTRANT"
+      CXXFLAGSO="$CXXFLAGSO -D_REENTRANT"
+      if test "$GXX_VERSION" = "gcc2.95" -o "$GXX_VERSION" = "gcc3.0" ; then
+        CXXFLAGSG="$CXXFLAGSG -D__USE_MALLOC"
+        CXXFLAGSO="$CXXFLAGSO -D__USE_MALLOC"
+      fi
     else
       if test "x$GXX_VERSION" = "xibm_xlc" ; then
         CXXFLAGSG = "$CXXFLAGSG -threaded"  
@@ -737,36 +742,134 @@ AC_DEFUN(DEAL_II_SET_MULTITHREADING_FLAGS, dnl
 
 
 dnl -------------------------------------------------------------
-dnl Test whether MT code shall be used through ACE. If so, set
-dnl $withmultithreading to the path to ACE
+dnl Test which library the MT code shall use to support threads.
+dnl We support either POSIX or ACE. If requested, then set
+dnl $withmultithreading to either POSIX or to the path to ACE.
 dnl
 dnl Usage:
-dnl   DEAL_II_CHECK_USE_ACE
+dnl   DEAL_II_CHECK_USE_MT
 dnl
 dnl -------------------------------------------------------------
-AC_DEFUN(DEAL_II_CHECK_USE_ACE, dnl
+AC_DEFUN(DEAL_II_CHECK_USE_MT, dnl
 [
   AC_ARG_WITH(multithreading,
-  [  --with-multithreading=DIR use DIR as path to the ACE library],
+  [  --with-multithreading=name If name==posix, then use POSIX threads,
+                                otherwise assume use of ACE and use given
+                                argument as path to ACE],
       withmultithreading=$withval,
       withmultithreading=no)
-  if test "$withmultithreading" != no ; then
-    AC_MSG_CHECKING(for ACE)
-    if test -d "$withmultithreading" ; then
-      AC_MSG_RESULT(found)
+
+dnl Default (i.e. no arg) means POSIX
+  if test "x$withmultithreading" = "xyes" ; then
+    withmultithreading=posix
+  fi
+
+  if test "x$withmultithreading" != "xno" ; then
+    if test "x$withmultithreading" = "xposix" ; then
+      DEAL_II_CHECK_POSIX_THREAD_FUNCTIONS
+      AC_DEFINE(DEAL_II_USE_MT_POSIX, 1,
+                [Defined if multi-threading is to be achieved by using
+                 the POSIX functions])
     else
-      AC_MSG_RESULT(not found)
-      AC_MSG_ERROR(Invalid ACE path)
+      AC_MSG_CHECKING(for ACE)
+      if test -d "$withmultithreading" ; then
+        AC_MSG_RESULT(found)
+      else
+        AC_MSG_RESULT(not found)
+        AC_MSG_ERROR(Invalid ACE path)
+      fi
+      AC_DEFINE(DEAL_II_USE_MT_ACE, 1,
+                [Defined if multi-threading is to be achieved by using
+                 the ACE library])
+      DEAL_II_SET_ACE_FLAGS
     fi
   
     AC_DEFINE(DEAL_II_USE_MT, 1, 
-              [Flag indicating whether the library shall be compiler for
+              [Flag indicating whether the library shall be compiled for
                multithreaded applications])
   fi
 ])
 
 
 
+dnl -------------------------------------------------------------
+dnl Check whether the POSIX functions needed for multi-threading
+dnl are available on this system
+dnl 
+dnl Usage: DEAL_II_CHECK_POSIX_THREAD_FUNCTIONS
+dnl
+dnl -------------------------------------------------------------
+AC_DEFUN(DEAL_II_CHECK_POSIX_THREAD_FUNCTIONS, dnl
+[
+  AC_MSG_CHECKING(for posix thread functions)
+  AC_LANG(C++)
+  AC_TRY_COMPILE(
+   [
+#      include <pthread.h>
+   ],
+   [
+       pthread_t         p;
+       pthread_create (&p, 0, 0, 0);
+       pthread_join (&p, 0);
+   ],
+   [
+       AC_MSG_RESULT(ok)
+   ],
+   [
+       AC_MSG_ERROR(not found)
+   ])
+
+  AC_MSG_CHECKING(for posix thread mutex functions)
+  AC_LANG(C++)
+  AC_TRY_COMPILE(
+   [
+#      include <pthread.h>
+   ],
+   [
+       pthread_mutex_t   pm;
+       pthread_mutex_init (&pm, 0);
+       pthread_mutex_lock (&pm);
+       pthread_mutex_unlock (&pm);
+       pthread_mutex_destroy (&pm);
+   ],
+   [
+       AC_MSG_RESULT(ok)
+   ],
+   [
+       AC_MSG_ERROR(not found)
+   ])
+
+  AC_MSG_CHECKING(for posix thread barrier functions)
+  AC_LANG(C++)
+  AC_TRY_COMPILE(
+   [
+#      include <pthread.h>
+   ],
+   [
+       pthread_barrier_t pb;
+       pthread_barrier_init (&pb, 0, 1);
+       pthread_barrier_wait (&pb);
+       pthread_barrier_destroy (&pb);
+   ],
+   [
+       AC_MSG_RESULT(ok)
+       x=0
+   ],
+   [
+       AC_MSG_RESULT(not found. barriers will not be supported)
+       x=1
+   ])
+   if test "x$x" = "x1" ; then
+     AC_DEFINE(DEAL_II_USE_MT_POSIX_NO_BARRIERS, 1,
+              [Defined if POSIX is supported but not the newer POSIX
+                barrier functions. Barriers will then not work in
+                the library, but the other threading functionality
+                is available.])
+  fi
+])
+
+
+
 dnl -------------------------------------------------------------
 dnl If the MT code shall be used through ACE, we might have to 
 dnl adjust the compiler flags: Possibly remove -pedantic from
index bd3541c71d3aa74a1b30c7e38eb106a63879a71f..62b33b6b254951e968be2d4fa1241e98d4d80f4a 100644 (file)
    description of this bug. */
 #undef DEAL_II_TEMPL_CONST_MEM_PTR_BUG
 
-/* Flag indicating whether the library shall be compiler for multithreaded
+/* Flag indicating whether the library shall be compiled for multithreaded
    applications */
 #undef DEAL_II_USE_MT
 
+/* Defined if multi-threading is to be achieved by using the ACE library */
+#undef DEAL_II_USE_MT_ACE
+
+/* Defined if multi-threading is to be achieved by using the POSIX functions
+   */
+#undef DEAL_II_USE_MT_POSIX
+
+/* Defined if POSIX is supported but not the newer POSIX barrier functions.
+   Barriers will then not work in the library, but the other threading
+   functionality is available. */
+#undef DEAL_II_USE_MT_POSIX_NO_BARRIERS
+
 /* Enable the multigrid components of the library */
 #undef ENABLE_MULTIGRID
 
index 58dcd1b6be64b1e5c8a3e90b917c893327e49cee..b50cd44ec90f894e3cabcaddd074d549fe7be753 100644 (file)
 #include <iterator>
 
 #ifdef DEAL_II_USE_MT
-#  include <ace/Thread_Manager.h>
-#  include <ace/Synch.h>
+#  if defined(DEAL_II_USE_MT_ACE)
+#    include <ace/Thread_Manager.h>
+#    include <ace/Synch.h>
+#  elif defined(DEAL_II_USE_MT_POSIX)
+#    include <pthread.h>
+#  endif
 #endif
 
 
@@ -179,17 +183,193 @@ namespace Threads
   
   
 #ifdef DEAL_II_USE_MT
+#  if defined(DEAL_II_USE_MT_ACE)
                                   /**
-                                   * In multithread mode, we alias
-                                   * the mutex and thread management
-                                   * classes to the respective
-                                   * classes of the ACE
+                                   * In multithread mode with ACE
+                                   * enabled, we alias the mutex and
+                                   * thread management classes to the
+                                   * respective classes of the ACE
                                    * library. Likewise for the
                                    * barrier class.
                                    */
   typedef ACE_Thread_Mutex   ThreadMutex;
   typedef ACE_Thread_Manager ThreadManager;
   typedef ACE_Barrier        Barrier;
+  
+#  elif defined(DEAL_II_USE_MT_POSIX)
+
+                                  /**
+                                   * Class implementing a Mutex with
+                                   * the help of POSIX functions.
+                                   *
+                                   * @author Wolfgang Bangerth, 2002
+                                   */
+  class PosixThreadMutex 
+  {
+    public:
+                                      /**
+                                       * Constructor. Initialize the
+                                       * underlying POSIX mutex data
+                                       * structure.
+                                       */
+      PosixThreadMutex ();
+
+                                      /**
+                                       * Destructor. Release all
+                                       * resources.
+                                       */
+      ~PosixThreadMutex ();
+      
+                                      /**
+                                       * Acquire a mutex.
+                                       */
+      inline void acquire () { pthread_mutex_lock(&mutex); };
+
+                                      /**
+                                       * Release the mutex again.
+                                       */
+      inline void release () { pthread_mutex_unlock(&mutex); };
+
+    private:
+                                      /**
+                                       * Data object storing the
+                                       * POSIX data which we need to
+                                       * call the POSIX functions.
+                                       */
+      pthread_mutex_t mutex;
+  };
+
+
+                                  /**
+                                   * Implementation of a thread
+                                   * barrier class, based on the
+                                   * POSIX thread functions. POSIX
+                                   * barriers are a relatively new
+                                   * feature and are not supported on
+                                   * all systems. If the
+                                   * configuration detected the
+                                   * absence of these functions, then
+                                   * barriers will not be available,
+                                   * and using this class will result
+                                   * in an exception been thrown. The
+                                   * rest of the threading
+                                   * functionality will be available,
+                                   * though.
+                                   *
+                                   * @author Wolfgang Bangerth, 2002
+                                   */
+  class PosixThreadBarrier 
+  {
+    public:
+                                      /**
+                                       * Constructor. Initialize the
+                                       * underlying POSIX barrier data
+                                       * structure.
+                                       */
+      PosixThreadBarrier (const unsigned int  count,
+                         const char         *name = 0,
+                         void               *arg  = 0);
+
+                                      /**
+                                       * Destructor. Release all
+                                       * resources.
+                                       */
+      ~PosixThreadBarrier ();      
+
+                                      /**
+                                       * Wait for all threads to
+                                       * reach this point. The return
+                                       * value is zero for all
+                                       * participating threads except
+                                       * for one, for which the
+                                       * return value is some
+                                       * non-zero value. The
+                                       * operating system picks the
+                                       * special thread by some not
+                                       * further known method.
+                                       */
+      int wait ();
+
+    private:
+                                      /**
+                                       * Data object storing the
+                                       * POSIX data which we need to
+                                       * call the POSIX functions.
+                                       */
+#ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS
+      pthread_barrier_t barrier;
+#endif
+  };
+
+
+  class PosixThreadManager 
+  {
+    public:
+                                      /**
+                                       * Typedef for a global
+                                       * function that might be
+                                       * called on a new thread.
+                                       */
+      typedef void * (*FunPtr) (void *);
+
+                                      /**
+                                       * Constructor. Initialize data
+                                       * structures.
+                                       */
+      PosixThreadManager ();
+
+                                      /**
+                                       * Destructor. Wait for all
+                                       * spawned threads if they have
+                                       * not yet finished, and
+                                       * release the resources of
+                                       * this object.
+                                       */
+      ~PosixThreadManager ();
+      
+                                      /**
+                                       * Spawn a new thread and
+                                       * calling the passed function
+                                       * thereon. Store the
+                                       * identifier of the thread for
+                                       * later operations as waiting
+                                       * for that thread.
+                                       *
+                                       * The @p{flags} argument is
+                                       * currently ignored.
+                                       */
+      void spawn (const FunPtr fun_ptr,
+                 void *       fun_data,
+                 int          flags);
+
+                                      /**
+                                       * Wait for all spawned threads
+                                       * to return.
+                                       */
+      void wait () const;
+
+    private:
+                                      /**
+                                       * List of thread ids. This
+                                       * variable actually points to
+                                       * an object of type
+                                       * @p{std::list<pthread_t>},
+                                       * but to avoid including
+                                       * @p{<list>} into this central
+                                       * header file and all other
+                                       * files including it, we use a
+                                       * void pointer instead.
+                                       */
+      void * const thread_id_list;
+  };
+  
+  
+  
+  typedef PosixThreadMutex   ThreadMutex;
+  typedef PosixThreadManager ThreadManager;
+  typedef PosixThreadBarrier Barrier;
+  
+#  endif
 #else
                                   /**
                                    * In non-multithread mode, the
index 5add51f3d0fcd4da3e2fdf69c516c254c65005ff..5dfe7811b49b5fd427deed5eb99e980aa43e55b3 100644 (file)
 
 
 #include <base/thread_management.h>
-
+#ifdef DEAL_II_USE_MT_POSIX
+#  include <list>
+#endif
 
 
 namespace Threads 
 {
+#ifndef DEAL_II_USE_MT
   void DummyThreadManager::spawn (const FunPtr fun_ptr,
                                  void *       fun_data,
                                  int          /*flags*/) const
@@ -34,7 +37,110 @@ namespace Threads
     Assert (count == 1, ExcBarrierSizeNotUseful(count));
   };
 
+
+#else
+#  ifdef DEAL_II_USE_MT_POSIX
+
+  PosixThreadMutex::PosixThreadMutex ()
+  {
+    pthread_mutex_init (&mutex, 0);
+  };
+
+
+
+  PosixThreadMutex::~PosixThreadMutex ()
+  {
+    pthread_mutex_destroy (&mutex);
+  };
+  
+
+  PosixThreadBarrier::PosixThreadBarrier (const unsigned int  count,
+                                         const char         *,
+                                         void               *)
+  {
+#ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS    
+    pthread_barrier_init (&barrier, 0, count);
+#else
+    AssertThrow (false,
+                ExcMessage ("Your local POSIX installation does not support\n"
+                            "POSIX barriers. You will not be able to use\n"
+                            "this class, but the rest of the threading\n"
+                            "functionality is available."));
+#endif
+  };
+
+
+
+  PosixThreadBarrier::~PosixThreadBarrier ()
+  {
+#ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS
+    pthread_barrier_destroy (&barrier);
+#else
+    abort ();
+#endif
+  };
+
+
+
+  int
+  PosixThreadBarrier::wait ()
+  {
+#ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS    
+    return pthread_barrier_wait (&barrier);
+#else
+    abort ();
+#endif
+  };
+  
+
+
+  PosixThreadManager::PosixThreadManager ()
+                 :
+                 thread_id_list (new std::list<pthread_t>())
+  {};
+
+
+  PosixThreadManager::~PosixThreadManager ()
+  {
+                                    // wait for all threads, and
+                                    // release memory
+    wait ();
+    delete reinterpret_cast<std::list<pthread_t>*>(thread_id_list);
+  };
+
+
+
+  void
+  PosixThreadManager::spawn (const FunPtr fun_ptr,
+                            void *       fun_data,
+                            int)
+  {
+    std::list<pthread_t> &tid_list
+      = *reinterpret_cast<std::list<pthread_t>*>(thread_id_list);
+
+    tid_list.push_back (pthread_t());
+
+    const int error
+      = pthread_create (&tid_list.back(), 0, fun_ptr, fun_data);
+
+    Assert (error == 0, ExcInternalError());
+  };
+  
+
+
+  void
+  PosixThreadManager::wait () const
+  {
+    std::list<pthread_t> &tid_list
+      = *reinterpret_cast<std::list<pthread_t>*>(thread_id_list);
+
+    for (std::list<pthread_t>::iterator i=tid_list.begin();
+        i != tid_list.end(); ++i)
+      pthread_join (tid_list.back(), 0);
+  };
   
+#  endif
+#endif  
   
   FunDataCounter::FunDataCounter () :
                  n_fun_encapsulation_objects (0),
@@ -166,9 +272,15 @@ namespace Threads
     fun_data.fun_data_base->lock.acquire ();
                                     // now start the new thread
 #ifdef DEAL_II_USE_MT
+#  if defined(DEAL_II_USE_MT_ACE)
     thread_manager.spawn (*fun_data.fun_data_base->thread_entry_point,
                          (void*)&fun_data,
                          THR_SCOPE_SYSTEM | THR_DETACHED);
+#  elif defined(DEAL_II_USE_MT_POSIX)
+    thread_manager.spawn (*fun_data.fun_data_base->thread_entry_point,
+                         (void*)&fun_data,
+                         0);    
+#  endif    
 #else
     thread_manager.spawn (*fun_data.fun_data_base->thread_entry_point,
                          (void*)&fun_data,
index eb682eb4e4733bb28dee55c5e62ef5dfe9565b9b..98b9d30787be06561a8c579810f52116ad39776d 100644 (file)
@@ -125,12 +125,14 @@ endif
 # if multithread support in the library is requested, then set the
 # respective flags
 ifneq ($(with-multithreading),no)
-  ACE_ROOT    = $(with-multithreading)
-  INCLUDE    += -I$(ACE_ROOT)
-  LIBPATH    += -L$(ACE_ROOT)/ace
+  ifneq ($(with-multithreading),posix)
+    ACE_ROOT    = $(with-multithreading)
+    INCLUDE    += -I$(ACE_ROOT)
+    LIBPATH    += -L$(ACE_ROOT)/ace
 
-  lib-ACE     = $(ACE_ROOT)/ace/libACE.so
-  LIBS       += $(lib-ACE)
+    lib-ACE     = $(ACE_ROOT)/ace/libACE.so
+    LIBS       += $(lib-ACE)
 
-  vpath %.a $(ACE_ROOT)
+    vpath %.a $(ACE_ROOT)
+  endif
 endif
index 31a0ae53b92f7e485ab9b48531740d323c81896d..1ea1e7518b44932cddb10b0a6aaf55cd8d4969da 100755 (executable)
@@ -820,7 +820,9 @@ Optional Features:
 Optional Packages:
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
-  --with-multithreading=DIR use DIR as path to the ACE library
+  --with-multithreading=name If name==posix, then use POSIX threads,
+                                otherwise assume use of ACE and use given
+                                argument as path to ACE
   --with-kdoc=DIR use kdoc installed in DIR
   --with-docxx=PATH use the doc++ executable pointed to by PATH
 
@@ -3097,8 +3099,15 @@ fi
 rm -f conftest.$ac_objext conftest.$ac_ext
 
 
-      CXXFLAGSG="$CXXFLAGSG -D__USE_MALLOC -D_REENTRANT"
-      CXXFLAGSO="$CXXFLAGSO -D__USE_MALLOC -D_REENTRANT"
+      CXXFLAGSG="$CXXFLAGSG -D_REENTRANT"
+      CXXFLAGSO="$CXXFLAGSO -D_REENTRANT"
+       echo xxxxxxxxxxxxxxxxxxxxxxxxx $GXX_VERSION
+      if test "$GXX_VERSION" = "gcc2.95" -o "$GXX_VERSION" = "gcc3.0" ; then
+       echo xxxxxxxxxxxxxxxxxxxxxxxxx
+        CXXFLAGSG="$CXXFLAGSG -D__USE_MALLOC"
+        CXXFLAGSO="$CXXFLAGSO -D__USE_MALLOC"
+      fi
+       echo xxxxxxxxxxxxxxxxxxxxxxxxx
     else
       if test "x$GXX_VERSION" = "xibm_xlc" ; then
         CXXFLAGSG = "$CXXFLAGSG -threaded"
@@ -3125,27 +3134,225 @@ if test "${with_multithreading+set}" = set; then
 else
   withmultithreading=no
 fi;
-  if test "$withmultithreading" != no ; then
-    echo "$as_me:$LINENO: checking for ACE" >&5
+
+  if test "x$withmultithreading" = "xyes" ; then
+    withmultithreading=posix
+  fi
+
+  if test "x$withmultithreading" != "xno" ; then
+    if test "x$withmultithreading" = "xposix" ; then
+
+  echo "$as_me:$LINENO: checking for posix thread functions" >&5
+echo $ECHO_N "checking for posix thread functions... $ECHO_C" >&6
+  ac_ext=cc
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#      include <pthread.h>
+
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+       pthread_t         p;
+       pthread_create (&p, 0, 0, 0);
+       pthread_join (&p, 0);
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+       echo "$as_me:$LINENO: result: ok" >&5
+echo "${ECHO_T}ok" >&6
+
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+
+       { { echo "$as_me:$LINENO: error: not found" >&5
+echo "$as_me: error: not found" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+
+  echo "$as_me:$LINENO: checking for posix thread mutex functions" >&5
+echo $ECHO_N "checking for posix thread mutex functions... $ECHO_C" >&6
+  ac_ext=cc
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#      include <pthread.h>
+
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+       pthread_mutex_t   pm;
+       pthread_mutex_init (&pm, 0);
+       pthread_mutex_lock (&pm);
+       pthread_mutex_unlock (&pm);
+       pthread_mutex_destroy (&pm);
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+       echo "$as_me:$LINENO: result: ok" >&5
+echo "${ECHO_T}ok" >&6
+
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+
+       { { echo "$as_me:$LINENO: error: not found" >&5
+echo "$as_me: error: not found" >&2;}
+   { (exit 1); exit 1; }; }
+
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+
+  echo "$as_me:$LINENO: checking for posix thread barrier functions" >&5
+echo $ECHO_N "checking for posix thread barrier functions... $ECHO_C" >&6
+  ac_ext=cc
+ac_cpp='$CXXCPP $CPPFLAGS'
+ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
+ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
+ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
+
+  cat >conftest.$ac_ext <<_ACEOF
+#line $LINENO "configure"
+#include "confdefs.h"
+
+#      include <pthread.h>
+
+#ifdef F77_DUMMY_MAIN
+#  ifdef __cplusplus
+     extern "C"
+#  endif
+   int F77_DUMMY_MAIN() { return 1; }
+#endif
+int
+main ()
+{
+
+       pthread_barrier_t pb;
+       pthread_barrier_init (&pb, 0, 1);
+       pthread_barrier_wait (&pb);
+       pthread_barrier_destroy (&pb);
+
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext
+if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
+  (eval $ac_compile) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } &&
+         { ac_try='test -s conftest.$ac_objext'
+  { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5
+  (eval $ac_try) 2>&5
+  ac_status=$?
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); }; }; then
+
+       echo "$as_me:$LINENO: result: ok" >&5
+echo "${ECHO_T}ok" >&6
+       x=0
+
+else
+  echo "$as_me: failed program was:" >&5
+cat conftest.$ac_ext >&5
+
+       echo "$as_me:$LINENO: result: not found. barriers will not be supported" >&5
+echo "${ECHO_T}not found. barriers will not be supported" >&6
+       x=1
+
+fi
+rm -f conftest.$ac_objext conftest.$ac_ext
+   if test "x$x" = "x1" ; then
+
+cat >>confdefs.h <<\_ACEOF
+#define DEAL_II_USE_MT_POSIX_NO_BARRIERS 1
+_ACEOF
+
+  fi
+
+
+cat >>confdefs.h <<\_ACEOF
+#define DEAL_II_USE_MT_POSIX 1
+_ACEOF
+
+    else
+      echo "$as_me:$LINENO: checking for ACE" >&5
 echo $ECHO_N "checking for ACE... $ECHO_C" >&6
-    if test -d "$withmultithreading" ; then
-      echo "$as_me:$LINENO: result: found" >&5
+      if test -d "$withmultithreading" ; then
+        echo "$as_me:$LINENO: result: found" >&5
 echo "${ECHO_T}found" >&6
-    else
-      echo "$as_me:$LINENO: result: not found" >&5
+      else
+        echo "$as_me:$LINENO: result: not found" >&5
 echo "${ECHO_T}not found" >&6
-      { { echo "$as_me:$LINENO: error: Invalid ACE path" >&5
+        { { echo "$as_me:$LINENO: error: Invalid ACE path" >&5
 echo "$as_me: error: Invalid ACE path" >&2;}
    { (exit 1); exit 1; }; }
-    fi
-
+      fi
 
 cat >>confdefs.h <<\_ACEOF
-#define DEAL_II_USE_MT 1
+#define DEAL_II_USE_MT_ACE 1
 _ACEOF
 
-  fi
-
 
   if test "$enablemultithreading" = yes ; then
     if test "$GXX" = yes ; then
@@ -3219,6 +3426,15 @@ echo "${ECHO_T}-pedantic" >&6
     fi
   fi
 
+    fi
+
+
+cat >>confdefs.h <<\_ACEOF
+#define DEAL_II_USE_MT 1
+_ACEOF
+
+  fi
+
 
 
 
index e9c4619214f29a8361f7f41162b2273c0c09aaf6..e9cb71e4185df19602c2b3b0dfd21ea92c5e020f 100644 (file)
@@ -127,9 +127,9 @@ DEAL_II_CHECK_MULTITHREADING
 DEAL_II_SET_MULTITHREADING_FLAGS
 AC_SUBST(enablemultithreading)
 
-dnl Next also check whether the MT code shall be used through ACE
-DEAL_II_CHECK_USE_ACE
-DEAL_II_SET_ACE_FLAGS
+dnl Next also check whether the MT code shall be used through 
+dnl POSIX or ACE
+DEAL_II_CHECK_USE_MT
 AC_SUBST(withmultithreading)
 
 
index f5f8d5594fa12c9560f31780487e153efa1da86a..27d25fc33f78ee77922600b84c65efc030d4664b 100644 (file)
@@ -34,7 +34,22 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
 
 <ol>
   <li> <p> 
+       New: In all previous versions, <acronym>deal.II</acronym> used
+       the <a href="http://www.cs.wustl.edu/~schmidt/ACE.html"
+       target="_top">ACE (Adaptive Communications Environment)</a>
+       library to support cross-platform threading
+       facilities. While this is still supported, the default way
+       is now to use the POSIX threading functions that are
+       available on many systems. The relieves you from the need of
+       installing a huge library of which the most part is not used
+       anyway. However, if you use ACE for other reasons, then it is
+       still supported. For installation instructions, see the 
+       <a href="../../readme.html" target="body">ReadMe</a> file.
+       <br>
+       (WB 2002/04/30)
+       </p>
 
+  <li> <p> 
        Changed: The Makefiles for the library are now truly
        parallel. To this end, the automatic generation of the files
        <tt>forward_declarations.h</tt> in the various directories had
@@ -44,7 +59,8 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
        single library. In this case, <tt>make forward</tt> can be used
        to build them manually.
        <br>
-       I introduced separate targets for the generation of the optimized versions only.
+       I introduced separate targets for the generation of the
+       optimized versions only.
        <br>
        (GK 2002/04/17)
        </p>
index 9962db0cb39a0782eff878caa5d384fb03376202..3a610fc9262e9452f63e39307b099d09d08a5325 100644 (file)
 
     <dir>
     <dl>
+      <dt>
+          <strong>2004/04/30: Multi-threading support using POSIX</strong>
+      </dt>
+      <dd>
+          In all previous versions, <acronym>deal.II</acronym> used
+          the <a href="http://www.cs.wustl.edu/~schmidt/ACE.html"
+         target="_top">ACE (Adaptive Communications Environment)</a>
+         library to support cross-platform threading
+          facilities. While this is still supported, the default way
+          is now to use the POSIX threading functions that are
+          available on many systems.
+         </p>
+      </dd>
+
       <dt>
           <strong>2004/04/16: New example program showing
           software design practices for finite element programs</strong>
index b8233fa6a3ff93e1b604f075fde974e21869bb1d..1b335ebe9e75dd72270b13bfb7071e3c6f919bfe 100644 (file)
       <p>
       <code>--enable-multithreading</code>: This sets compiler
       variables such that the resulting program supports
-      multi-threading. Basically, for this different system include
+      multi-threading. Basically, for this, different system include
       files have to be selected (gcc option -threads) and memory
       allocation has to be made thread-safe; the latter can be done
       for the C++ standard containers by defining
-      <code>-D__USE_MALLOC</code>. Note that not all parts of the
-      deal.II library are fully thread-safe (though most are and
-      multi-threaded programs are working well and routinely) and that
-      gcc's runtime library is not thread-safe unless you configure gcc
-      with <code>--enable-threads</code> and recompile it. Using a gcc
+      <code>-D__USE_MALLOC</code>. Note that 
+      gcc's runtime library was not thread-safe prior to gcc 3.x
+      unless you configured gcc 
+      with <code>--enable-threads</code> and recompiled it. Using a gcc
       that was not configured with this option may lead to errors in
-      your threaded programs that are extremely hard to find.
+      your threaded programs that are extremely hard to find. Newer
+      versions of gcc are thread-safe by default.
       </p>
 
     <li>
       <p>
-      <code>--with-multithreading=ACE-path</code>: enabling
+      <code>--with-multithreading=name</code>: enabling
       multi-threading as shown above does not enable multi-threading
-      inside the library itself. However, there are several places
-      where multi-threading can be used (in some parts of the graphical
-      output routines, the KellyErrorEstimator class and some other
-      places), and you can switch to multi-threading using this
-      configure option.
+      inside the library itself. However, there are many places in the
+      library and example programs
+      where multi-threading can be used, and you can switch to
+      multi-threading using this configure option.
       </p>
 
       <p>
-      To support multi-threading in a cross-platform way, we use the 
-      <a href="http://www.cs.wustl.edu/~schmidt/ACE.html" target="_top">ACE
-      (Adaptive Communications Environment)</a> library. This needs
-      to be installed separately, and the path to its installation
-      directory needs to be given to this option. 
+      To support multi-threading in a cross-platform way, two methods
+      are implemented that are selected by the argument given to
+      <code>--with-multithreading=name</code>:
+      <ul>
+        <li> <code>name=posix</code>: in this case, POSIX functions
+        are used to start threads and to implement mutex and barrier
+        data structures. Most systems today support POSIX, so this
+        should be fairly portable. If no argument is given to
+        <code>--with-multithreading</code>, then POSIX is assumed.
+
+       <li> <code>name=path-to-ACE</code>: 
+       In previous versions of
+       <acronym>deal.II</acronym>, we exclusively used the <a
+       href="http://www.cs.wustl.edu/~schmidt/ACE.html"
+       target="_top">ACE (Adaptive Communications Environment)</a>
+       library for cross-platform portability. This mode is still
+       supported for backward compatibility, although we prefer to
+       use POSIX. The ACE library needs to be installed separately,
+       and the path to its installation directory needs to be given
+       as argument to this option.
+      </ul>
+      As a rule, if the name of the argument is <code>posix</code>,
+      then POSIX threads are used. Otherwise, the configuration script
+      assumes that it is the path to the ACE library.
       </p>
 
       <p>
-      In our experience, if you want to use ACE on Sun, you should
-      compile it for pthreads rather than Solaris threads.
-      </p>
-
-      <p>
-      Note that the multi-thread support in the library is still
-      experimental. While <acronym>deal.II</acronym> runs on a variety
-      of Unix systems, we presently support detection of the number of
-      CPUs in your system only for Linux and Solaris.
+      Note that the library tries to detect the number of processors
+      in your system in multit-thread mode, to determine a default
+      number of threads to start in some situations. We presently
+      support this detection only on Linux, Solaris, OSF, and SGI
+      systems.
       </p>
 
     <li>
 
     <ul>
       <li>
-      <p>
+      <p> The
       <a href="http://www.cs.wustl.edu/~schmidt/ACE.html" target="_top">ACE
-      (Adaptive Communications Environment)</a>: This library is used
-      to support multithreading in a cross-platform way. It also
+      (Adaptive Communications Environment)</a> library: This library
+      can be used
+      to support multithreading in a cross-platform way if you say so
+      to the <code>./configure</code> script. It also
       enables programs to use interprocess communication and many
       other related services using a platform independent
       interface. On how to enable using this library, see the section on

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.