1 //  Copyright (c) 2007-2012 Hartmut Kaiser
2 //
3 //  Distributed under the Boost Software License, Version 1.0. (See accompanying
4 //  file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5 
6 #if !defined(HPX_UTIL_PBS_ENVIRONMENT_AUG_26_2011_0901AM)
7 #define HPX_UTIL_PBS_ENVIRONMENT_AUG_26_2011_0901AM
8 
9 #include <hpx/config.hpp>
10 #include <hpx/config/asio.hpp>
11 #include <hpx/util/spinlock.hpp>
12 #include <hpx/util_fwd.hpp>
13 
14 #include <boost/asio/ip/tcp.hpp>
15 
16 #include <cstddef>
17 #include <cstdlib>
18 #include <map>
19 #include <string>
20 #include <utility>
21 #include <vector>
22 
23 #if defined(HPX_MSVC_WARNING_PRAGMA)
24 #pragma warning(push)
25 #pragma warning(disable: 4251)
26 #endif
27 
28 namespace hpx { namespace util
29 {
30     ///////////////////////////////////////////////////////////////////////
31     // Try to retrieve default values from a batch environment
32     struct HPX_EXPORT batch_environment
33     {
34         // the constructor tries to read initial values from a batch environment,
35         // filling our map of nodes and thread counts
36         batch_environment(std::vector<std::string> & nodelist,
37             util::runtime_configuration const& cfg,
38             bool debug = false, bool enable = true);
39 
40         // this function initializes the map of nodes from the given (space
41         // separated) list of nodes
42         std::string init_from_nodelist(std::vector<std::string> const& nodes,
43             std::string const& agas_host);
44 
45         // The number of threads is either one (if no PBS information was
46         // found), or it is the same as the number of times this node has
47         // been listed in the node file.
48         std::size_t retrieve_number_of_threads() const;
49 
50         // The number of localities is either one (if no PBS information
51         // was found), or it is the same as the number of distinct node
52         // names listed in the node file.
53         std::size_t retrieve_number_of_localities() const;
54 
55         // Try to retrieve the node number from the PBS environment
56         std::size_t retrieve_node_number() const;
57 
58         std::string host_name() const;
59 
60         std::string host_name(std::string const& def_hpx_name) const;
61 
62         // We either select the first host listed in the node file or a given
63         // host name to host the AGAS server.
64         std::string agas_host_name(std::string const& def_agas) const;
65 
66         // The AGAS node number represents the number of the node which has
67         // been selected as the AGAS host.
agas_nodehpx::util::batch_environment68         std::size_t agas_node() const { return agas_node_num_; }
69 
70         // The function will analyze the current environment and return true
71         // if it finds sufficient information to deduce its running as a batch
72         // job.
73         bool found_batch_environment() const;
74 
75         // Return a string containing the name of the batch system
76         std::string get_batch_name() const;
77 
78         typedef std::map<
79             boost::asio::ip::tcp::endpoint, std::pair<std::string, std::size_t>
80         > node_map_type;
81 
82         std::string agas_node_;
83         std::size_t agas_node_num_;
84         std::size_t node_num_;
85         std::size_t num_threads_;
86         node_map_type nodes_;
87         std::size_t num_localities_;
88         std::string batch_name_;
89         bool debug_;
90     };
91 }}
92 
93 #if defined(HPX_MSVC_WARNING_PRAGMA)
94 #pragma warning(pop)
95 #endif
96 
97 #endif
98