Skip to content

SherlockC787/CGraph

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

214 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

languages os stars forks

CGraph 说明文档

CGraph is a cross-platform DAG(Directed Acyclic Graph) framework based on C++17 without any 3rd-party.

You, with it, can build your own operators simply, and then describe any running schedules as you need, such as dependence, parallelling, aggregation and so on. Some useful tools and plugins are also provided to improve your project.

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

一. 简介

本工程实现了一套无任何第三方依赖的跨平台图流程计算框架。通过GPipeline(流水线)底层调度,实现了依赖元素依次顺序执行、非依赖元素并发执行的调度功能。

使用者只需继承GNode(节点)类,实现子类的run()方法,并根据需要设定依赖关系,即可实现任务的图化执行。

同时,使用者还可以通过设定各种包含多节点信息的GGroup(组),自行控制图的条件判断、循环和并发执行逻辑。

此外,还可以通过添加GAspect(切面)的方式,实现以上各种元素功能的横向扩展,或是通过引入各种GAdapter(适配器)对单个节点功能进行加强。

CGraph Skeleton

二. 编译说明

  • 本工程支持MacOS、Linux和Windows系统,无任何第三方依赖。使用CLion作为IDE的开发者,打开CMakeLists.txt文件作为工程,即可编译通过

  • Linux环境开发者,在命令行模式下,输入以下指令,即可编译通过

    $ git clone https://github.com/ChunelFeng/CGraph.git
    $ cd CGraph
    $ cmake . -Bbuild
    $ cd build
    $ make -j8
  • Windows环境中,使用Visual Studio作为IDE的开发者,clone本工程前请优先设置换行符类型

    $ git config --global core.autocrlf true              # 设置Windows平台支持的CRLF换行符形式
    $ git clone https://github.com/ChunelFeng/CGraph.git
    $ ... ...     # 接下来操作同Linux命令行环境,即可生成相应的*.sln文件
  • 提供基于Ubuntu 20.04.3 LTS的Docker镜像。输入以下指令,即可获取并进入

    $ docker pull chunelfeng/cenv                         # 获取docker镜像
    $ docker run -it --name CGraphEnv chunelfeng/cenv     # 开启docker容器,并进入

三. 使用Demo

MyNode1.h

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

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

MyNode2.h

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

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

main.cpp

#include "MyGNode/MyNode1.h"
#include "MyGNode/MyNode2.h"

using namespace CGraph;

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

    /* 注册节点,其中MyNode1和MyNode2必须为GNode的子类,否则无法通过编译。
     * MyNode1中run()执行内容为sleep(1s)
     * MyNode2中run()执行内容为sleep(2s) */
    CStatus status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA");    // 将名为nodeA,无执行依赖的node信息,注册入pipeline中
    status += pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB");    // 将名为nodeB,依赖a执行的node信息,注册入pipeline中
    status += pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");
    status += pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD");    // 将名为nodeD,依赖{b,c}执行的node信息,注册入pipeline中
    if (!status.isOK()) {
        return;    // 使用时,请对所有CGraph接口的返回值做判定
    }

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

    return 0;
}

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

四. 推荐阅读


附录-1. 版本信息

[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内容

更多版本变更信息,请参考 ChangeLog.md 文件


附录-2. 感谢

  • 感谢 @yangyuxiang77 @wuxing @whenever5225 @Yaha 等朋友(排名按贡献时间为顺序)为项目做出的贡献
  • 感谢所有为CGraph项目提出的意见和建议的朋友,在此不一一提及。随时欢迎大家加入,一起共建

附录-3. 联系方式

CGraph Author

About

【A simple C++ DAG framework】 一个简单的、无任何三方依赖的、跨平台的基于流图的并行计算框架,功能丰富,扩展性强。欢迎star & fork,更多信息请参考:http://www.chunel.cn

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • C++ 93.0%
  • C 5.6%
  • Other 1.4%