Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable resolving hostnames if TCP is disabled #6389

Merged
merged 2 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
//
// SPDX-License-Identifier: BSL-1.0
// Distributed under the Boost Software License, Version 1.0. (See accompanying
Expand Down Expand Up @@ -31,13 +31,13 @@ namespace hpx::util {
{
// the constructor tries to read initial values from a batch
// environment, filling our map of nodes and thread counts
batch_environment(std::vector<std::string>& nodelist,
explicit batch_environment(std::vector<std::string>& nodelist,
bool have_mpi = false, bool debug = false, bool enable = true);

// this function initializes the map of nodes from the given (space
// separated) list of nodes
std::string init_from_nodelist(std::vector<std::string> const& nodes,
std::string const& agas_host);
std::string const& agas_host, bool have_tcp);

// The number of threads is either one (if no PBS information was
// found), or it is the same as the number of times this node has been
Expand Down Expand Up @@ -71,17 +71,20 @@ namespace hpx::util {
// Return a string containing the name of the batch system
std::string get_batch_name() const;

using node_map_type = std::map<asio::ip::tcp::endpoint,
std::pair<std::string, std::size_t>>;

std::string agas_node_;
std::size_t agas_node_num_;
std::size_t node_num_;
std::size_t num_threads_;
node_map_type nodes_;
std::size_t num_localities_;
std::string batch_name_;
bool debug_;

#if defined(HPX_HAVE_PARCELPORT_TCP)
using node_map_type = std::map<asio::ip::tcp::endpoint,
std::pair<std::string, std::size_t>>;

node_map_type nodes_;
#endif
};
} // namespace hpx::util

Expand Down
53 changes: 36 additions & 17 deletions libs/core/batch_environments/src/batch_environment.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2007-2022 Hartmut Kaiser
// Copyright (c) 2007-2023 Hartmut Kaiser
// Copyright (c) 2013 Thomas Heller
//
// SPDX-License-Identifier: BSL-1.0
Expand Down Expand Up @@ -120,7 +120,8 @@ namespace hpx::util {

// this function initializes the map of nodes from the given a list of nodes
std::string batch_environment::init_from_nodelist(
std::vector<std::string> const& nodes, std::string const& agas_host)
std::vector<std::string> const& nodes, std::string const& agas_host,
bool have_tcp)
{
if (debug_)
std::cerr << "got node list" << std::endl;
Expand All @@ -139,29 +140,41 @@ namespace hpx::util {
if (debug_)
std::cerr << "extracted: '" << s << "'" << std::endl;

asio::ip::tcp::endpoint ep =
util::resolve_hostname(s, 0, io_service);

#if defined(HPX_HAVE_PARCELPORT_TCP)
if (!found_agas_host &&
((agas_host.empty() && nodes_.empty()) || s == agas_host))
{
agas_node_ = s;
found_agas_host = true;
agas_node_ = s;
agas_node_num_ = agas_node_num;
}

if (0 == nodes_.count(ep))
if (have_tcp)
{
if (debug_)
std::cerr << "incrementing agas_node_num" << std::endl;
++agas_node_num;
asio::ip::tcp::endpoint ep =
util::resolve_hostname(s, 0, io_service);

if (0 == nodes_.count(ep))
{
if (debug_)
std::cerr << "incrementing agas_node_num"
<< std::endl;
++agas_node_num;
}

std::pair<std::string, std::size_t>& data = nodes_[ep];
if (data.first.empty())
data.first = s;
++data.second;
}

std::pair<std::string, std::size_t>& data = nodes_[ep];
if (data.first.empty())
data.first = s;
++data.second;

#else
if (!found_agas_host && (agas_host.empty() || s == agas_host))
{
found_agas_host = true;
agas_node_ = s;
agas_node_num_ = agas_node_num;
}
#endif
nodes_list += s + ' ';
}
}
Expand All @@ -184,6 +197,7 @@ namespace hpx::util {
<< std::endl;
}

#if defined(HPX_HAVE_PARCELPORT_TCP)
std::cerr << "Nodes from nodelist:" << std::endl;
node_map_type::const_iterator const end = nodes_.end();
for (node_map_type::const_iterator it = nodes_.begin(); it != end;
Expand All @@ -192,14 +206,15 @@ namespace hpx::util {
std::cerr << (*it).second.first << ": " << (*it).second.second
<< " (" << (*it).first << ")" << std::endl;
}
#endif
}
HPX_UNUSED(nodes);
return nodes_list;
}

// The number of threads is either one (if no PBS/SLURM information was
// found), or it is the same as the number of times this node has been
// listed in the node file. Additionally this takes into account the number
// listed in the node file. Additionally, this takes into account the number
// of tasks run on this node.
std::size_t batch_environment::retrieve_number_of_threads() const noexcept
{
Expand Down Expand Up @@ -233,7 +248,11 @@ namespace hpx::util {
std::string batch_environment::host_name(
std::string const& def_hpx_name) const
{
#if defined(HPX_HAVE_PARCELPORT_TCP)
std::string host = nodes_.empty() ? def_hpx_name : host_name();
#else
std::string host = host_name();
#endif
if (debug_)
std::cerr << "host_name: " << host << std::endl;
return host;
Expand Down
21 changes: 14 additions & 7 deletions libs/full/command_line_handling/src/command_line_handling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,8 @@ namespace hpx::util {
node != static_cast<std::size_t>(-1) && vm.count("hpx:debug-clp");

// create host name mapping
[[maybe_unused]] bool const have_tcp =
rtcfg_.get_entry("hpx.parcel.tcp.enable", "1") != "0";
util::map_hostnames mapnames(debug_clp);

if (vm.count("hpx:ifsuffix"))
Expand Down Expand Up @@ -493,8 +495,8 @@ namespace hpx::util {
if (!nodelist.empty())
{
using_nodelist = true;
ini_config.emplace_back(
"hpx.nodes!=" + env.init_from_nodelist(nodelist, agas_host));
ini_config.emplace_back("hpx.nodes!=" +
env.init_from_nodelist(nodelist, agas_host, have_tcp));
}

// let the batch environment decide about the AGAS host
Expand All @@ -503,8 +505,8 @@ namespace hpx::util {
#endif

bool run_agas_server = false;
std::string hpx_host;
std::uint16_t hpx_port = 0;
[[maybe_unused]] std::string hpx_host;
[[maybe_unused]] std::uint16_t hpx_port = 0;

#if defined(HPX_HAVE_NETWORKING)
bool expect_connections = false;
Expand Down Expand Up @@ -724,9 +726,14 @@ namespace hpx::util {
// handle high-priority threads
handle_high_priority_threads(vm, ini_config);

#if defined(HPX_HAVE_PARCELPORT_TCP)
// map host names to ip addresses, if requested
hpx_host = mapnames.map(hpx_host, hpx_port);
agas_host = mapnames.map(agas_host, agas_port);
if (have_tcp)
{
hpx_host = mapnames.map(hpx_host, hpx_port);
agas_host = mapnames.map(agas_host, agas_port);
}
#endif

// sanity checks
if (rtcfg_.mode_ != hpx::runtime_mode::local && num_localities_ == 1 &&
Expand Down Expand Up @@ -762,7 +769,7 @@ namespace hpx::util {
}
else if (env.found_batch_environment())
{
// in batch mode, if the network addresses are different and we
// in batch mode, if the network addresses are different, and we
// should not run the AGAS server we assume to be in worker mode
rtcfg_.mode_ = hpx::runtime_mode::worker;

Expand Down
Loading