【A common used C++ & Python DAG framework】 一个通用的、无三方依赖的、跨平台的、收录于awesome-cpp的、基于流图的并行计算框架。欢迎star & fork & 交流
See the code中文 | English Readme | deepwiki
CGraph is a cross-platform Directed Acyclic Graph framework based on pure C++ without any 3rd-party dependencies.
You, with it, can build your own operators simply, and describe any running schedules as you need, such as dependence, parallelling, aggregation, conditional and so on. Python APIs are also supported to build your pipeline.
Tutorials and contact information are shown as follows. Please get in touch with us for free if you need more about this repository.
CGraph中文名为【色丶图】,是一套无任何第三方依赖的跨平台图流程执行框架。通过GPipeline(流水线)底层调度,提供了包含依赖元素依次执行、非依赖元素并发执行,支持暂停、恢复、超时设定的 eDAG 调度功能。
使用者只需继承GNode(节点)类,实现子类的run()方法,并根据需要设定依赖关系,即可实现任务的图化执行或流水线执行。还可以通过设定各种包含多节点信息的GGroup(组),自行控制图的条件判断、循环和并发执行逻辑。
本工程使用纯C++11标准库编写,无任何第三方依赖,兼容MacOS、Linux、Windows和Android系统。支持本地编译和二次开发,并且提供Python版本:pycgraph。编译和安装方法,请参考 CGraph 编译说明
详细功能介绍和用法,请参考 一面之猿网 中的文章内容。相关视频在B站持续更新中,欢迎观看和交流:
#include "CGraph.h"
using namespace CGraph;
class MyNode1 : public GNode {
public:
CStatus run() override {
printf("[%s], sleep for 1 second ...\n", this->getName().c_str());
CGRAPH_SLEEP_SECOND(1)
return CStatus();
}
};
class MyNode2 : public GNode {
public:
CStatus run() override {
printf("[%s], sleep for 2 second ...\n", this->getName().c_str());
CGRAPH_SLEEP_SECOND(2)
return CStatus();
}
};
int main() {
/* 创建一个流水线,用于设定和执行流图信息 */
GPipelinePtr pipeline = GPipelineFactory::create();
GElementPtr a, b, c, d = nullptr;
/* 注册节点之间的依赖关系 */
pipeline->registerGElement<MyNode1>(&a, {}, "nodeA");
pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB");
pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");
pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD");
/* 执行流图框架 */
pipeline->process();
/* 清空流水线中所有的资源 */
GPipelineFactory::remove(pipeline);
return 0;
}
如上图所示,图结构执行的时候,首先执行a节点。a节点执行完毕后,并行执行b和c节点。b和c节点全部执行完毕后,再执行d节点。
# pip install pycgraph
import time
from datetime import datetime
from pycgraph import GNode, GPipeline, CStatus
class MyNode1(GNode):
def run(self):
print("[{0}] {1}, sleep for 1 second ... ".format(datetime.now(), self.getName()))
time.sleep(1)
return CStatus()
class MyNode2(GNode):
def run(self):
print("[{0}] {1}, sleep for 2 second ... ".format(datetime.now(), self.getName()))
time.sleep(2)
return CStatus()
if __name__ == '__main__':
pipeline = GPipeline()
a, b, c, d = MyNode1(), MyNode2(), MyNode1(), MyNode2()
pipeline.registerGElement(a, set(), "nodeA")
pipeline.registerGElement(b, {a}, "nodeB")
pipeline.registerGElement(c, {a}, "nodeC")
pipeline.registerGElement(d, {b, c}, "nodeD")
pipeline.process()
[2021.05.04 - v1.0.0 - Chunel]
[2021.05.09 - v1.1.0 - Chunel]
[2021.05.18 - v1.1.1 - Chunel]
name和session信息[2021.05.23 - v1.2.0 - Chunel]
[2021.05.29 - v1.3.0 - Chunel]
cluster(簇)和region(区域)划分和循环执行功能tutorial内容,包含多种使用样例[2021.06.14 - v1.4.0 - Chunel]
param(参数)传递机制group(组)功能,多节点模块统一继承自group模块[2021.06.20 - v1.4.1 - Chunel]
condition(条件)功能[2021.06.24 - v1.5.0 - Chunel]
pipeline工厂创建方法tutorial内容[2021.07.07 - v1.5.1 - Chunel]
[2021.07.11 - v1.5.2 - Chunel]
[2021.07.31 - v1.5.3 - Chunel]
[2021.08.29 - v1.6.0 - Chunel]
pipeline功能,优化底层逻辑tutorial内容[2021.09.19 - v1.6.1 - Chunel]
Lru算子、Trie算子和模板节点功能,优化底层逻辑tutorial内容[2021.09.29 - v1.7.0 - Chunel]
aspect(切面)功能,用于横向扩展node或group功能tutorial内容[2021.10.07 - v1.7.1 - Chunel]
aspect(切面)实现逻辑,提供切面参数功能,提供批量添加切面功能tutorial内容[2021.11.01 - v1.8.0 - Chunel]
adapter(适配器)功能,提供singleton适配器功能pipeline执行逻辑tutorial内容[2021.12.18 - v1.8.1 - Chunel]
CStatus信息[2022.01.02 - v1.8.2 - Chunel]
task group(任务组)功能[2022.01.23 - v1.8.3 - Chunel]
function适配器,实现函数式编程功能tutorial内容[2022.01.31 - v1.8.4 - Chunel]
node(节点)异步执行的功能[2022.02.03 - v1.8.5 - Chunel]
daemon(守护)功能,用于定时执行非流图中任务tutorial内容[2022.04.03 - v1.8.6 - Chunel]
DistanceCalculator算子,用于实现任意数据类型、任意距离类型的计算tutorial内容[2022.04.05 - v2.0.0 - Chunel]
domain(领域)功能,提供Ann领域抽象模型,开始支持个别专业方向tutorial内容[2022.05.01 - v2.0.1 - Chunel]
pipeline注册机制,支持init方法自定义顺序执行[2022.05.29 - v2.1.0 - Chunel]
element参数写入方法tutorial内容[2022.10.03 - v2.1.1 - Chunel]
group执行逻辑[2022.11.03 - v2.2.0 - Chunel]
message(消息)功能,主要用于完成不同pipeline之间的数据传递tutorial内容[2022.12.24 - v2.2.1 - Chunel]
TemplateNode(模板节点)功能,用于优化参数传参方式tutorial内容[2022.12.25 - v2.2.2 - yeshenyong]
[2022.12.30 - v2.2.3 - Chunel]
message发布订阅功能[2023.01.21 - v2.3.0 - Chunel]
event(事件)功能CGraph Intro.xmind文件,通过脑图的方式,介绍了CGraph的整体逻辑[2023.01.25 - v2.3.1 - Chunel]
[2023.02.10 - v2.3.2 - Chunel]
[2023.02.12 - v2.3.3 - yeshenyong, Chunel]
[2023.02.22 - v2.3.4 - Chunel]
param机制和event(事件)机制[2023.03.25 - v2.4.0 - woodx, Chunel]
pipeline调度资源管控机制[2023.05.05 - v2.4.1 - Chunel]
pipeline最大并发度获取方法。感谢 Hanano-Yuuki 提供相关解决方案pipeline异步执行功能和执行时退出功能[2023.06.17 - v2.4.2 - Chunel]
MultiCondition(多条件)功能pipeline暂停执行和恢复执行功能[2023.07.12 - v2.4.3 - Chunel]
CStatus功能,添加了异常定位信息[2023.09.05 - v2.5.0 - Chunel]
pipeline的性能分析element的超时机制some(部分)功能,优化pipeline的异步执行方式[2023.09.15 - v2.5.1 - Chunel]
fence(栅栏)功能coordinator(协调)功能[2023.11.06 - v2.5.2 - Chunel]
message(消息)功能,可以设定写入阻塞时的处理方式,减少内存copy次数example相关内容,针对不同行业,提供一些简单实现[2023.11.15 - v2.5.3 - Chunel]
proto定义文件mutable(异变)功能,提供依赖关系注册语法糖[2024.01.05 - v2.5.4 - Chunel]
test内容,包含性能和功能方面的测试用例event(事件)机制,支持异步等待功能[2024.07.18 - v2.6.0 - PaPaPig-Melody, Chunel]
pipeline的拓扑执行的方式element之间是否有依赖关系的方法[2024.09.17 - v2.6.1 - Chunel]
pipeline的静态执行的方式,提供基于静态执行的微任务机制pipeline剪裁功能,用于删除element之间重复的依赖element删除依赖的方法event(事件)机制,异步事件可以等待结束[2024.11.16 - v2.6.2 - Chunel]
tutorial内容[2025.03.16 - v3.0.0 - Chunel]
stage(阶段)功能,用于element之间同步运行tutorial内容[2025.05.04 - v3.1.0 - Chunel]
pip3 install PyCGraph 安装[2025.06.15 - v3.1.1 - Chunel]
CODE_OF_CONDUCT.md 文档[2025.09.06 - v3.1.2 - Chunel]
message 功能aspect 功能[2025.11.08 - v3.2.2 - Chunel]
PyCGraph 为 pycgraph,支持 pip3 install pycgraph 安装[2026.03.24 - v3.2.3 - Chunel]
message 功能[2026.05.10 - v3.2.4 - Chunel]
pycgraph 功能[2026.08.15 - v3.2.5 - Chunel]
pycgraph 功能GSome 使用方式[2026.08.22 - v3.3.0 - Chunel]
GParam 的 trace 功能pycgraph 功能
Taskflow Group: awesome-parallel-computing, and we always treat taskflow as a role modelCGraph项目提出的意见和建议的朋友,在此不一一提及。随时欢迎大家加入,一起共建277 followers · starred Sep 2023
9 followers · starred Jul 2024
10 followers · starred Nov 2023
9 followers · starred Sep 2025
【A common used C++ & Python DAG framework】 一个通用的、无三方依赖的、跨平台的、收录于awesome-cpp的、基于流图的并行计算框架。欢迎star & fork & 交流
See the code中文 | English Readme | deepwiki
CGraph is a cross-platform Directed Acyclic Graph framework based on pure C++ without any 3rd-party dependencies.
You, with it, can build your own operators simply, and describe any running schedules as you need, such as dependence, parallelling, aggregation, conditional and so on. Python APIs are also supported to build your pipeline.
Tutorials and contact information are shown as follows. Please get in touch with us for free if you need more about this repository.
CGraph中文名为【色丶图】,是一套无任何第三方依赖的跨平台图流程执行框架。通过GPipeline(流水线)底层调度,提供了包含依赖元素依次执行、非依赖元素并发执行,支持暂停、恢复、超时设定的 eDAG 调度功能。
使用者只需继承GNode(节点)类,实现子类的run()方法,并根据需要设定依赖关系,即可实现任务的图化执行或流水线执行。还可以通过设定各种包含多节点信息的GGroup(组),自行控制图的条件判断、循环和并发执行逻辑。
本工程使用纯C++11标准库编写,无任何第三方依赖,兼容MacOS、Linux、Windows和Android系统。支持本地编译和二次开发,并且提供Python版本:pycgraph。编译和安装方法,请参考 CGraph 编译说明
详细功能介绍和用法,请参考 一面之猿网 中的文章内容。相关视频在B站持续更新中,欢迎观看和交流:
#include "CGraph.h"
using namespace CGraph;
class MyNode1 : public GNode {
public:
CStatus run() override {
printf("[%s], sleep for 1 second ...\n", this->getName().c_str());
CGRAPH_SLEEP_SECOND(1)
return CStatus();
}
};
class MyNode2 : public GNode {
public:
CStatus run() override {
printf("[%s], sleep for 2 second ...\n", this->getName().c_str());
CGRAPH_SLEEP_SECOND(2)
return CStatus();
}
};
int main() {
/* 创建一个流水线,用于设定和执行流图信息 */
GPipelinePtr pipeline = GPipelineFactory::create();
GElementPtr a, b, c, d = nullptr;
/* 注册节点之间的依赖关系 */
pipeline->registerGElement<MyNode1>(&a, {}, "nodeA");
pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB");
pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");
pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD");
/* 执行流图框架 */
pipeline->process();
/* 清空流水线中所有的资源 */
GPipelineFactory::remove(pipeline);
return 0;
}
如上图所示,图结构执行的时候,首先执行a节点。a节点执行完毕后,并行执行b和c节点。b和c节点全部执行完毕后,再执行d节点。
# pip install pycgraph
import time
from datetime import datetime
from pycgraph import GNode, GPipeline, CStatus
class MyNode1(GNode):
def run(self):
print("[{0}] {1}, sleep for 1 second ... ".format(datetime.now(), self.getName()))
time.sleep(1)
return CStatus()
class MyNode2(GNode):
def run(self):
print("[{0}] {1}, sleep for 2 second ... ".format(datetime.now(), self.getName()))
time.sleep(2)
return CStatus()
if __name__ == '__main__':
pipeline = GPipeline()
a, b, c, d = MyNode1(), MyNode2(), MyNode1(), MyNode2()
pipeline.registerGElement(a, set(), "nodeA")
pipeline.registerGElement(b, {a}, "nodeB")
pipeline.registerGElement(c, {a}, "nodeC")
pipeline.registerGElement(d, {b, c}, "nodeD")
pipeline.process()
[2021.05.04 - v1.0.0 - Chunel]
[2021.05.09 - v1.1.0 - Chunel]
[2021.05.18 - v1.1.1 - Chunel]
name和session信息[2021.05.23 - v1.2.0 - Chunel]
[2021.05.29 - v1.3.0 - Chunel]
cluster(簇)和region(区域)划分和循环执行功能tutorial内容,包含多种使用样例[2021.06.14 - v1.4.0 - Chunel]
param(参数)传递机制group(组)功能,多节点模块统一继承自group模块[2021.06.20 - v1.4.1 - Chunel]
condition(条件)功能[2021.06.24 - v1.5.0 - Chunel]
pipeline工厂创建方法tutorial内容[2021.07.07 - v1.5.1 - Chunel]
[2021.07.11 - v1.5.2 - Chunel]
[2021.07.31 - v1.5.3 - Chunel]
[2021.08.29 - v1.6.0 - Chunel]
pipeline功能,优化底层逻辑tutorial内容[2021.09.19 - v1.6.1 - Chunel]
Lru算子、Trie算子和模板节点功能,优化底层逻辑tutorial内容[2021.09.29 - v1.7.0 - Chunel]
aspect(切面)功能,用于横向扩展node或group功能tutorial内容[2021.10.07 - v1.7.1 - Chunel]
aspect(切面)实现逻辑,提供切面参数功能,提供批量添加切面功能tutorial内容[2021.11.01 - v1.8.0 - Chunel]
adapter(适配器)功能,提供singleton适配器功能pipeline执行逻辑tutorial内容[2021.12.18 - v1.8.1 - Chunel]
CStatus信息[2022.01.02 - v1.8.2 - Chunel]
task group(任务组)功能[2022.01.23 - v1.8.3 - Chunel]
function适配器,实现函数式编程功能tutorial内容[2022.01.31 - v1.8.4 - Chunel]
node(节点)异步执行的功能[2022.02.03 - v1.8.5 - Chunel]
daemon(守护)功能,用于定时执行非流图中任务tutorial内容[2022.04.03 - v1.8.6 - Chunel]
DistanceCalculator算子,用于实现任意数据类型、任意距离类型的计算tutorial内容[2022.04.05 - v2.0.0 - Chunel]
domain(领域)功能,提供Ann领域抽象模型,开始支持个别专业方向tutorial内容[2022.05.01 - v2.0.1 - Chunel]
pipeline注册机制,支持init方法自定义顺序执行[2022.05.29 - v2.1.0 - Chunel]
element参数写入方法tutorial内容[2022.10.03 - v2.1.1 - Chunel]
group执行逻辑[2022.11.03 - v2.2.0 - Chunel]
message(消息)功能,主要用于完成不同pipeline之间的数据传递tutorial内容[2022.12.24 - v2.2.1 - Chunel]
TemplateNode(模板节点)功能,用于优化参数传参方式tutorial内容[2022.12.25 - v2.2.2 - yeshenyong]
[2022.12.30 - v2.2.3 - Chunel]
message发布订阅功能[2023.01.21 - v2.3.0 - Chunel]
event(事件)功能CGraph Intro.xmind文件,通过脑图的方式,介绍了CGraph的整体逻辑[2023.01.25 - v2.3.1 - Chunel]
[2023.02.10 - v2.3.2 - Chunel]
[2023.02.12 - v2.3.3 - yeshenyong, Chunel]
[2023.02.22 - v2.3.4 - Chunel]
param机制和event(事件)机制[2023.03.25 - v2.4.0 - woodx, Chunel]
pipeline调度资源管控机制[2023.05.05 - v2.4.1 - Chunel]
pipeline最大并发度获取方法。感谢 Hanano-Yuuki 提供相关解决方案pipeline异步执行功能和执行时退出功能[2023.06.17 - v2.4.2 - Chunel]
MultiCondition(多条件)功能pipeline暂停执行和恢复执行功能[2023.07.12 - v2.4.3 - Chunel]
CStatus功能,添加了异常定位信息[2023.09.05 - v2.5.0 - Chunel]
pipeline的性能分析element的超时机制some(部分)功能,优化pipeline的异步执行方式[2023.09.15 - v2.5.1 - Chunel]
fence(栅栏)功能coordinator(协调)功能[2023.11.06 - v2.5.2 - Chunel]
message(消息)功能,可以设定写入阻塞时的处理方式,减少内存copy次数example相关内容,针对不同行业,提供一些简单实现[2023.11.15 - v2.5.3 - Chunel]
proto定义文件mutable(异变)功能,提供依赖关系注册语法糖[2024.01.05 - v2.5.4 - Chunel]
test内容,包含性能和功能方面的测试用例event(事件)机制,支持异步等待功能[2024.07.18 - v2.6.0 - PaPaPig-Melody, Chunel]
pipeline的拓扑执行的方式element之间是否有依赖关系的方法[2024.09.17 - v2.6.1 - Chunel]
pipeline的静态执行的方式,提供基于静态执行的微任务机制pipeline剪裁功能,用于删除element之间重复的依赖element删除依赖的方法event(事件)机制,异步事件可以等待结束[2024.11.16 - v2.6.2 - Chunel]
tutorial内容[2025.03.16 - v3.0.0 - Chunel]
stage(阶段)功能,用于element之间同步运行tutorial内容[2025.05.04 - v3.1.0 - Chunel]
pip3 install PyCGraph 安装[2025.06.15 - v3.1.1 - Chunel]
CODE_OF_CONDUCT.md 文档[2025.09.06 - v3.1.2 - Chunel]
message 功能aspect 功能[2025.11.08 - v3.2.2 - Chunel]
PyCGraph 为 pycgraph,支持 pip3 install pycgraph 安装[2026.03.24 - v3.2.3 - Chunel]
message 功能[2026.05.10 - v3.2.4 - Chunel]
pycgraph 功能[2026.08.15 - v3.2.5 - Chunel]
pycgraph 功能GSome 使用方式[2026.08.22 - v3.3.0 - Chunel]
GParam 的 trace 功能pycgraph 功能
Taskflow Group: awesome-parallel-computing, and we always treat taskflow as a role modelCGraph项目提出的意见和建议的朋友,在此不一一提及。随时欢迎大家加入,一起共建277 followers · starred Sep 2023
9 followers · starred Jul 2024
10 followers · starred Nov 2023
9 followers · starred Sep 2025