Skip to content

Commit 6c9d3be

Browse files
committed
Adding locality parameter to python execution interface
- flyby: adding sleep primitive
1 parent 1925853 commit 6c9d3be

18 files changed

Lines changed: 669 additions & 222 deletions

File tree

phylanx/execution_tree/compiler/actors.hpp

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,49 @@ namespace phylanx { namespace execution_tree { namespace compiler
173173
return extract_copy_value(arg_, name_);
174174
}
175175

176+
// evaluate object itself and use the returned value to
177+
// asynchronously evaluate the arguments
178+
hpx::shared_future<result_type> async(
179+
arguments_type const& args, eval_context ctx) const
180+
{
181+
if (is_primitive_operand(arg_))
182+
{
183+
arguments_type params;
184+
params.reserve(args.size());
185+
for (auto const& arg : args)
186+
{
187+
params.emplace_back(extract_ref_value(arg, name_));
188+
}
189+
190+
return value_operand(arg_, std::move(params), name_).share();
191+
}
192+
return hpx::make_ready_future(extract_copy_value(arg_, name_))
193+
.share();
194+
}
195+
196+
hpx::shared_future<result_type> async(
197+
arguments_type&& args, eval_context ctx) const
198+
{
199+
if (is_primitive_operand(arg_))
200+
{
201+
arguments_type keep_alive(std::move(args));
202+
203+
// construct argument-pack to use for actual call
204+
arguments_type params;
205+
params.reserve(keep_alive.size());
206+
for (auto const& arg : keep_alive)
207+
{
208+
params.emplace_back(extract_ref_value(arg, name_));
209+
}
210+
211+
return value_operand(
212+
arg_, std::move(params), name_, "<unknown>", std::move(ctx))
213+
.share();
214+
}
215+
return hpx::make_ready_future(extract_copy_value(arg_, name_))
216+
.share();
217+
}
218+
176219
using kwarguments_type = std::map<std::string, primitive_argument_type>;
177220

178221
result_type operator()(arguments_type&& args, kwarguments_type&& kwargs,
@@ -222,6 +265,53 @@ namespace phylanx { namespace execution_tree { namespace compiler
222265
return extract_copy_value(arg_, name_);
223266
}
224267

268+
hpx::shared_future<result_type> async(arguments_type&& args,
269+
kwarguments_type&& kwargs, eval_context ctx) const
270+
{
271+
if (is_primitive_operand(arg_))
272+
{
273+
arguments_type keep_alive(std::move(args));
274+
kwarguments_type kw_keep_alive(std::move(kwargs));
275+
276+
// construct argument-pack to use for actual call
277+
arguments_type params;
278+
params.reserve(keep_alive.size() + num_named_args_);
279+
for (auto const& arg : keep_alive)
280+
{
281+
params.emplace_back(extract_ref_value(arg, name_));
282+
}
283+
284+
// fill in the given named arguments at their correct positions
285+
for (auto const& kwarg : kw_keep_alive)
286+
{
287+
auto it = std::find(named_args_.get(),
288+
named_args_.get() + num_named_args_, kwarg.first);
289+
if (it == named_args_.get() + num_named_args_)
290+
{
291+
HPX_THROW_EXCEPTION(hpx::bad_parameter,
292+
"function::operator()",
293+
hpx::util::format("cannot locate requested "
294+
"named argument '{}'", kwarg.first));
295+
}
296+
297+
std::ptrdiff_t kwarg_pos =
298+
std::distance(named_args_.get(), it);
299+
if (kwarg_pos >= std::ptrdiff_t(params.size()))
300+
{
301+
params.resize(kwarg_pos + 1);
302+
}
303+
304+
params[kwarg_pos] = extract_ref_value(kwarg.second, name_);
305+
}
306+
307+
return value_operand(
308+
arg_, std::move(params), name_, "<unknown>", std::move(ctx))
309+
.share();
310+
}
311+
return hpx::make_ready_future(extract_copy_value(arg_, name_))
312+
.share();
313+
}
314+
225315
template <typename T1, typename ... Ts>
226316
typename std::enable_if<
227317
!std::is_same<eval_context, typename std::decay<T1>::type>::value,

phylanx/plugins/controls/controls.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <phylanx/plugins/controls/parallel_block_operation.hpp>
2020
#include <phylanx/plugins/controls/parallel_map_operation.hpp>
2121
#include <phylanx/plugins/controls/range_operation.hpp>
22+
#include <phylanx/plugins/controls/sleep_operation.hpp>
2223
#include <phylanx/plugins/controls/while_operation.hpp>
2324

2425
#endif
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
// Copyright (c) 2020 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(PHYLANX_SLEEP_OPERATION_APR_24_2020_0840AM)
7+
#define PHYLANX_SLEEP_OPERATION_APR_24_2020_0840AM
8+
9+
#include <phylanx/config.hpp>
10+
#include <phylanx/execution_tree/primitives/base_primitive.hpp>
11+
#include <phylanx/execution_tree/primitives/primitive_component_base.hpp>
12+
13+
#include <hpx/lcos/future.hpp>
14+
15+
#include <string>
16+
#include <utility>
17+
18+
namespace phylanx { namespace execution_tree { namespace primitives {
19+
20+
class sleep_operation : public primitive_component_base
21+
{
22+
public:
23+
static match_pattern_type const match_data;
24+
25+
sleep_operation() = default;
26+
27+
sleep_operation(primitive_arguments_type&& operands,
28+
std::string const& name, std::string const& codename);
29+
30+
protected:
31+
hpx::future<primitive_argument_type> eval(
32+
primitive_arguments_type const& operands,
33+
primitive_arguments_type const& args,
34+
eval_context ctx) const override;
35+
};
36+
37+
inline primitive create_sleep_operation(hpx::id_type const& locality,
38+
primitive_arguments_type&& operands, std::string const& name = "",
39+
std::string const& codename = "")
40+
{
41+
return create_primitive_component(
42+
locality, "sleep", std::move(operands), name, codename);
43+
}
44+
}}} // namespace phylanx::execution_tree::primitives
45+
46+
#endif

0 commit comments

Comments
 (0)