Giter VIP home page Giter VIP logo

kingmoment / cgraph Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chunelfeng/cgraph

0.0 0.0 0.0 2.59 MB

#A simple C++ DAG framework# 一个简单的跨平台的基于流图的并行计算框架,支持注册依赖、循环执行、条件判断、面向切面、函数式编程、守护任务、自动优化、自定义分区等功能。欢迎star & fork,更多信息请参考:http://www.chunel.cn

License: MIT License

CMake 0.58% C++ 94.50% C 4.92%

cgraph's Introduction

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 for them as you need, such as dependence, parallelling, loop, condition and aggregation. 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
  • 提供基于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;
    }
};

demo.cpp

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

using namespace CGraph;

void tutorial_simple() {
    /* 创建一个流水线,用于设定和执行流图信息 */
    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);
}

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

四. 感谢


附录-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内容

附录-2. 推荐阅读


附录-3. 联系方式

CGraph Author

cgraph's People

Contributors

chunelfeng avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.