detail::partitioner &get_partitioner() { util::static_<detail::partitioner, partitioner_tag> rp; if (!rp.get().cmd_line_parsed()) { if (get_runtime_ptr() != nullptr) { HPX_THROW_EXCEPTION(invalid_status, "hpx::resource::get_partitioner", "can be called only after the resource partitioner has " "been allowed to parse the command line options."); } else { // if the resource partitioner is not accessed for the first time // if the command-line parsing has not yet been done throw std::invalid_argument( "hpx::resource::get_partitioner() can be called only after " "the resource partitioner has been allowed to parse the " "command line options."); } } return rp.get(); }
boost::uint32_t get_locality_id(error_code& ec) { if (get_runtime_ptr() == 0) return naming::invalid_locality_id; naming::gid_type l = naming::get_agas_client().get_local_locality(ec); return l ? naming::get_locality_id_from_gid(l) : naming::invalid_locality_id; }
// return whether resolver client is in state described by st bool router_is(state st) { runtime* rt = get_runtime_ptr(); if (nullptr == rt) { // we're probably either starting or stopping return st == state_starting || st == state_stopping; } return (rt->get_agas_client().get_status() == st); }
// return whether thread manager is in the state described by st bool threadmanager_is(state st) { hpx::runtime* rt = get_runtime_ptr(); if (nullptr == rt) { // we're probably either starting or stopping return st == state_starting || st == state_stopping; } return (rt->get_thread_manager().status() == st); }
topology const& get_topology() { runtime* rt = get_runtime_ptr(); if (rt == NULL) { HPX_THROW_EXCEPTION(invalid_status, "hpx::threads::get_topology", "the hpx runtime system has not been initialized yet"); } return rt->get_topology(); }
HPX_EXPORT std::exception_ptr get_exception(Exception const& e, std::string const& func, std::string const& file, long line, std::string const& auxinfo) { if (is_of_lightweight_hpx_category(e)) return construct_lightweight_exception(e, func, file, line); std::int64_t pid = ::getpid(); std::string back_trace(backtrace()); std::string state_name("not running"); std::string hostname; hpx::runtime* rt = get_runtime_ptr(); if (rt) { state rts_state = rt->get_state(); state_name = get_runtime_state_name(rts_state); if (rts_state >= state_initialized && rts_state < state_stopped) { std::ostringstream strm; strm << get_runtime().here(); hostname = strm.str(); } } // if this is not a HPX thread we do not need to query neither for // the shepherd thread nor for the thread id error_code ec(lightweight); std::uint32_t node = get_locality_id(ec); std::size_t shepherd = std::size_t(-1); threads::thread_id_type thread_id; util::thread_description thread_name; threads::thread_self* self = threads::get_self_ptr(); if (nullptr != self) { if (threads::threadmanager_is(state_running)) shepherd = hpx::get_worker_thread_num(); thread_id = threads::get_self_id(); thread_name = threads::get_thread_description(thread_id); } std::string env(get_execution_environment()); std::string config(configuration_string()); return construct_exception(e, func, file, line, back_trace, node, hostname, pid, shepherd, reinterpret_cast<std::size_t>(thread_id.get()), util::as_string(thread_name), env, config, state_name, auxinfo); }
HPX_API_EXPORT parcel_write_handler_type set_parcel_write_handler( parcel_write_handler_type const& f) { runtime* rt = get_runtime_ptr(); if (0 != rt) return rt->get_parcel_handler().set_write_handler(f); HPX_THROW_EXCEPTION(invalid_status, "hpx::set_default_parcel_write_handler", "the runtime system is not operational at this point"); }
std::string get_locality_base_name() { runtime* rt = get_runtime_ptr(); if (rt == 0) { HPX_THROW_EXCEPTION(invalid_status, "hpx::detail::get_locality_name", "the runtime system is not operational at this point"); return ""; } return rt->get_parcel_handler().get_locality_name(); }
void register_pre_startup_function(startup_function_type const& f) { runtime* rt = get_runtime_ptr(); if (NULL != rt) { if (rt->get_state() >= runtime::state_pre_startup) { HPX_THROW_EXCEPTION(invalid_status, "register_startup_function", "Too late to register a new pre-startup function."); return; } rt->add_pre_startup_function(f); } else { global_startup_functions.push_back(f); } }
void assertion_failed_msg(char const* msg, char const* expr, char const* function, char const* file, long line) { if (!expect_exception_flag.load(std::memory_order_relaxed) && get_config_entry("hpx.attach_debugger", "") == "exception") { util::attach_debugger(); } bool threw = false; std::string str("assertion '" + std::string(msg) + "' failed"); if (expr != msg) str += " (" + std::string(expr) + ")"; try { boost::filesystem::path p(hpx::util::create_path(file)); hpx::detail::throw_exception( hpx::exception(hpx::assertion_failure, str), function, p.string(), line); } catch (...) { threw = true; // If the runtime pointer is available, we can safely get the prefix // of this locality. If it's not available, then just terminate. runtime* rt = get_runtime_ptr(); if (nullptr != rt) { rt->report_error(std::current_exception()); } else { std::cerr << "Runtime is not available, reporting error locally. " << hpx::diagnostic_information(std::current_exception()) << std::flush; } } // If the exception wasn't thrown, then print out the assertion message, // so that the program doesn't abort without any diagnostics. if (!threw) { std::cerr << "Runtime is not available, reporting error locally\n" "{what}: " << str << std::endl; } std::abort(); }
detail::partitioner &create_partitioner( util::function_nonser< int(boost::program_options::variables_map& vm) > const& f, boost::program_options::options_description const& desc_cmdline, int argc, char **argv, std::vector<std::string> ini_config, resource::partitioner_mode rpmode, runtime_mode mode, bool check) { util::static_<detail::partitioner, partitioner_tag> rp_; auto &rp = rp_.get(); if (rp.cmd_line_parsed()) { if (check) { // if the resource partitioner is not accessed for the // first time if the command-line parsing has not yet // been done if (get_runtime_ptr() != nullptr) { HPX_THROW_EXCEPTION(invalid_status, "hpx::resource::get_partitioner", "can be called only after the resource partitioner " "has been allowed to parse the command line " "options."); } else { throw std::invalid_argument( "hpx::resource::get_partitioner() can be called " "only after the resource partitioner has been " "allowed to parse the command line options."); } } // no need to parse a second time } else { rp.parse(f, desc_cmdline, argc, argv, std::move(ini_config), rpmode, mode); } return rp; }
naming::gid_type get_next_id( std::size_t count , error_code& ec ) { if (get_runtime_ptr() == 0) { HPX_THROWS_IF(ec, invalid_status, "get_next_id", "the runtime system has not been started yet."); return naming::invalid_gid; } naming::resolver_client& agas_ = naming::get_agas_client(); naming::gid_type lower_bound, upper_bound; agas_.get_id_range(count, lower_bound, upper_bound, ec); if (ec) return naming::invalid_gid; return lower_bound; }
HPX_EXPORT void throw_exception(Exception const& e, std::string const& func, std::string const& file, long line) { boost::int64_t pid_ = ::getpid(); std::string back_trace(backtrace()); std::string hostname_ = ""; if (get_runtime_ptr()) { util::osstream strm; strm << get_runtime().here(); hostname_ = util::osstream_get_string(strm); } // if this is not a HPX thread we do not need to query neither for // the shepherd thread nor for the thread id boost::uint32_t node = 0; std::size_t shepherd = std::size_t(-1); std::size_t thread_id = 0; std::string thread_name(""); threads::thread_self* self = threads::get_self_ptr(); if (NULL != self) { if (threads::threadmanager_is(running)) { node = get_locality_id(); shepherd = threads::threadmanager_base::get_worker_thread_num(); } thread_id = reinterpret_cast<std::size_t>(self->get_thread_id()); thread_name = threads::get_thread_description(self->get_thread_id()); } rethrow_exception(e, func, file, line, back_trace, node, hostname_, pid_, shepherd, thread_id, thread_name); }
void register_shutdown_function(shutdown_function_type const& f) { runtime* rt = get_runtime_ptr(); if (NULL != rt) rt->add_shutdown_function(f); }
std::string configuration_string() { std::ostringstream strm; #if defined(HPX_HAVE_NATIVE_TLS) strm << " HPX_HAVE_NATIVE_TLS=ON\n"; #else strm << " HPX_HAVE_NATIVE_TLS=OFF\n"; #endif #if defined(HPX_HAVE_STACKTRACES) strm << " HPX_HAVE_STACKTRACES=ON\n"; #else strm << " HPX_HAVE_STACKTRACES=OFF\n"; #endif #if defined(HPX_HAVE_COMPRESSION_BZIP2) strm << " HPX_HAVE_COMPRESSION_BZIP2=ON\n"; #else strm << " HPX_HAVE_COMPRESSION_BZIP2=OFF\n"; #endif #if defined(HPX_HAVE_COMPRESSION_SNAPPY) strm << " HPX_HAVE_COMPRESSION_SNAPPY=ON\n"; #else strm << " HPX_HAVE_COMPRESSION_SNAPPY=OFF\n"; #endif #if defined(HPX_HAVE_COMPRESSION_ZLIB) strm << " HPX_HAVE_COMPRESSION_ZLIB=ON\n"; #else strm << " HPX_HAVE_COMPRESSION_ZLIB=OFF\n"; #endif #if defined(HPX_HAVE_PARCEL_COALESCING) strm << " HPX_HAVE_PARCEL_COALESCING=ON\n"; #else strm << " HPX_HAVE_PARCEL_COALESCING=OFF\n"; #endif #if defined(HPX_HAVE_PARCELPORT_TCP) strm << " HPX_HAVE_PARCELPORT_TCP=ON\n"; #else strm << " HPX_HAVE_PARCELPORT_TCP=OFF\n"; #endif #if defined(HPX_HAVE_PARCELPORT_MPI) strm << " HPX_HAVE_PARCELPORT_MPI=ON (" << mpi_version() << ")\n"; #else strm << " HPX_HAVE_PARCELPORT_MPI=OFF\n"; #endif #if defined(HPX_HAVE_PARCELPORT_IPC) strm << " HPX_HAVE_PARCELPORT_IPC=ON\n"; #else strm << " HPX_HAVE_PARCELPORT_IPC=OFF\n"; #endif #if defined(HPX_HAVE_PARCELPORT_IBVERBS) strm << " HPX_HAVE_PARCELPORT_IBVERBS=ON\n"; #else strm << " HPX_HAVE_PARCELPORT_IBVERBS=OFF\n"; #endif #if defined(HPX_HAVE_VERIFY_LOCKS) strm << " HPX_HAVE_VERIFY_LOCKS=ON\n"; #else strm << " HPX_HAVE_VERIFY_LOCKS=OFF\n"; #endif #if defined(HPX_HAVE_HWLOC) strm << " HPX_HAVE_HWLOC=ON\n"; #else strm << " HPX_HAVE_HWLOC=OFF\n"; #endif #if defined(HPX_HAVE_ITTNOTIFY) strm << " HPX_HAVE_ITTNOTIFY=ON\n"; #else strm << " HPX_HAVE_ITTNOTIFY=OFF\n"; #endif #if defined(HPX_MSVC) #if defined(HPX_HAVE_FIBER_BASED_COROUTINES) strm << " HPX_HAVE_FIBER_BASED_COROUTINES=ON\n"; #else strm << " HPX_HAVE_FIBER_BASED_COROUTINES=OFF\n"; #endif #if defined(HPX_HAVE_SWAP_CONTEXT_EMULATION) strm << " HPX_HAVE_SWAP_CONTEXT_EMULATION=ON\n"; #else strm << " HPX_HAVE_SWAP_CONTEXT_EMULATION=OFF\n"; #endif #endif #if defined(HPX_HAVE_RUN_MAIN_EVERYWHERE) strm << " HPX_HAVE_RUN_MAIN_EVERYWHERE=ON\n"; #else strm << " HPX_HAVE_RUN_MAIN_EVERYWHERE=OFF\n"; #endif #if defined(HPX_PARCEL_MAX_CONNECTIONS) strm << " HPX_PARCEL_MAX_CONNECTIONS=" << HPX_PARCEL_MAX_CONNECTIONS << "\n"; #endif #if defined(HPX_PARCEL_MAX_CONNECTIONS_PER_LOCALITY) strm << " HPX_PARCEL_MAX_CONNECTIONS_PER_LOCALITY=" << HPX_PARCEL_MAX_CONNECTIONS_PER_LOCALITY << "\n"; #endif #if defined(HPX_AGAS_LOCAL_CACHE_SIZE) strm << " HPX_AGAS_LOCAL_CACHE_SIZE=" << HPX_AGAS_LOCAL_CACHE_SIZE << "\n"; #endif #if defined(HPX_HAVE_PARCELPORT_IPC) && defined(HPX_PARCEL_IPC_DATA_BUFFER_CACHE_SIZE) strm << " HPX_PARCEL_IPC_DATA_BUFFER_CACHE_SIZE=" << HPX_PARCEL_IPC_DATA_BUFFER_CACHE_SIZE << "\n"; #endif #if defined(HPX_HAVE_MALLOC) strm << " HPX_HAVE_MALLOC=" << HPX_HAVE_MALLOC << "\n"; #endif if (get_runtime_ptr() == nullptr) { strm << " HPX_PREFIX (configured)=unknown\n"; #if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__MIC) strm << " HPX_PREFIX=unknown\n"; #endif } else { strm << " HPX_PREFIX (configured)=" << util::hpx_prefix() << "\n"; #if !defined(__ANDROID__) && !defined(ANDROID) && !defined(__MIC) strm << " HPX_PREFIX=" << util::find_prefix() << "\n"; #endif } return strm.str(); }