From: Wolfgang Bangerth Date: Tue, 30 Apr 2002 08:30:07 +0000 (+0000) Subject: Support POSIX threads, as an alternative to ACE. X-Git-Tag: v8.0.0~18096 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6a301b17d35524e89d25a74db5b3e2b2bb338ac9;p=dealii.git Support POSIX threads, as an alternative to ACE. git-svn-id: https://svn.dealii.org/trunk@5759 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/aclocal.m4 b/deal.II/aclocal.m4 index 84868de57f..600c85f92c 100644 --- a/deal.II/aclocal.m4 +++ b/deal.II/aclocal.m4 @@ -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_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_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_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 diff --git a/deal.II/base/include/base/config.h.in b/deal.II/base/include/base/config.h.in index bd3541c71d..62b33b6b25 100644 --- a/deal.II/base/include/base/config.h.in +++ b/deal.II/base/include/base/config.h.in @@ -76,10 +76,22 @@ 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 diff --git a/deal.II/base/include/base/thread_management.h b/deal.II/base/include/base/thread_management.h index 58dcd1b6be..b50cd44ec9 100644 --- a/deal.II/base/include/base/thread_management.h +++ b/deal.II/base/include/base/thread_management.h @@ -22,8 +22,12 @@ #include #ifdef DEAL_II_USE_MT -# include -# include +# if defined(DEAL_II_USE_MT_ACE) +# include +# include +# elif defined(DEAL_II_USE_MT_POSIX) +# include +# 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}, + * but to avoid including + * @p{} 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 diff --git a/deal.II/base/source/thread_management.cc b/deal.II/base/source/thread_management.cc index 5add51f3d0..5dfe7811b4 100644 --- a/deal.II/base/source/thread_management.cc +++ b/deal.II/base/source/thread_management.cc @@ -13,11 +13,14 @@ #include - +#ifdef DEAL_II_USE_MT_POSIX +# include +#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()) + {}; + + + PosixThreadManager::~PosixThreadManager () + { + // wait for all threads, and + // release memory + wait (); + delete reinterpret_cast*>(thread_id_list); + }; + + + + void + PosixThreadManager::spawn (const FunPtr fun_ptr, + void * fun_data, + int) + { + std::list &tid_list + = *reinterpret_cast*>(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 &tid_list + = *reinterpret_cast*>(thread_id_list); + + for (std::list::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, diff --git a/deal.II/common/Make.global_options.in b/deal.II/common/Make.global_options.in index eb682eb4e4..98b9d30787 100644 --- a/deal.II/common/Make.global_options.in +++ b/deal.II/common/Make.global_options.in @@ -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 diff --git a/deal.II/configure b/deal.II/configure index 31a0ae53b9..1ea1e7518b 100755 --- a/deal.II/configure +++ b/deal.II/configure @@ -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 + +#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 + +#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 + +#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 + diff --git a/deal.II/configure.in b/deal.II/configure.in index e9c4619214..e9cb71e418 100644 --- a/deal.II/configure.in +++ b/deal.II/configure.in @@ -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) diff --git a/deal.II/doc/news/2002/c-3-3.html b/deal.II/doc/news/2002/c-3-3.html index f5f8d5594f..27d25fc33f 100644 --- a/deal.II/doc/news/2002/c-3-3.html +++ b/deal.II/doc/news/2002/c-3-3.html @@ -34,7 +34,22 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK
  1. + New: In all previous versions, deal.II used + the ACE (Adaptive Communications Environment) + 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 + ReadMe file. +
    + (WB 2002/04/30) +

    +
  2. Changed: The Makefiles for the library are now truly parallel. To this end, the automatic generation of the files forward_declarations.h in the various directories had @@ -44,7 +59,8 @@ contributor's names are abbreviated by WB (Wolfgang Bangerth), GK single library. In this case, make forward can be used to build them manually.
    - I introduced separate targets for the generation of the optimized versions only. + I introduced separate targets for the generation of the + optimized versions only.
    (GK 2002/04/17)

    diff --git a/deal.II/doc/news/news.html b/deal.II/doc/news/news.html index 9962db0cb3..3a610fc926 100644 --- a/deal.II/doc/news/news.html +++ b/deal.II/doc/news/news.html @@ -48,6 +48,20 @@
    +
    + 2004/04/30: Multi-threading support using POSIX +
    +
    + In all previous versions, deal.II used + the ACE (Adaptive Communications Environment) + 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. +

    +
    +
    2004/04/16: New example program showing software design practices for finite element programs diff --git a/deal.II/doc/readme.html b/deal.II/doc/readme.html index b8233fa6a3..1b335ebe9e 100644 --- a/deal.II/doc/readme.html +++ b/deal.II/doc/readme.html @@ -454,48 +454,62 @@

    --enable-multithreading: 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 - -D__USE_MALLOC. 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 --enable-threads and recompile it. Using a gcc + -D__USE_MALLOC. Note that + gcc's runtime library was not thread-safe prior to gcc 3.x + unless you configured gcc + with --enable-threads 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.

  3. - --with-multithreading=ACE-path: enabling + --with-multithreading=name: 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.

    - To support multi-threading in a cross-platform way, we use the - ACE - (Adaptive Communications Environment) 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 + --with-multithreading=name: +

      +
    • name=posix: 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 + --with-multithreading, then POSIX is assumed. + +
    • name=path-to-ACE: + In previous versions of + deal.II, we exclusively used the ACE (Adaptive Communications Environment) + 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. +
    + As a rule, if the name of the argument is posix, + then POSIX threads are used. Otherwise, the configuration script + assumes that it is the path to the ACE library.

    - In our experience, if you want to use ACE on Sun, you should - compile it for pthreads rather than Solaris threads. -

    - -

    - Note that the multi-thread support in the library is still - experimental. While deal.II 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.

  4. @@ -617,10 +631,12 @@
    • -

      +

      The ACE - (Adaptive Communications Environment): This library is used - to support multithreading in a cross-platform way. It also + (Adaptive Communications Environment) library: This library + can be used + to support multithreading in a cross-platform way if you say so + to the ./configure 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