SkillAgentSearch skills...

CGraph

【A common used C++ & Python DAG framework】 一个通用的、无三方依赖的、跨平台的、收录于awesome-cpp的、基于流图的并行计算框架。欢迎star & fork & 交流

Install / Use

/learn @ChunelFeng/CGraph
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

<p align="left"> <a href="https://github.com/ChunelFeng/CGraph"><img src="https://badgen.net/badge/langs/C++,Python/cyan?list=1" alt="languages"></a> <a href="https://github.com/ChunelFeng/CGraph"><img src="https://badgen.net/badge/os/MacOS,Linux,Windows/cyan?list=1" alt="os"></a> <a href="https://github.com/ChunelFeng/CGraph/stargazers"><img src="https://badgen.net/github/stars/ChunelFeng/CGraph?color=cyan" alt="stars"></a> <a href="https://github.com/ChunelFeng/CGraph/network/members"><img src="https://badgen.net/github/forks/ChunelFeng/CGraph?color=cyan" alt="forks"></a> <a href="https://badge.fury.io/py/pycgraph"><img src="https://badge.fury.io/py/pycgraph.svg" alt="pypi"></a> <a href="https://pepy.tech/projects/pycgraph"><img src="https://static.pepy.tech/personalized-badge/pycgraph?period=total&units=INTERNATIONAL_SYSTEM&left_color=GRAY&right_color=GREEN&left_text=pypi+downloads" alt="PyPI Downloads"></a> <a href="https://www.codefactor.io/repository/github/chunelfeng/cgraph/overview/main"><img src="https://www.codefactor.io/repository/github/chunelfeng/cgraph/badge/main" alt="CodeFactor" /></a> </p>

awesome-cpp HelloGithub

中文 | English Readme | deepwiki

<h1 align="center"> CGraph 说明文档 </h1> <img align="right" src="https://github.com/ChunelFeng/CGraph/blob/main/doc/image/CGraph%20Author.jpg" width="256px">

<b>CGraph</b> is a cross-platform <b>D</b>irected <b>A</b>cyclic <b>G</b>raph framework based on pure C++ without any 3rd-party dependencies.</br></br> You, with it, can <b>build your own operators simply, and describe any running schedules</b> as you need, such as dependence, parallelling, aggregation, conditional and so on. <b>Python APIs</b> are also supported to build your pipeline.</br></br> Tutorials and contact information are shown as follows. Please <b>get in touch with us for free</b> if you need more about this repository.

一. 简介

CGraph中文名为【色丶图】,是一套无任何第三方依赖的跨平台图流程执行框架。通过GPipeline(流水线)底层调度,提供了包含依赖元素依次执行、非依赖元素并发执行,支持暂停、恢复、超时设定的 eDAG 调度功能。

使用者只需继承GNode(节点)类,实现子类的run()方法,并根据需要设定依赖关系,即可实现任务的图化执行或流水线执行。还可以通过设定各种包含多节点信息的GGroup(组),自行控制图的条件判断、循环和并发执行逻辑。

CGraph Skeleton <br>

本工程使用纯C++11标准库编写,无任何第三方依赖,兼容MacOSLinuxWindowsAndroid系统。支持本地编译和二次开发,并且提供Python版本:pycgraph。编译和安装方法,请参考 CGraph 编译说明 <br>

详细功能介绍和用法,请参考 一面之猿网 中的文章内容。相关视频在B站持续更新中,欢迎观看和交流:<br>


二. 入门Demo

<b>C++ 版本</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;
}

CGraph Demo <br> 如上图所示,图结构执行的时候,首先执行a节点。a节点执行完毕后,并行执行bc节点。bc节点全部执行完毕后,再执行d节点。

<b>Python 版本</b>

import time
from datetime import datetime

from pycgraph import GNode, GPipeline, CStatus


class MyNode1(GNode):
    def run(self):
        print("[{0}] {1}, enter MyNode1 run function. Sleep for 1 second ... ".format(datetime.now(), self.getName()))
        time.sleep(1)
        return CStatus()

class MyNode2(GNode):
    def run(self):
        print("[{0}] {1}, enter MyNode2 run function. 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()

<b>其他版本</b>

  • CsCGraph : A CSharp native, CGraph-API-liked DAG project
  • JaCGraph : A Java native, CGraph-API-liked DAG project
  • GoCGraph : A Go native, CGraph-API-liked DAG project
  • CGraph-lite : A one-header-only, CGraph-API-liked DAG project, lite version by C++

三. 推荐阅读


四. 关联项目

View on GitHub
GitHub Stars2.3k
CategoryDevelopment
Updated1d ago
Forks383

Languages

C++

Security Score

100/100

Audited on Mar 26, 2026

No findings