Giter VIP home page Giter VIP logo

conveyorpp's Introduction

conveyorpp

A simple С++ library for building conveyor-like pipelines

Build Status

Description

This library allows users to easily create linear parallel pipelines. For instance. imagine you have three functions f1, f2 and f3, and your result is calculated like

output = f3(f2(f1(input)));

So, if you continuously feed this pipeline with data, your timing looks like this:

f1: |XXXXXX|..............|XXXXXX|..............|XXXXXX|..............
f2: .......|XXXXXXXXXX|..........|XXXXXXXXXX|..........|XXXXXXXXXX|...
f3: ..................|XX|..................|XX|..................|XX|

An easy way o speed up the process is to execute the function chain in parallel, i.e. create several threads for each f3(f2(f1(...))) call. However, sometimes it is not possible, e.g. your functions depend on some hardware calculation modules with exclusive access or aren't reentrant.

Conveyourpp lib solves this problems by simplifying building of a parallel worker chain. For instance, the example above with conveyorpp (with zero-queue settings) looks like this:

f1: |XXXXXX||XXXXXX|...|XXXXXX|....|XXXXXX|....|XXXXXX|....
f2: .......|XXXXXXXXXX||XXXXXXXXXX||XXXXXXXXXX||XXXXXXXXXX|
f3: ..................|XX|........|XX|........|XX|.........

So if your calculation can be divided in several stages, you can utilize all the computational power you've got.

Installation

To install conveyourpp, clone this repository and perform the following actions:

mkdir build && cd build
cmake ..
make

Optionally you can install it via

sudo make install

Usage

Usual functions

Imagine you have three functions:

int f1(float);
double f2(int);
bool f3(double);

You can parallelize their execution by:

auto chainer = cnvpp::MakeChainer(f1, f2, f3);

This line of code creates execution chain f1->f2->f3, which is equivalent to f3(f2(f1(...))) To feed this conveyor with input data, simply call:

int x = 42;
chainer.Call(x);

To obtain result of the computation, call

auto result = chainer.GetResult();

Method GetResult blocks until result is available. If the last function's return type is void,method GetResult is excluded from compilation.

Lambdas

Lambda-functions need to be processed with some special care. In particular, user has to manually describe their input and output types, e.g.

double multiplier = 2.5;
auto l1 = [=] (int x) { return (float)x * multiplier; };
auto l2 = [&] (float y) { return (size_t)(y / multiplier + 1); };

auto chainer = cnvpp::MakeChainer(
  cnvpp::LambdaWrapper<float, int>(l1),
  cnvpp::LambdaWrapper<size_t, float>(l2),
};

Roadmap

  • Add more test and examples
  • Add more documentation and diagrams
  • Find a way to get rid of LambdaWrapper class and handle functions, class methods and lambdas in a unified way
  • Make internal queuing mechanism more customizable (at the current moment each conveyor stage has internal queue with size 5)
  • Add mechanisms for auto-balancing the load (e.g. user adds a sequence of actions to perform, and conveyorpp's runtime determines optimal amount of threads to use, not just execute each stage in a separate thread)

conveyorpp's People

Contributors

atanzu avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.