• 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

13.43
/libs/core/batch_environments/src/pbs_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/batch_environments/pbs_environment.hpp>
9
#include <hpx/modules/errors.hpp>
10
#include <hpx/modules/format.hpp>
11
#include <hpx/util/from_string.hpp>
12

13
#include <cstddef>
14
#include <fstream>
15
#include <iostream>
16
#include <set>
17
#include <string>
18
#include <vector>
19

20
namespace hpx::util::batch_environments {
21

22
    pbs_environment::pbs_environment(
1,195✔
23
        std::vector<std::string>& nodelist, bool have_mpi, bool debug)
24
      : node_num_(std::size_t(-1))
1,195✔
25
      , num_localities_(std::size_t(-1))
1,195✔
26
      , num_threads_(std::size_t(-1))
1,195✔
27
      , valid_(false)
1,195✔
28
    {
29
        char* node_num = std::getenv("PBS_NODENUM");
1,195✔
30
        valid_ = node_num != nullptr;
1,195✔
31
        if (valid_)
1,195✔
32
        {
33
            // Initialize our node number
34
            node_num_ = from_string<std::size_t>(node_num, std::size_t(1));
×
35

36
            if (nodelist.empty())
×
37
            {
38
                // read the PBS node file. This initializes the number of
39
                // localities
40
                read_nodefile(nodelist, have_mpi, debug);
×
41
            }
×
42
            else
43
            {
44
                // read the PBS node list. This initializes the number of
45
                // localities
46
                read_nodelist(nodelist, debug);
×
47
            }
48

49
            char* thread_num = std::getenv("PBS_NUM_PPN");
×
50
            if (thread_num != nullptr)
×
51
            {
52
                // Initialize number of cores to run on
53
                num_threads_ =
×
54
                    from_string<std::size_t>(thread_num, std::size_t(-1));
×
55
            }
×
56
        }
×
57
    }
1,195✔
58

59
    void pbs_environment::read_nodefile(
×
60
        std::vector<std::string>& nodelist, bool have_mpi, bool debug)
61
    {
62
        char* node_file = std::getenv("PBS_NODEFILE");
×
63
        if (!node_file)
×
64
        {
65
            valid_ = false;
×
66
            return;
×
67
        }
68

69
        std::ifstream ifs(node_file);
×
70
        if (ifs.is_open())
×
71
        {
72
            std::set<std::string> nodes;
×
73
            typedef std::set<std::string>::iterator nodes_iterator;
74

75
            bool fill_nodelist = nodelist.empty();
×
76

77
            if (debug)
×
78
                std::cerr << "opened: " << node_file << std::endl;
×
79

80
            std::string line;
×
81
            while (std::getline(ifs, line))
×
82
            {
83
                if (!line.empty())
×
84
                {
85
                    nodes_iterator it = nodes.find(line);
×
86
                    if (it == nodes.end())
×
87
                    {
88
                        nodes.insert(line);
×
89
                        if (fill_nodelist)
×
90
                        {
91
                            nodelist.push_back(line);
×
92
                        }
×
93
                    }
×
94
                }
×
95
            }
96
            num_localities_ = nodes.size();
×
97
        }
×
98
        else
99
        {
100
            if (debug)
×
101
                std::cerr << "failed opening: " << node_file << std::endl;
×
102

103
            // if MPI is active we can ignore the missing node-file
104
            if (have_mpi)
×
105
            {
106
                return;
×
107
            }
108

109
            // raise hard error if nodefile could not be opened
110
            throw hpx::detail::command_line_error(
×
111
                hpx::util::format("Could not open nodefile: '{}'", node_file));
×
112
        }
113
    }
×
114

115
    void pbs_environment::read_nodelist(
×
116
        std::vector<std::string>& nodelist, bool debug)
117
    {
118
        if (nodelist.empty())
×
119
        {
120
            valid_ = false;
×
121
            return;
×
122
        }
123

124
        std::set<std::string> nodes;
×
125
        typedef std::set<std::string>::iterator nodes_iterator;
126

127
        if (debug)
×
128
            std::cerr << "parsing nodelist" << std::endl;
×
129

130
        for (std::string const& s : nodelist)
×
131
        {
132
            if (!s.empty())
×
133
            {
134
                nodes_iterator it = nodes.find(s);
×
135
                if (it == nodes.end())
×
136
                {
137
                    nodes.insert(s);
×
138
                }
×
139
            }
×
140
        }
141
        num_localities_ = nodes.size();
×
142
    }
×
143
}    // namespace hpx::util::batch_environments
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