16 #include <deal.II/base/thread_management.h> 23 #ifdef DEAL_II_HAVE_UNISTD_H 28 DEAL_II_NAMESPACE_OPEN
37 volatile unsigned int n_existing_threads_counter = 1;
38 Mutex n_existing_threads_mutex;
41 void register_thread ()
43 Mutex::ScopedLock lock (n_existing_threads_mutex);
44 ++n_existing_threads_counter;
49 void deregister_thread ()
51 Mutex::ScopedLock lock (n_existing_threads_mutex);
52 --n_existing_threads_counter;
53 Assert (n_existing_threads_counter >= 1,
59 void handle_std_exception (
const std::exception &exc)
70 Mutex::ScopedLock lock(mutex);
72 std::cerr << std::endl << std::endl
73 <<
"---------------------------------------------------------" 75 <<
"In one of the sub-threads of this program, an exception\n" 76 <<
"was thrown and not caught. Since exceptions do not\n" 77 <<
"propagate to the main thread, the library has caught it.\n" 78 <<
"The information carried by this exception is given below.\n" 80 <<
"---------------------------------------------------------" 82 std::cerr <<
"Exception message: " << std::endl
83 <<
" " << exc.what() << std::endl
84 <<
"Exception type: " << std::endl
85 <<
" " <<
typeid(exc).name() << std::endl;
86 std::cerr <<
"Aborting!" << std::endl
87 <<
"---------------------------------------------------------" 96 void handle_unknown_exception ()
107 Mutex::ScopedLock lock(mutex);
109 std::cerr << std::endl << std::endl
110 <<
"---------------------------------------------------------" 112 <<
"In one of the sub-threads of this program, an exception\n" 113 <<
"was thrown and not caught. Since exceptions do not\n" 114 <<
"propagate to the main thread, the library has caught it.\n" 116 <<
"---------------------------------------------------------" 118 std::cerr <<
"Type of exception is unknown, but not std::exception.\n" 119 <<
"No additional information is available.\n" 120 <<
"---------------------------------------------------------" 132 return internal::n_existing_threads_counter;
139 const pid_t this_id = syscall(SYS_gettid);
140 #elif defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETPID) 141 const pid_t this_id = getpid();
143 const unsigned int this_id = 0;
146 return static_cast<unsigned int>(this_id);
151 #ifndef DEAL_II_WITH_THREADS 162 # ifdef DEAL_II_USE_MT_POSIX 165 #ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS 170 pthread_barrier_init (&
barrier, 0, count);
187 ExcMessage (
"Your local POSIX installation does not support\n" 188 "POSIX barriers. You will not be able to use\n" 189 "this class, but the rest of the threading\n" 190 "functionality is available."));
198 #ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS 199 pthread_barrier_destroy (&
barrier);
214 #ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS 215 return pthread_barrier_wait (&
barrier);
239 std::vector<std::pair<unsigned int,unsigned int> >
241 const unsigned int end,
242 const unsigned int n_intervals)
246 const unsigned int n_elements = end-begin;
247 const unsigned int n_elements_per_interval = n_elements / n_intervals;
248 const unsigned int residual = n_elements % n_intervals;
250 std::vector<std::pair<unsigned int,unsigned int> > return_values (n_intervals);
252 return_values[0].first = begin;
253 for (
unsigned int i=0; i<n_intervals; ++i)
255 if (i != n_intervals-1)
257 return_values[i].second = (return_values[i].first
258 + n_elements_per_interval);
264 ++return_values[i].second;
265 return_values[i+1].first = return_values[i].second;
268 return_values[i].second = end;
270 return return_values;
275 DEAL_II_NAMESPACE_CLOSE
unsigned int this_thread_id()
#define AssertThrow(cond, exc)
PosixThreadBarrier(const unsigned int count, const char *name=0, void *arg=0)
std::vector< std::pair< unsigned int, unsigned int > > split_interval(const unsigned int begin, const unsigned int end, const unsigned int n_intervals)
DummyBarrier(const unsigned int count, const char *name=0, void *arg=0)
static ::ExceptionBase & ExcMessage(std::string arg1)
#define Assert(cond, exc)
unsigned int n_existing_threads()
pthread_barrier_t barrier
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcBarrierSizeNotUseful(int arg1)