16 #include <deal.II/base/thread_management.h> 22 #ifdef DEAL_II_HAVE_UNISTD_H 27 DEAL_II_NAMESPACE_OPEN
34 static std::atomic<unsigned int> n_existing_threads_counter(1);
37 void register_thread ()
39 ++n_existing_threads_counter;
44 void deregister_thread ()
46 --n_existing_threads_counter;
47 Assert (n_existing_threads_counter >= 1,
54 void handle_std_exception (
const std::exception &exc)
65 Mutex::ScopedLock lock(mutex);
67 std::cerr << std::endl << std::endl
68 <<
"---------------------------------------------------------" 70 <<
"In one of the sub-threads of this program, an exception\n" 71 <<
"was thrown and not caught. Since exceptions do not\n" 72 <<
"propagate to the main thread, the library has caught it.\n" 73 <<
"The information carried by this exception is given below.\n" 75 <<
"---------------------------------------------------------" 77 std::cerr <<
"Exception message: " << std::endl
78 <<
" " << exc.what() << std::endl
79 <<
"Exception type: " << std::endl
80 <<
" " <<
typeid(exc).name() << std::endl;
81 std::cerr <<
"Aborting!" << std::endl
82 <<
"---------------------------------------------------------" 92 void handle_unknown_exception ()
103 Mutex::ScopedLock lock(mutex);
105 std::cerr << std::endl << std::endl
106 <<
"---------------------------------------------------------" 108 <<
"In one of the sub-threads of this program, an exception\n" 109 <<
"was thrown and not caught. Since exceptions do not\n" 110 <<
"propagate to the main thread, the library has caught it.\n" 112 <<
"---------------------------------------------------------" 114 std::cerr <<
"Type of exception is unknown, but not std::exception.\n" 115 <<
"No additional information is available.\n" 116 <<
"---------------------------------------------------------" 127 return internal::n_existing_threads_counter;
134 const pid_t this_id = syscall(SYS_gettid);
135 #elif defined(DEAL_II_HAVE_UNISTD_H) && defined(DEAL_II_HAVE_GETPID) 136 const pid_t this_id = getpid();
138 const unsigned int this_id = 0;
141 return static_cast<unsigned int>(this_id);
146 #ifndef DEAL_II_WITH_THREADS 157 # ifdef DEAL_II_USE_MT_POSIX 160 #ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS 165 pthread_barrier_init (&
barrier,
nullptr, count);
182 ExcMessage (
"Your local POSIX installation does not support\n" 183 "POSIX barriers. You will not be able to use\n" 184 "this class, but the rest of the threading\n" 185 "functionality is available."));
193 #ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS 194 pthread_barrier_destroy (&
barrier);
209 #ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS 210 return pthread_barrier_wait (&
barrier);
234 std::vector<std::pair<unsigned int,unsigned int> >
236 const unsigned int end,
237 const unsigned int n_intervals)
241 const unsigned int n_elements = end-begin;
242 const unsigned int n_elements_per_interval = n_elements / n_intervals;
243 const unsigned int residual = n_elements % n_intervals;
245 std::vector<std::pair<unsigned int,unsigned int> > return_values (n_intervals);
247 return_values[0].first = begin;
248 for (
unsigned int i=0; i<n_intervals; ++i)
250 if (i != n_intervals-1)
252 return_values[i].second = (return_values[i].first
253 + n_elements_per_interval);
259 ++return_values[i].second;
260 return_values[i+1].first = return_values[i].second;
263 return_values[i].second = end;
265 return return_values;
270 DEAL_II_NAMESPACE_CLOSE
unsigned int this_thread_id()
#define AssertThrow(cond, exc)
std::vector< std::pair< unsigned int, unsigned int > > split_interval(const unsigned int begin, const unsigned int end, const unsigned int n_intervals)
static ::ExceptionBase & ExcMessage(std::string arg1)
DummyBarrier(const unsigned int count, const char *name=nullptr, void *arg=nullptr)
#define Assert(cond, exc)
unsigned int n_existing_threads()
PosixThreadBarrier(const unsigned int count, const char *name=nullptr, void *arg=nullptr)
pthread_barrier_t barrier
static ::ExceptionBase & ExcInternalError()
static ::ExceptionBase & ExcBarrierSizeNotUseful(int arg1)