• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

STEllAR-GROUP / hpx / #856

28 Dec 2022 02:00AM UTC coverage: 86.602% (+0.05%) from 86.55%
#856

push

StellarBot
Merge #6119

6119: Update CMakeLists.txt r=hkaiser a=khuck

updating the default APEX version


Co-authored-by: Kevin Huck <khuck@cs.uoregon.edu>

174566 of 201573 relevant lines covered (86.6%)

1876093.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.69
/libs/core/batch_environments/src/batch_environment.cpp
1
//  Copyright (c) 2007-2022 Hartmut Kaiser
2
//  Copyright (c)      2013 Thomas Heller
3
//
4
//  SPDX-License-Identifier: BSL-1.0
5
//  Distributed under the Boost Software License, Version 1.0. (See accompanying
6
//  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7

8
#include <hpx/config.hpp>
9
#include <hpx/config/asio.hpp>
10
#include <hpx/asio/asio_util.hpp>
11
#include <hpx/batch_environments/alps_environment.hpp>
12
#include <hpx/batch_environments/batch_environment.hpp>
13
#include <hpx/batch_environments/pbs_environment.hpp>
14
#include <hpx/batch_environments/pjm_environment.hpp>
15
#include <hpx/batch_environments/slurm_environment.hpp>
16
#include <hpx/modules/errors.hpp>
17
#include <hpx/type_support/unused.hpp>
18

19
#include <asio/io_context.hpp>
20
#include <asio/ip/host_name.hpp>
21

22
#include <cstddef>
23
#include <iostream>
24
#include <string>
25
#include <utility>
26
#include <vector>
27

28
namespace hpx::util {
29

30
    batch_environment::batch_environment(std::vector<std::string>& nodelist,
1,197✔
31
        bool have_mpi, bool debug, bool enable)
32
      : agas_node_num_(0)
1,197✔
33
      , node_num_(std::size_t(-1))
1,197✔
34
      , num_threads_(std::size_t(-1))
1,197✔
35
      , num_localities_(std::size_t(-1))
1,197✔
36
      , debug_(debug)
1,197✔
37
    {
38
        if (!enable)
1,197✔
39
            return;
2✔
40

41
        struct onexit
42
        {
43
            explicit onexit(batch_environment const& env) noexcept
1,195✔
44
              : env_(env)
1,195✔
45
            {
46
            }
1,195✔
47

48
            ~onexit()
1,195✔
49
            {
50
                if (env_.debug_)
1,195✔
51
                {
52
                    std::cerr << "batch_name: " << env_.batch_name_
1✔
53
                              << std::endl;
1✔
54
                    std::cerr << "num_threads: " << env_.num_threads_
1✔
55
                              << std::endl;
1✔
56
                    std::cerr << "node_num_: " << env_.node_num_ << std::endl;
1✔
57
                    std::cerr << "num_localities: " << env_.num_localities_
1✔
58
                              << std::endl;
1✔
59
                }
1✔
60
            }
1,195✔
61

62
            batch_environment const& env_;
63
        };
64

65
        onexit _(*this);
1,195✔
66

67
        batch_environments::alps_environment alps_env(nodelist, debug);
1,195✔
68
        if (alps_env.valid())
1,195✔
69
        {
70
            batch_name_ = "ALPS";
×
71
            num_threads_ = alps_env.num_threads();
×
72
            num_localities_ = alps_env.num_localities();
×
73
            node_num_ = alps_env.node_num();
×
74
            return;
×
75
        }
76

77
        batch_environments::pjm_environment pjm_env(nodelist, have_mpi, debug);
1,195✔
78
        if (pjm_env.valid())
1,195✔
79
        {
80
            batch_name_ = "PJM";
×
81
            num_threads_ = pjm_env.num_threads();
×
82
            num_localities_ = pjm_env.num_localities();
×
83
            node_num_ = pjm_env.node_num();
×
84
            return;
×
85
        }
86

87
        batch_environments::slurm_environment slurm_env(nodelist, debug);
1,195✔
88
        if (slurm_env.valid())
1,195✔
89
        {
90
            batch_name_ = "SLURM";
×
91
            num_threads_ = slurm_env.num_threads();
×
92
            num_localities_ = slurm_env.num_localities();
×
93
            node_num_ = slurm_env.node_num();
×
94
            return;
×
95
        }
96

97
        batch_environments::pbs_environment pbs_env(nodelist, have_mpi, debug);
1,195✔
98
        if (pbs_env.valid())
1,195✔
99
        {
100
            batch_name_ = "PBS";
×
101
            num_threads_ = pbs_env.num_threads();
×
102
            num_localities_ = pbs_env.num_localities();
×
103
            node_num_ = pbs_env.node_num();
×
104
            return;
×
105
        }
106
    }
1,197✔
107

108
    // This function returns true if a batch environment was found.
109
    bool batch_environment::found_batch_environment() const noexcept
1,761✔
110
    {
111
        return !batch_name_.empty();
1,761✔
112
    }
113

114
    // this function initializes the map of nodes from the given a list of nodes
115
    std::string batch_environment::init_from_nodelist(
×
116
        std::vector<std::string> const& nodes, std::string const& agas_host)
117
    {
118
        if (debug_)
×
119
            std::cerr << "got node list" << std::endl;
×
120

121
        std::string nodes_list;
×
122
        bool found_agas_host = false;
×
123

124
#if defined(HPX_HAVE_NETWORKING)
125
        asio::io_context io_service;
×
126

127
        std::size_t agas_node_num = 0;
×
128
        for (std::string const& s : nodes)
×
129
        {
130
            if (!s.empty())
×
131
            {
132
                if (debug_)
×
133
                    std::cerr << "extracted: '" << s << "'" << std::endl;
×
134

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

138
                if (!found_agas_host &&
×
139
                    ((agas_host.empty() && nodes_.empty()) || s == agas_host))
×
140
                {
141
                    agas_node_ = s;
×
142
                    found_agas_host = true;
×
143
                    agas_node_num_ = agas_node_num;
×
144
                }
×
145

146
                if (0 == nodes_.count(ep))
×
147
                {
148
                    if (debug_)
×
149
                        std::cerr << "incrementing agas_node_num" << std::endl;
×
150
                    ++agas_node_num;
×
151
                }
×
152

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

158
                nodes_list += s + ' ';
×
159
            }
×
160
        }
161
#endif
162

163
        // if an AGAS host is specified, it needs to be in the list of nodes
164
        // participating in this run
165
        if (!agas_host.empty() && !found_agas_host)
×
166
        {
167
            throw hpx::detail::command_line_error("Requested AGAS host (" +
×
168
                agas_host + ") not found in node list");
×
169
        }
170

171
        if (debug_)
×
172
        {
173
            if (!agas_node_.empty())
×
174
            {
175
                std::cerr << "using AGAS host: '" << agas_node_
×
176
                          << "' (node number " << agas_node_num_ << ")"
×
177
                          << std::endl;
×
178
            }
×
179

180
            std::cerr << "Nodes from nodelist:" << std::endl;
×
181
            node_map_type::const_iterator end = nodes_.end();
×
182
            for (node_map_type::const_iterator it = nodes_.begin(); it != end;
×
183
                 ++it)
×
184
            {
185
                std::cerr << (*it).second.first << ": " << (*it).second.second
×
186
                          << " (" << (*it).first << ")" << std::endl;
×
187
            }
×
188
        }
×
189
        HPX_UNUSED(nodes);
×
190
        return nodes_list;
×
191
    }
×
192

193
    // The number of threads is either one (if no PBS/SLURM information was
194
    // found), or it is the same as the number of times this node has been
195
    // listed in the node file. Additionally this takes into account the number
196
    // of tasks run on this node.
197
    std::size_t batch_environment::retrieve_number_of_threads() const noexcept
3,588✔
198
    {
199
        return num_threads_;
3,588✔
200
    }
201

202
    // The number of localities is either one (if no PBS information was found),
203
    // or it is the same as the number of distinct node names listed in the node
204
    // file. In case of SLURM we can extract the number of localities from the
205
    // job environment.
206
    std::size_t batch_environment::retrieve_number_of_localities()
1,196✔
207
        const noexcept
208
    {
209
        return num_localities_;
1,196✔
210
    }
211

212
    // Try to retrieve the node number from the PBS/SLURM environment
213
    std::size_t batch_environment::retrieve_node_number() const noexcept
598✔
214
    {
215
        return node_num_;
598✔
216
    }
217

218
    std::string batch_environment::host_name() const
×
219
    {
220
        std::string hostname = asio::ip::host_name();
×
221
        if (debug_)
×
222
            std::cerr << "asio host_name: " << hostname << std::endl;
×
223
        return hostname;
×
224
    }
×
225

226
    std::string batch_environment::host_name(
1,196✔
227
        std::string const& def_hpx_name) const
228
    {
229
        std::string host = nodes_.empty() ? def_hpx_name : host_name();
1,196✔
230
        if (debug_)
1,196✔
231
            std::cerr << "host_name: " << host << std::endl;
×
232
        return host;
1,196✔
233
    }
1,196✔
234

235
    // We either select the first host listed in the node file or a given host
236
    // name to host the AGAS server.
237
    std::string batch_environment::agas_host_name(
1,196✔
238
        std::string const& def_agas) const
239
    {
240
        std::string host = agas_node_.empty() ? def_agas : agas_node_;
1,196✔
241
        if (debug_)
1,196✔
242
            std::cerr << "agas host_name: " << host << std::endl;
×
243
        return host;
1,196✔
244
    }
1,196✔
245

246
    std::size_t batch_environment::agas_node() const noexcept
874✔
247
    {
248
        return agas_node_num_;
874✔
249
    }
250

251
    // Return a string containing the name of the batch system
252
    std::string batch_environment::get_batch_name() const
×
253
    {
254
        return batch_name_;
×
255
    }
256
}    // namespace hpx::util
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc