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);
40 ++n_existing_threads_counter;
48 --n_existing_threads_counter;
55 handle_std_exception(
const std::exception &exc) {
65 Mutex::ScopedLock lock(mutex);
70 <<
"---------------------------------------------------------" 72 <<
"In one of the sub-threads of this program, an exception\n" 73 <<
"was thrown and not caught. Since exceptions do not\n" 74 <<
"propagate to the main thread, the library has caught it.\n" 75 <<
"The information carried by this exception is given below.\n" 77 <<
"---------------------------------------------------------" 79 std::cerr <<
"Exception message: " << std::endl
80 <<
" " << exc.what() << std::endl
81 <<
"Exception type: " << std::endl
82 <<
" " <<
typeid(exc).name() << std::endl;
83 std::cerr <<
"Aborting!" << std::endl
84 <<
"---------------------------------------------------------" 93 [[noreturn]]
void handle_unknown_exception()
104 Mutex::ScopedLock lock(mutex);
109 <<
"---------------------------------------------------------" 111 <<
"In one of the sub-threads of this program, an exception\n" 112 <<
"was thrown and not caught. Since exceptions do not\n" 113 <<
"propagate to the main thread, the library has caught it.\n" 115 <<
"---------------------------------------------------------" 117 std::cerr <<
"Type of exception is unknown, but not std::exception.\n" 118 <<
"No additional information is available.\n" 119 <<
"---------------------------------------------------------" 131 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 155 Assert(count == 1, ExcBarrierSizeNotUseful(count));
160 # ifdef DEAL_II_USE_MT_POSIX 163 # ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS 168 pthread_barrier_init(&barrier,
nullptr, count);
185 ExcMessage(
"Your local POSIX installation does not support\n" 186 "POSIX barriers. You will not be able to use\n" 187 "this class, but the rest of the threading\n" 188 "functionality is available."));
196 # ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS 197 pthread_barrier_destroy(&barrier);
212 # ifndef DEAL_II_USE_MT_POSIX_NO_BARRIERS 213 return pthread_barrier_wait(&barrier);
236 std::vector<std::pair<unsigned int, unsigned int>>
238 const unsigned int end,
239 const unsigned int n_intervals)
243 const unsigned int n_elements = end - begin;
244 const unsigned int n_elements_per_interval = n_elements / n_intervals;
245 const unsigned int residual = n_elements % n_intervals;
247 std::vector<std::pair<unsigned int, unsigned int>> return_values(
250 return_values[0].first = begin;
251 for (
unsigned int i = 0; i < n_intervals; ++i)
253 if (i != n_intervals - 1)
255 return_values[i].second =
256 (return_values[i].first + n_elements_per_interval);
262 ++return_values[i].second;
263 return_values[i + 1].first = return_values[i].second;
266 return_values[i].second = end;
268 return return_values;
273 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)
static::ExceptionBase & ExcInternalError()