2 Star 6 Fork 6

Chunel / CGraph

Create your Gitee Account
Explore and code with more than 12 million developers,Free private repositories !:)
Sign up
Clone or Download
contribute
Sync branch
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README
MIT

languages os stars forks

awesome-cpp HelloGithub

中文 | English Readme

CGraph Readme

1. Introduction

CGraph, short for Color Graph, is a cross-platform DAG computing framework without any third-party dependencies. With the scheduling via GPipeline, the purpose of sequential and concurrent executing elements is realized.

You only need to inherit GNode class, implement the run() method in the subclass, and set the dependencies as needed to achieve the graphical execution of tasks.

At the same time, you can also control the graph conditional judgment, loop or concurrent execution logic by setting various GGroups, which containing multi-node information by themselves.

You can transfer your params in many scenes. It is also possible to extend the functions of the above elements horizontally by adding GAspect, to enhance the functions of individual nodes by introducing various GAdapter, or to enrich pipeline schedule by GEvent.

CGraph Skeleton

2. Compile

  • This project supports MacOS, Linux, and Windows systems without any third-party dependencies. C++11 is default and lowest version, C++17 is recommended.

  • For developers using CLion as IDE within all platform, open the CMakeLists.txt file as project to compile.

  • Developers on Windows system, using Visual Studio(2013 version at least) as IDE, with cmake, enter commands as flowers to build CGraph.sln file.

    $ git clone https://github.com/ChunelFeng/CGraph.git
    $ cd CGraph
    $ cmake . -Bbuild
  • Developers on MacOS system, using Xcode as IDE, with cmake, enter commands as flowers to build CGraph.xcodeproj file.

    $ git clone https://github.com/ChunelFeng/CGraph.git
    $ cd CGraph
    $ mkdir build && cd build
    $ cmake .. -G Xcode
  • Developers on Linux system, enter commands as flowers to compile.

    $ git clone https://github.com/ChunelFeng/CGraph.git
    $ cd CGraph
    $ cmake . -Bbuild
    $ cd build
    $ make -j8
  • Compile online, enter CGraph env online, log in with your Github id, enter commands as flowers to compile and run your first tutorial.

    $ sudo apt-get install cmake -y
    $ ./CGraph-build.sh
    $ ./build/tutorial/T00-HelloCGraph

3. Demo

MyNode.h

#include "CGraph.h"

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


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

main.cpp

#include "MyNode.h"

using namespace CGraph;

int main() {
    /* build a pipeline */
    GPipelinePtr pipeline = GPipelineFactory::create();
    GElementPtr a, b, c, d = nullptr;

    /* register node with dependency info */
    CStatus status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA");    // register nodeA with no dependency
    status += pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB");    // b depends a
    status += pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");
    status += pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD");    // d depends b and c
    if (!status.isOK()) {
        return;
    }

    /* run dag pipeline */
    status = pipeline->process();
    GPipelineFactory::remove(pipeline);

    return 0;
}

CGraph Demo
As is shown on the picture, run a firstly. Then, run b and c parallelized. Run d at last after b and c finished.

MIT License Copyright (c) 2024 Chunel Feng Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

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

Releases

No release

Contributors

All

Activities

Load More
can not load any more
C++
1
https://gitee.com/Chunel_Feng/CGraph.git
git@gitee.com:Chunel_Feng/CGraph.git
Chunel_Feng
CGraph
CGraph
main

Search

53164aa7 5694891 3bd8fe86 5694891