• Stars
    star
    561
  • Rank 76,330 (Top 2 %)
  • Language
    C++
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Powerful multi-threaded coroutine dispatcher and parallel execution engine

Quantum Library : A scalable C++ coroutine framework

Build status

Quantum is a full-featured and powerful C++ framework build on top of the Boost coroutine library. The framework allows users to dispatch units of work (a.k.a. tasks) as coroutines and execute them concurrently using the 'reactor' pattern.

Features

  • NEW Added support for simpler V2 coroutine API which returns computed values directly.
  • Header-only library and interface-based design.
  • Full integration with Boost asymmetric coroutine library.
  • Highly parallelized coroutine framework for CPU-bound workloads.
  • Support for long-running or blocking IO tasks.
  • Allows explicit and implicit cooperative yielding between coroutines.
  • Task continuations and coroutine chaining for serializing work execution.
  • Synchronous and asynchronous dispatching using futures and promises similar to STL.
  • Support for streaming futures which allows faster processing of large data sets.
  • Support for future references.
  • Cascading execution output during task continuations (a.k.a. past futures).
  • Task prioritization.
  • Internal error handling and exception forwarding.
  • Ability to write lock-free code by synchronizing coroutines on dedicated queues.
  • Coroutine-friendly mutexes and condition variables for locking critical code paths or synchronizing access to external objects.
  • Fast pre-allocated memory pools for internal objects and coroutines.
  • Parallel forEach and mapReduce functions.
  • Various stats API.
  • Sequencer class allowing strict FIFO ordering of tasks based on sequence ids.

Sample code

Quantum is very simple and easy to use:

using namespace Bloomberg::quantum;

// Define a coroutine
int getDummyValue(CoroContextPtr<int> ctx)
{
    int value;
    ...           //do some work
    ctx->yield(); //be nice and let other coroutines run (optional cooperation)
    ...           //do more work and calculate 'value'
    return ctx->set(value);
}

// Create a dispatcher
Dispatcher dispatcher;

// Dispatch a work item to do some work and return a value
int result = dispatcher.post(getDummyValue)->get();

Chaining tasks can also be straightforward. In this example we produce various types in a sequence.

using namespace Bloomberg::quantum;

// Create a dispatcher
Dispatcher dispatcher;

auto ctx = dispatcher.postFirst([](CoroContextPtr<int> ctx)->int {
    return ctx->set(55); //Set the 1st value
})->then([](CoroContextPtr<double> ctx)->int {
    // Get the first value and add something to it
    return ctx->set(ctx->getPrev<int>() + 22.33); //Set the 2nd value
})->then([](CoroContextPtr<std::string> ctx)->int {
    return ctx->set("Hello world!"); //Set the 3rd value
})->finally([](CoroContextPtr<std::list<int>> ctx)->int {
    return ctx->set(std::list<int>{1,2,3}); //Set 4th value
})->end();

int i = ctx->getAt<int>(0); //This will throw 'FutureAlreadyRetrievedException'
                            //since future was already read in the 2nd coroutine
double d = ctx->getAt<double>(1); //returns 77.33
std::string s = ctx->getAt<std::string>(2); //returns "Hello world!";
std::list<int>& listRef = ctx->getRefAt<std::list<int>>(3); //get list reference
std::list<int>& listRef2 = ctx->getRef(); //get another list reference.
                                          //The 'At' overload is optional for last chain future
std::list<int> listValue = ctx->get(); //get list value

Chaining with the new V2 api:

using namespace Bloomberg::quantum;

// Create a dispatcher
Dispatcher dispatcher;

auto ctx = dispatcher.postFirst([](VoidContextPtr ctx)->int {
    return 55; //Set the 1st value
})->then([](VoidContextPtr ctx)->double {
    // Get the first value and add something to it
    return ctx->getPrev<int>() + 22.33; //Set the 2nd value
})->then([](VoidContextPtr ctx)->std::string {
    return "Hello world!"; //Set the 3rd value
})->finally([](VoidContextPtr ctx)->std::list<int> {
    return {1,2,3}; //Set 4th value
})->end();

Building and installing

Quantum is a header-only library and as such no targets need to be built. To install simply run:

> cmake -Bbuild <options> .
> cd build
> make install

CMake options

Various CMake options can be used to configure the output:

  • QUANTUM_BUILD_DOC : Build Doxygen documentation. Default OFF.
  • QUANTUM_ENABLE_DOT : Enable generation of DOT viewer files. Default OFF.
  • QUANTUM_VERBOSE_MAKEFILE : Enable verbose cmake output. Default ON.
  • QUANTUM_ENABLE_TESTS : Builds the tests target. Default OFF.
  • QUANTUM_BOOST_STATIC_LIBS: Link with Boost static libraries. Default ON.
  • QUANTUM_BOOST_USE_MULTITHREADED : Use Boost multi-threaded libraries. Default ON.
  • QUANTUM_USE_DEFAULT_ALLOCATOR : Use default system supplied allocator instead of Quantum's. Default OFF.
  • QUANTUM_ALLOCATE_POOL_FROM_HEAP : Pre-allocates object pools from heap instead of the application stack. Default OFF.
  • QUANTUM_BOOST_USE_SEGMENTED_STACKS : Use Boost segmented stacks for coroutines. Default OFF.
  • QUANTUM_BOOST_USE_PROTECTED_STACKS : Use Boost protected stacks for coroutines (slow!). Default OFF.
  • QUANTUM_BOOST_USE_FIXEDSIZE_STACKS : Use Boost fixed size stacks for coroutines. Default OFF.
  • QUANTUM_INSTALL_ROOT : Specify custom install path. Default is /usr/local/include for Linux or c:/Program Files for Windows.
  • QUANTUM_PKGCONFIG_DIR : Specify custom install path for the quantum.pc file. Default is ${QUANTUM_INSTALL_ROOT}/share/pkgconfig. To specify a relative path from QUANTUM_INSTALL_ROOT, omit leading /.
  • QUANTUM_EXPORT_PKGCONFIG : Generate quantum.pc file. Default ON.
  • QUANTUM_CMAKE_CONFIG_DIR : Specify a different install directory for the project's config, target and version files. Default is ${QUANTUM_INSTALL_ROOT}/share/cmake.
  • QUANTUM_EXPORT_CMAKE_CONFIG : Generate CMake config, target and version files. Default ON.
  • BOOST_ROOT : Specify a different Boost install directory.
  • GTEST_ROOT : Specify a different GTest install directory.

Note: options must be preceded with -D when passed as arguments to CMake.

Running tests

Run the following from the top directory:

> cmake -Bbuild -DQUANTUM_ENABLE_TESTS=ON <options> .
> cd build
> make quantum_test && ctest

Using

To use the library simply include <quantum/quantum.h> in your application. Also, the following libraries must be included in the link:

  • boost_context
  • pthread

Quantum library is fully is compatible with C++11, C++14 and C++17 language features. See compiler options below for more details.

Compiler options

The following compiler options can be set when building your application:

  • __QUANTUM_PRINT_DEBUG : Prints debug and error information to stdout and stderr respectively.
  • __QUANTUM_USE_DEFAULT_ALLOCATOR : Disable pool allocation for internal objects (other than coroutine stacks) and use default system allocators instead.
  • __QUANTUM_ALLOCATE_POOL_FROM_HEAP : Pre-allocates object pools from heap instead of the application stack (default). This affects internal object allocations other than coroutines. Coroutine pools are always heap-allocated due to their size.
  • __QUANTUM_BOOST_USE_SEGMENTED_STACKS : Uses boost segmented stack for on-demand coroutine stack growth. Note that Boost.Context library must be built with property segmented-stacks=on and applying BOOST_USE_UCONTEXT and BOOST_USE_SEGMENTED_STACKS at b2/bjam command line.
  • __QUANTUM_BOOST_USE_PROTECTED_STACKS : Uses boost protected stack for runtime bound-checking. When using this option, coroutine creation (but not runtime efficiency) becomes more expensive.
  • __QUANTUM_BOOST_USE_FIXEDSIZE_STACKS : Uses boost fixed size stack. This defaults to system default allocator.

Application-wide settings

Various application-wide settings can be configured via ThreadTraits, AllocatorTraits and StackTraits.

Documentation

Please see the wiki page for a detailed overview of this library, use-case scenarios and examples.

For class description visit the API reference page.

More Repositories

1

memray

Memray is a memory profiler for Python
Python
12,344
star
2

blazingmq

A modern high-performance open source message queuing system
C++
2,436
star
3

goldpinger

Debugging tool for Kubernetes which tests and displays connectivity between nodes in the cluster.
JavaScript
2,413
star
4

bde

Basic Development Environment - a set of foundational C++ libraries used at Bloomberg.
C++
1,542
star
5

comdb2

Bloomberg's distributed RDBMS
C
1,283
star
6

pystack

πŸ” 🐍 Like pstack but for Python!
Python
907
star
7

xcdiff

A tool which helps you diff xcodeproj files.
Swift
901
star
8

ipydatagrid

Fast Datagrid widget for the Jupyter Notebook and JupyterLab
TypeScript
484
star
9

foml

Foundations of Machine Learning
Handlebars
330
star
10

pytest-memray

pytest plugin for easy integration of memray memory profiler
Python
308
star
11

python-github-webhook

A framework for writing webhooks for GitHub, in Python.
Python
276
star
12

chromium.bb

Chromium source code and modifications
267
star
13

koan

A word2vec negative sampling implementation with correct CBOW update.
C++
261
star
14

blpapi-node

Bloomberg Open API module for node.js
C++
243
star
15

chef-bcpc

Bloomberg Clustered Private Cloud distribution
Python
228
star
16

phabricator-tools

Phabricator Tools
Python
221
star
17

scatteract

Project which implements extraction of data from scatter plots
Jupyter Notebook
207
star
18

record-tuple-polyfill

A polyfill for the ECMAScript Record and Tuple proposal.
JavaScript
159
star
19

pasta-sourcemaps

Pretty (and) Accurate Stack Trace Analysis is an extension to the JavaScript source map format that allows for accurate function name decoding.
TypeScript
159
star
20

collectdwin

CollectdWin - a system statistics collection daemon for Windows, inspired by 'collectd'
C#
123
star
21

clangmetatool

A framework for reusing code in Clang tools
C++
117
star
22

kubernetes-cluster-cookbook

Ruby
100
star
23

quant-research

A collection of projects published by Bloomberg's Quantitative Finance Research team.
Jupyter Notebook
95
star
24

blpapi-http

HTTP wrapper for Bloomberg Open API
TypeScript
83
star
25

amqpprox

An AMQP 0.9.1 proxy server, designed for use in front of an AMQP 0.9.1 compliant message queue broker such as RabbitMQ.
C++
71
star
26

spire-tpm-plugin

Provides agent and server plugins for SPIRE to allow TPM 2-based node attestation.
Go
68
star
27

bde-tools

Tools for developing and building libraries modeled on BDE
Perl
67
star
28

dataless-model-merging

Code release for Dataless Knowledge Fusion by Merging Weights of Language Models (https://openreview.net/forum?id=FCnohuR6AnM)
Python
65
star
29

repofactor

Tools for refactoring history of git repositories
Perl
63
star
30

chef-bach

Chef recipes for Bloomberg's deployment of Hadoop and related components
Ruby
60
star
31

minilmv2.bb

Our open source implementation of MiniLMv2 (https://aclanthology.org/2021.findings-acl.188)
Python
60
star
32

ntf-core

Sockets, timers, resolvers, events, reactors, proactors, and thread pools for asynchronous network programming
C++
60
star
33

wsk

A straightforward and maintainable build system from the Bloomberg Graphics team.
JavaScript
57
star
34

git-adventure-game

An adventure game to help people learn Git
Shell
55
star
35

attrs-strict

Provides runtime validation of attributes specified in Python 'attr'-based data classes.
Python
50
star
36

corokafka

C++ Kafka coroutine library using Quantum dispatcher and wrapping CppKafka
C++
49
star
37

cnn-rnf

Convolutional Neural Networks with Recurrent Neural Filters
Python
49
star
38

ppx_string_interpolation

PPX rewriter that enables string interpolation in OCaml
OCaml
44
star
39

selekt

A Kotlin and familiar Android SQLite database library that uses encryption.
Kotlin
44
star
40

bde_verify

Tool used to format, improve and verify code to BDE guidelines
C++
42
star
41

vault-auth-spire

vault-auth-spire is an authentication plugin for Hashicorp Vault which allows logging into Vault using a Spire provided SVID.
Go
41
star
42

rmqcpp

A batteries included C++ RabbitMQ Client Library/API.
C++
40
star
43

spark-flow

Library for organizing batch processing pipelines in Apache Spark
Scala
40
star
44

startup-python-bootcamp

35
star
45

chef-umami

A tool to automatically generate test code for Chef cookbooks and policies.
Ruby
34
star
46

p1160

P1160 Add Test Polymorphic Memory Resource To Standard Library
C++
33
star
47

pycsvw

A tool to read CSV files with CSVW metadata and transform them into other formats.
Python
32
star
48

bde-allocator-benchmarks

A set of benchmarking tools used to quantify the performance of BDE-style polymorphic allocators.
C++
31
star
49

blpapi-hs

Haskell interface to BLPAPI
Haskell
30
star
50

rwl-bench

A set of benchmark tools for reader/writer locks.
C++
28
star
51

entsum

Open Source / ENTSUM: A Data Set for Entity-Centric Extractive Summarization
Jupyter Notebook
27
star
52

bbit-learning-labs

Learning labs curated by BBIT
Python
26
star
53

consul-cluster-cookbook

Wrapper cookbook which installs and configures a Consul cluster.
Ruby
26
star
54

kbir_keybart

Experimental code used in pre-training the KBIR and KeyBART models
Python
26
star
55

presto-accumulo

Presto Accumulo Integration
Java
25
star
56

sgtb

Structured Gradient Tree Boosting
Python
25
star
57

python-comdb2

Python API to Bloomberg's comdb2 database.
Python
23
star
58

jupyterhub-kdcauthenticator

A Kerberos authenticator module for the JupyterHub platform
Python
22
star
59

docket

Tool to make running test suites easier, using docker-compose.
Go
21
star
60

tzcron

A parser of cron-style scheduling expressions.
Python
20
star
61

blazingmq-sdk-python

Python SDK for BlazingMQ, a modern high-performance open source message queuing system.
Python
20
star
62

constant.js

Immutable/Constant Objects for JavaScript
JavaScript
20
star
63

redis-cookbook

A set of Chef recipes for installing and configuring Redis.
HTML
19
star
64

userchroot

A tool to allow controlled access to 'chroot' functionality by users without root permissions
C
19
star
65

go-testgroup

Helps you organize tests in Go programs into groups.
Go
18
star
66

blazingmq-sdk-java

Java SDK for BlazingMQ, a modern high-performance open source message queuing system.
Java
18
star
67

nginx-cookbook

A set of Chef recipes for installing and configuring Nginx.
Ruby
17
star
68

zookeeper-cookbook

A set of Chef recipes for installing and configuring Apache Zookeeper.
Ruby
17
star
69

mynexttalk

16
star
70

chef-bcs

Bloomberg Cloud Storage Chef application
Ruby
16
star
71

vault-cluster-cookbook

Application cookbook which installs and configures Vault with Consul as a backend.
Ruby
15
star
72

git-adventure-game-builder

A set of tools for building a Git adventure game, to help people learn Git
Shell
15
star
73

emnlp20_depsrl

Research code and scripts used in the paper Semantic Role Labeling as Syntactic Dependency Parsing.
Python
14
star
74

MixCE-acl2023

Implementation of MixCE method described in ACL 2023 paper by Zhang et al.
Python
14
star
75

k8eraid

A relatively simple, unified method for reporting on Kubernetes resource issues.
Go
12
star
76

hackathon-aws-cluster

HTML
11
star
77

coffeechat

A simple web application for arranging 'chats over coffee'.
TypeScript
11
star
78

fast-noise-aware-topic-clustering

Research code and scripts used in the Silburt et al. (2021) EMNLP 2021 paper 'FANATIC: FAst Noise-Aware TopIc Clustering'
Python
10
star
79

emnlp21_fewrel

Code to reproduce the results of the paper 'Towards Realistic Few-Shot Relation Extraction' (EMNLP 2021)
Python
10
star
80

mastering-difficult-conversations

Plan It, Say It, Nail It: Mastering Difficult Conversations
10
star
81

wsk-notify

Simple, customizable console notifications.
JavaScript
10
star
82

jenkins-cluster-cookbook

Ruby
9
star
83

decorator-taxonomy

A taxonomy of Python decorator types.
HTML
9
star
84

pytest-pystack

Pytest plugin that runs PyStack on slow or hanging tests.
Python
9
star
85

tdd-labs

Problems and Solutions for Test-Driven-Development training
JavaScript
9
star
86

argument-relation-transformer-acl2022

This repository contains code for our ACL 2022 Findings paper `Efficient Argument Structure Extraction with Transfer Learning and Active Learning`. We implement an argument structure extraction method based on a pre-trained Transformer model.`
Python
9
star
87

sigir2018-kg-contextualization

8
star
88

bloomberg.github.io

Source code for the https://bloomberg.github.io site
HTML
8
star
89

locking_resource-cookbook

Chef cookbook for serializing access to resources
Ruby
7
star
90

datalake-query-ingester

Python
7
star
91

cobbler-cookbook

A Chef cookbook for installing and maintaining Cobbler
Ruby
7
star
92

p2473

Example code for WG21 paper P2473
Perl
6
star
93

collectd-cookbook

Ruby
6
star
94

Catalyst-Authentication-Credential-GSSAPI

A module that provides integration of the Catalyst web application framework with GSSAPI/SPNEGO HTTP authentication.
Perl
6
star
95

bob-bot

Java
5
star
96

.github

Organization-wide community files
5
star
97

jenkins-procguard

Perl
5
star
98

datalake-query-db-consumer

Python
4
star
99

wsk.example

A sample starter project using wsk.
JavaScript
4
star
100

datalake-metrics-db

Python
3
star