MCPcopy Create free account
hub / github.com/ChunelFeng/CGraph / tutorial_simple

Function tutorial_simple

tutorial/T01-Simple.cpp:14–52  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

12using namespace CGraph;
13
14void tutorial_simple() {
15 /* 创建图对应的pipeline */
16 GPipelinePtr pipeline = GPipelineFactory::create();
17
18 /* 定义GElementPtr类型的变量 */
19 GElementPtr a, b, c, d = nullptr;
20
21 /**
22 * 注册节点,其中MyNode1和MyNode2必须为GNode的子类,否则无法通过编译。
23 * status+= 操作,可以用于记录链路异常问题
24 * */
25 CStatus status = pipeline->registerGElement<MyNode1>(&a, {}, "nodeA"); // 将名为nodeA,无执行依赖的node信息,注册入pipeline中
26 status += pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB"); // 将名为nodeB,依赖a执行的node信息,注册入pipeline中
27 status += pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");
28 status += pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD"); // 将名为nodeD,依赖{b,c}执行的node信息,注册入pipeline中
29 if (!status.isOK()) {
30 return; // 使用时,请对所有CGraph接口的返回值做判定。今后tutorial例子中省略该操作。
31 }
32
33 /**
34 UThreadPoolConfig config; // (可选)推荐根据自己设定的dag逻辑,来配置调度信息
35 config.default_thread_size_ = 2;
36 config.secondary_thread_size_ = 0; // 更多配置信息,请参考 UThreadPoolDefine.h 中的描述
37 pipeline->setUniqueThreadPoolConfig(config);
38 */
39
40 /* 图信息初始化,准备开始计算 */
41 status += pipeline->init();
42
43 /* 运行流图信息。初始化后,支持多次循环计算 */
44 for (int i = 0; i < 3; i++) {
45 status = pipeline->run();
46 CGRAPH_ECHO("==== tutorial_simple, loop : [%d], and run status = [%d].", i + 1, status.getCode());
47 }
48
49 /* 图信息逆初始化,准备结束计算 */
50 status += pipeline->destroy();
51 GPipelineFactory::remove(pipeline);
52}
53
54
55int main () {

Callers 1

mainFunction · 0.70

Calls 8

createFunction · 0.85
CGRAPH_ECHOFunction · 0.85
removeFunction · 0.85
isOKMethod · 0.80
getCodeMethod · 0.80
initMethod · 0.45
runMethod · 0.45
destroyMethod · 0.45

Tested by

no test coverage detected