Boost logo

Boost :

Subject: Re: [boost] Boost.Pipeline -- scheduling of segments
From: Hartmut Kaiser (hartmut.kaiser_at_[hidden])
Date: 2014-07-10 11:42:57


> > I've put together some slides to show what I'm thinking of and make sure
> > we
> > are on the same page:
> > http://www.slideshare.net/erenon/boostpipeline-scheduling-of-segments-
> > 36832455
> >
> > To point here, assuming a pipeline, one can use extra information to
> make
> > some educated guesses regarding scheduling: Yield to offending queue
> > (upstream if input is empty, downstream if output is full), choose
> > specific
> > segment to optimize latency.
> >
> > Probably this can be achieved using fibers, or even with coroutines.
> >
> > Due to the complexity of HPX I'm not sure how does it compare.
>
> Huh? Complexity? It's 100% API compatible to C++11 and various proposals
> to C++14/17.
> I'd like to know more about why you think HPX is complex.

I added a much simplified implementation of what you described in your
slides. Most of the complexity lies in the operator&, not it the HPX code
itself.

#include <hpx/hpx.hpp>
#include <hpx/hpx_main.hpp>

#include <iostream>
#include <string>

#include <boost/algorithm/string/trim.hpp>

hpx::future<std::string> read()
{
    std::string s(" foo ");
    return hpx::make_ready_future(s);
}

hpx::future<std::string> process(std::string const& input)
{
    return
        hpx::async(
            [](std::string const& s)
                { return boost::algorithm::trim_copy(s); },
            input
        );
}

hpx::future<void> write(std::string const& input)
{
    return
        hpx::async(
            [](std::string const& s)
 t { std::cout << "->" << s << "<-" << std::endl; },
            input
        );
}

///////////////////////////////////////////////////////////////////////////
struct future_identity
{
    template <typename Future>
    Future operator() (Future && f) const
    {
        return f;
    }
};

template <typename F1, typename F2>
auto operator& (F1 && f1, F2 && f2) ->
    decltype(hpx::util::bind(future_identity(),
        f1().then(hpx::util::unwrapped(f2)))
    )
{
    return hpx::util::bind(future_identity(),
        f1().then(hpx::util::unwrapped(f2)));
}

int main()
{
    auto read_step = []() { return read(); };

    auto result = read_step & process & write;
    result();

    return 0;
}

HTH
Regards Hartmut
---------------
http://boost-spirit.com
http://stellar.cct.lsu.edu


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk