mCRL2
Loading...
Searching...
No Matches
parallel_tool.h
Go to the documentation of this file.
1// Author(s): Jan Friso Groote
2// Copyright: see the accompanying file COPYING or copy at
3// https://github.com/mCRL2org/mCRL2/blob/master/COPYING
4//
5// Distributed under the Boost Software License, Version 1.0.
6// (See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//
11
12#ifndef MCRL2_UTILITIES_PARALLEL_TOOL_H
13#define MCRL2_UTILITIES_PARALLEL_TOOL_H
14
17
18namespace mcrl2
19{
20
21namespace utilities
22{
23
24namespace tools
25{
26
28template <typename Tool>
29class parallel_tool: public Tool
30{
31 protected:
33 std::size_t m_number_of_threads=1;
34
37 void add_options(utilities::interface_description& desc)
38 {
39 Tool::add_options(desc);
41 {
42 desc.add_option("threads", utilities::make_mandatory_argument("NUM"), "run with NUM threads (default=1). With multiple threads the stack size on a Mac is limited which can lead to bus errors. ");
43 }
44 else
45 {
46 desc.add_option("threads", utilities::make_mandatory_argument("NUM"), "run with NUM threads (default=1). This option is not available as this tool is compiled as a sequential tool.");
47 }
48 }
49
50
53 void parse_options(const utilities::command_line_parser& parser)
54 {
55 Tool::parse_options(parser);
56
57 if (parser.has_option("threads"))
58 {
59 m_number_of_threads = parser.option_argument_as<std::size_t>("threads");
61 {
62 throw mcrl2::runtime_error("The number of threads should at least be 1.");
63 }
65 {
66 throw mcrl2::runtime_error("This tool is compiled for sequential use. The number of threads (now: " +
67 std::to_string(number_of_threads()) +
68 ") can only be 1.");
69 }
70 }
71 }
72
73 public:
74
76 parallel_tool(const std::string& name,
77 const std::string& author,
78 const std::string& what_is,
79 const std::string& tool_description,
80 std::string known_issues = ""
81 )
82 : Tool(name, author, what_is, tool_description, known_issues)
83 {}
84
87 std::size_t number_of_threads() const
88 {
90 }
91};
92
93} // namespace tools
94
95} // namespace utilities
96
97} // namespace mcrl2
98
99#endif // MCRL2_UTILITIES_PARALLEL_TOOL_H
Standard exception class for reporting runtime errors.
Definition exception.h:27
Base class for tools that are using multiple threads.
void add_options(utilities::interface_description &desc)
Add the –threads option to an interface description.
std::size_t m_number_of_threads
The number of threads in the parallel tool.
void parse_options(const utilities::command_line_parser &parser)
Parse non-standard options.
parallel_tool(const std::string &name, const std::string &author, const std::string &what_is, const std::string &tool_description, std::string known_issues="")
Constructor.
std::size_t number_of_threads() const
Returns the number of threads in this tool.
Components for command line interfaces of mCRL2 tools.
static constexpr bool GlobalThreadSafe
Enables thread safety for the whole toolset.
interface_description::mandatory_argument< std::string > make_mandatory_argument(std::string const &name, std::string const &default_value)
A class that takes a linear process specification and checks all tau-summands of that LPS for conflue...
Definition indexed_set.h:72