Skip to content

Commit 19ada69

Browse files
authored
Merge pull request STEllAR-GROUP#6617 from STEllAR-GROUP/fixing_6616
Adding support for the Flux job scheduling environment
2 parents dbc0ce6 + 55d5228 commit 19ada69

File tree

4 files changed

+98
-4
lines changed

4 files changed

+98
-4
lines changed

libs/core/batch_environments/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019-2022 The STE||AR-Group
1+
# Copyright (c) 2019-2025 The STE||AR-Group
22
#
33
# SPDX-License-Identifier: BSL-1.0
44
# Distributed under the Boost Software License, Version 1.0. (See accompanying
@@ -9,6 +9,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
99
set(batch_environments_headers
1010
hpx/batch_environments/alps_environment.hpp
1111
hpx/batch_environments/batch_environment.hpp
12+
hpx/batch_environments/flux_environment.hpp
1213
hpx/batch_environments/pjm_environment.hpp
1314
hpx/batch_environments/pbs_environment.hpp
1415
hpx/batch_environments/slurm_environment.hpp
@@ -25,8 +26,8 @@ set(batch_environments_compat_headers
2526
# cmake-format: on
2627

2728
set(batch_environments_sources
28-
alps_environment.cpp batch_environment.cpp pbs_environment.cpp
29-
pjm_environment.cpp slurm_environment.cpp
29+
alps_environment.cpp batch_environment.cpp flux_environment.cpp
30+
pbs_environment.cpp pjm_environment.cpp slurm_environment.cpp
3031
)
3132

3233
include(HPX_AddModule)
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2007-2025 Hartmut Kaiser
2+
//
3+
// SPDX-License-Identifier: BSL-1.0
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#pragma once
8+
9+
#include <hpx/config.hpp>
10+
11+
#include <cstddef>
12+
#include <string>
13+
14+
namespace hpx::util::batch_environments {
15+
16+
struct flux_environment
17+
{
18+
HPX_CORE_EXPORT flux_environment();
19+
20+
constexpr bool valid() const noexcept
21+
{
22+
return valid_;
23+
}
24+
25+
constexpr std::size_t node_num() const noexcept
26+
{
27+
return node_num_;
28+
}
29+
30+
constexpr std::size_t num_localities() const noexcept
31+
{
32+
return num_localities_;
33+
}
34+
35+
private:
36+
std::size_t node_num_;
37+
std::size_t num_localities_;
38+
bool valid_;
39+
};
40+
} // namespace hpx::util::batch_environments

libs/core/batch_environments/src/batch_environment.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2007-2023 Hartmut Kaiser
1+
// Copyright (c) 2007-2025 Hartmut Kaiser
22
// Copyright (c) 2013 Thomas Heller
33
//
44
// SPDX-License-Identifier: BSL-1.0
@@ -9,6 +9,7 @@
99
#include <hpx/asio/asio_util.hpp>
1010
#include <hpx/batch_environments/alps_environment.hpp>
1111
#include <hpx/batch_environments/batch_environment.hpp>
12+
#include <hpx/batch_environments/flux_environment.hpp>
1213
#include <hpx/batch_environments/pbs_environment.hpp>
1314
#include <hpx/batch_environments/pjm_environment.hpp>
1415
#include <hpx/batch_environments/slurm_environment.hpp>
@@ -90,6 +91,15 @@ namespace hpx::util {
9091
return;
9192
}
9293

94+
batch_environments::flux_environment const flux_env;
95+
if (flux_env.valid())
96+
{
97+
batch_name_ = "FLUX";
98+
num_localities_ = flux_env.num_localities();
99+
node_num_ = flux_env.node_num();
100+
return;
101+
}
102+
93103
batch_environments::slurm_environment const slurm_env(nodelist, debug);
94104
if (slurm_env.valid())
95105
{
@@ -200,12 +210,14 @@ namespace hpx::util {
200210
#if defined(HPX_HAVE_PARCELPORT_TCP)
201211
std::cerr << "Nodes from nodelist:" << std::endl;
202212
node_map_type::const_iterator const end = nodes_.end();
213+
// clang-format off
203214
for (node_map_type::const_iterator it = nodes_.begin(); it != end;
204215
++it)
205216
{
206217
std::cerr << (*it).second.first << ": " << (*it).second.second
207218
<< " (" << (*it).first << ")" << std::endl;
208219
}
220+
// clang-format on
209221
#endif
210222
}
211223
HPX_UNUSED(nodes);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) 2007-2025 Hartmut Kaiser
2+
//
3+
// SPDX-License-Identifier: BSL-1.0
4+
// Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
7+
#include <hpx/batch_environments/flux_environment.hpp>
8+
#include <hpx/util/from_string.hpp>
9+
10+
#include <cstddef>
11+
#include <string>
12+
13+
namespace hpx::util::batch_environments {
14+
15+
// FLUX_TASK_RANK: number of physical nodes
16+
// FLUX_JOB_NNODES: number of nodes in the job
17+
flux_environment::flux_environment()
18+
: node_num_(static_cast<std::size_t>(-1))
19+
, num_localities_(0)
20+
, valid_(false)
21+
{
22+
char const* num_nodes = std::getenv("FLUX_JOB_NNODES");
23+
valid_ = num_nodes != nullptr;
24+
if (valid_)
25+
{
26+
// Get the number of localities
27+
num_localities_ = from_string<std::size_t>(num_nodes);
28+
29+
// Initialize our node number, if available
30+
char const* var = std::getenv("FLUX_TASK_RANK");
31+
if (var != nullptr)
32+
{
33+
node_num_ = from_string<std::size_t>(var);
34+
}
35+
else
36+
{
37+
valid_ = false;
38+
}
39+
}
40+
}
41+
} // namespace hpx::util::batch_environments

0 commit comments

Comments
 (0)