HarleysZhang / CGraph

【A simple C++ DAG framework】 一个简单好用的、无任何三方依赖的、跨平台的、收录于awesome-cpp的、基于流图的并行计算框架。欢迎star & fork

Home Page:http://www.chunel.cn

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

languages os stars forks

awesome-cpp HelloGithub

中文 | English Readme

CGraph 说明文档

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 and so on. Some useful tools and plugins are also provide to improve your project.

Tutorials and contact information are show as follows. Please get in touch with us for free if you need more about this repository.

一. 简介

CGraph中文名为【色丶图】,是一套无任何第三方依赖的跨平台图流程执行框架。通过GPipeline(流水线)底层调度,实现了依赖元素依次顺序执行、非依赖元素并发执行的调度功能。

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

项目提供了丰富的参数类型,用于不同应用场景下的数据互通。此外,还可以通过添加GAspect(切面)的方式,实现以上各种元素功能的横向扩展,或是通过引入GAdapter(适配器)对单个节点功能进行加强。

CGraph Skeleton

二. 编译说明

  • 本工程支持MacOS、Linux和Windows系统,无任何第三方依赖。默认使用C++11版本,推荐使用C++17版本,暂不支持C++11以下的版本

  • 使用CLion(推荐)作为IDE的开发者,打开CMakeLists.txt文件作为工程,即可编译通过

  • Windows环境中,使用Visual Studio(2013版或以上版本)作为IDE的开发者,安装cmake之后,输入以下指令,即可生成CGraph.sln文件

    $ git clone https://github.com/ChunelFeng/CGraph.git
    $ cd CGraph
    $ cmake . -Bbuild    # 在 build 文件夹下,生成对应的CGraph.sln文件
  • Linux环境开发者,在命令行模式下,输入以下指令,即可编译通过

    $ git clone https://github.com/ChunelFeng/CGraph.git
    $ cd CGraph
    $ cmake . -Bbuild
    $ cd build
    $ make -j8
  • 若本地无法编译,提供基于Ubuntu 20.04的Docker镜像。输入以下指令,即可获取并进入

    $ docker pull chunelfeng/cenv                         # 获取docker镜像
    $ docker run -it --name CGraphEnv chunelfeng/cenv     # 开启docker容器,并进入
  • 提供online版本的编译调试环境,点击进入页面:CGraph env online ,通过github账号登录。进入后,输入以下指令,即可编译通过,并查看执行结果

    $ sudo apt-get install cmake             # 安装cmake
    $ ./CGraph-build.sh                      # 编译CGraph工程,生成的内容在同级/build/文件夹中
    $ ./build/tutorial/T00-HelloCGraph       # 运行第一个实例程序,并且在终端输出 Hello, CGraph.

三. 使用Demo

MyNode.h

#include "../src/CGraph.h"

class MyNode1 : public CGraph::GNode {
public:
    CStatus run () override {
        CStatus status;
        CGraph::CGRAPH_ECHO("[%s], Sleep for 1 second ...", this->getName().c_str());
        CGRAPH_SLEEP_SECOND(1)
        return status;
    }
};

class MyNode2 : public CGraph::GNode {
public:
    CStatus run () override {
        CStatus status;
        CGraph::CGRAPH_ECHO("[%s], Sleep for 2 second ...", this->getName().c_str());
        CGRAPH_SLEEP_SECOND(2)
        return status;
    }
};

main.cpp

#include "MyNode.h"

using namespace CGraph;

int main() {
    /* 创建一个流水线,用于设定和执行流图信息 */
    GPipelinePtr pipeline = GPipelineFactory::create();
    GElementPtr a, b, c, d = nullptr;

    /* 注册节点,其中MyNode1和MyNode2必须为GNode的子类,否则无法通过编译 */
    CStatus status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA");
    status += pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB");
    status += pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");
    status += pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD");
    if (!status.isOK()) {
        return;    // 对以上所有CGraph接口的返回值做判定
    }

    /* 执行流图框架 */
    status = pipeline->process();
    GPipelineFactory::remove(pipeline);

    return 0;
}

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

四. 推荐阅读

五. 关联项目

  • GraphANNS : Graph-based Approximate Nearest Neighbor Search Working off CGraph
  • CThreadPool : 一个简单好用、功能强大、性能优异、跨平台的C++线程池

附录-1. 版本信息

[2021.05.04 - v1.0.0 - Chunel]

  • 提供图化执行功能,支持非依赖节点并行计算

[2021.05.09 - v1.1.0 - Chunel]

  • 优化图执行过程中的并发度

[2021.05.18 - v1.1.1 - Chunel]

  • 添加节点namesession信息

[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模块
  • 添加对Linux系统的的支持

[2021.06.20 - v1.4.1 - Chunel]

  • 提供condition(条件)功能
  • 添加对Windows系统的支持

[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(切面)功能,用于横向扩展nodegroup功能
  • 更新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适配器,实现函数式编程功能
  • 提供线程优先级调度功能,提供线程绑定cpu执行功能
  • 更新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领域抽象模型,开始支持个别专业方向
  • 提供hold执行机制,支持根据运行时条件,判断是否需要重新执行当前内容,直到满足条件为止
  • 更新tutorial内容

[2022.05.01 - v2.0.1 - Chunel]

  • 优化pipeline注册机制,支持init方法自定义顺序执行
  • 提供一键编译脚本

[2022.05.29 - v2.1.0 - Chunel]

  • 提供element参数写入方法
  • 提供针对C++14版本的支持
  • 更新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]

  • 提供针对C++11版本的支持。感谢 MirrorYuChen 提供相关解决方案

[2023.02.10 - v2.3.2 - Chunel]

  • 优化调度策略,提供调度参数配置接口
  • 提供英文版本readme.md

[2023.02.12 - v2.3.3 - yeshenyong, Chunel]

  • 提供graphviz可视化图展示功能
  • 提供参数链路追踪功能

[2023.02.22 - v2.3.4 - Chunel]

  • 优化Windows系统下调度机制
  • 优化参数机制

附录-2. 感谢


附录-3. 联系方式

CGraph Author

About

【A simple C++ DAG framework】 一个简单好用的、无任何三方依赖的、跨平台的、收录于awesome-cpp的、基于流图的并行计算框架。欢迎star & fork

http://www.chunel.cn

License:MIT License


Languages

Language:C++ 92.4%Language:C 6.2%Language:CMake 1.0%Language:Lua 0.3%Language:Shell 0.0%