/*************************** @Author: woodx @Contact: woodx9@163.com @File: T19Test.cpp @Time: 2023/2/12 15:13 下午 @Desc: 本例主要是用来测试多层嵌套region和cluster是否会发生bug ***************************/ #include "MyGNode/MyWriteParamNode.h" #include "MyGNode/MyReadParamNode.h" //condition #include "MyGCondition/MyCondition.h" using namespace CGraph; GElementPtr createCluster(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName, std::vector loopVect) { GElementPtrArr nodeArr; GElementPtr node = nullptr; prefixName = prefixName + "_Node"; for (int i = 0; i < loopVect.size(); ++i) { node = pipeline->createGNode(GNodeInfo({}, prefixName + std::to_string(i), loopVect[i])); nodeArr.push_back(node); } GElementPtr cluster = pipeline->createGGroup(nodeArr, dependElements, "", 1); return cluster; } //7 GElementPtr createClusterB(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName) { return createCluster(pipeline, dependElements, prefixName, {1, 5, 1}); } //4 GElementPtr createClusterL(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName) { return createCluster(pipeline, dependElements, prefixName, {3, 1}); } //12 GElementPtr createRegionD(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName) { GElementPtr nodeD1 = pipeline->createGNode(GNodeInfo({}, prefixName + "nodeD1", 1)); GElementPtr clusterL = createClusterL(pipeline, {nodeD1}, prefixName + "_ClusterL"); GElementPtr clusterB = createClusterB(pipeline, {nodeD1}, prefixName + "_ClusterB"); GElementPtr d_region = pipeline->createGGroup({nodeD1, clusterL, clusterB}, dependElements, prefixName, 1); return d_region; } //并行的n个节点(n为loopVect数组的大小),循环由loopVect里的数据决定 GElementPtr createRegionE(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName, std::vector loopVect) { GElementPtrArr ptrList; for (int i = 0; i < loopVect.size(); ++i) { GElementPtr nodeE = pipeline->createGNode(GNodeInfo({}, prefixName + "_nodeE" + std::to_string(i), loopVect[i])); ptrList.push_back(nodeE); } GElementPtr e_region = pipeline->createGGroup(ptrList, dependElements, prefixName, 1); return e_region; } //condition总是选择第一个node GElementPtr createConditionF(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName, std::vector loopVect) { GElementPtrArr ptrList; for (int i = 0; i < loopVect.size(); ++i) { GElementPtr nodeF = pipeline->createGNode(GNodeInfo({}, prefixName + "_nodeF" + std::to_string(i), loopVect[i])); ptrList.push_back(nodeF); } GElementPtr f_condtion = pipeline->createGGroup(ptrList, dependElements, prefixName, 1); return f_condtion; } //16 GElementPtr createClusterK(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName) { GElementPtrArr ptrList; GElementPtr regionD = createRegionD(pipeline, {}, prefixName + "_RegionD"); ptrList.push_back(regionD); //12 GElementPtr clusterL = createClusterL(pipeline, {}, prefixName + "_ClusterL"); ptrList.push_back(clusterL); //4 GElementPtr k_cluster = pipeline->createGGroup(ptrList, dependElements, "", 1); return k_cluster; } //48 * 2 GElementPtr createRegionJ(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName, std::vector loopVect) { GElementPtrArr ptrList; GElementPtr regionE = createRegionE(pipeline, {}, "RegionE0", {1, 2, 3, 4, 5, 6, 7}); ptrList.push_back(regionE); //28 GElementPtr clusterL = createClusterL(pipeline, {}, prefixName + "_ClusterL"); ptrList.push_back(clusterL); //4 GElementPtr clusterK = createClusterK(pipeline, {regionE, clusterL}, prefixName + "_ClusterK"); ptrList.push_back(clusterK); //16 GElementPtr j_region = pipeline->createGGroup(ptrList, dependElements, prefixName, 2); return j_region; } //110 GElementPtr createRegionM(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName, std::vector loopVect) { GElementPtrArr ptrList; GElementPtr nodeM1 = pipeline->createGNode(GNodeInfo({}, prefixName + "nodeM1", 10)); ptrList.push_back(nodeM1); //10 //condition总是选择第二个,此处为4 GElementPtr conditionF = createConditionF(pipeline, {}, prefixName + "_ConditonF", {3, 4, 5}); ptrList.push_back(conditionF); //4 GElementPtr regionJ = createRegionJ(pipeline, {nodeM1, conditionF}, prefixName + "_RegionJ", {}); ptrList.push_back(regionJ); //96 GElementPtr m_region = pipeline->createGGroup(ptrList, dependElements, prefixName, 1); return m_region; } //126 GElementPtr createRegionI(GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName, std::vector loopVect) { GElementPtrArr ptrList; GElementPtr regionD = createRegionD(pipeline, {}, prefixName + "_RegionD"); ptrList.push_back(regionD); //12 //condition总是选择第二个,此处为4 GElementPtr conditionF = createConditionF(pipeline, {}, prefixName + "_ConditonF", {3, 4, 5}); ptrList.push_back(conditionF); //4 GElementPtr regionJ = createRegionM(pipeline, {regionD, conditionF}, prefixName + "_RegionJ", {}); ptrList.push_back(regionJ); //110 GElementPtr i_region = pipeline->createGGroup(ptrList, dependElements, prefixName, 1); return i_region; } //n * 16 GElementPtr createRegionI_recursion(int n, GPipelinePtr pipeline, const GElementPtrSet & dependElements, std::string prefixName, std::vector loopVect) { if (n == 1) return createRegionI(pipeline, dependElements, prefixName + "_RegionJ", {0}); GElementPtrArr ptrList; GElementPtr regionD = createRegionD(pipeline, {}, prefixName + "_RegionD"); ptrList.push_back(regionD); //12 //condition总是选择第二个,此处为4 GElementPtr conditionF = createConditionF(pipeline, {}, prefixName + "_ConditonF", {3, 4, 5}); ptrList.push_back(conditionF); //4 GElementPtr regionI_r; regionI_r = createRegionI_recursion(n - 1, pipeline, {regionD, conditionF}, prefixName + "regionI_r" + std::to_string(n), {}); ptrList.push_back(regionI_r); GElementPtr i_region; i_region = pipeline->createGGroup(ptrList, dependElements, prefixName, 1); return i_region; } void tutorial_test() { CStatus status; GPipelinePtr pipeline = GPipelineFactory::create(); GElementPtr nodeA; status += pipeline->registerGElement(&nodeA, {}, "nodeA", 1); //1 GElementPtr clusterB0 = createClusterB(pipeline, {nodeA},"ClusterB0"); status += pipeline->registerGElement(&clusterB0, {nodeA}, "clusterB0", 1); //8 GElementPtr nodeC; status += pipeline->registerGElement(&nodeC, {}, "nodeC", 5); //13 GElementPtr regionD0 = createRegionD(pipeline, {}, "RegionD0"); status += pipeline->registerGElement(®ionD0, {nodeA}, "regionD0", 1); //25 GElementPtr regionE0 = createRegionE(pipeline, {}, "RegionE0", {1, 2, 3, 4, 5, 6, 7}); status += pipeline->registerGElement(®ionE0, {clusterB0, nodeC, regionD0}, "regionD0", 1); //53 //condition总是选择第二个,此处为4 GElementPtr conditionF0 = createConditionF(pipeline, {}, "ConditonF0", {3, 4, 5}); status += pipeline->registerGElement(&conditionF0, {regionE0}, "CondtionF0", 1); //57 GElementPtr clusterL1 = createClusterL(pipeline, {}, "ClusterL1"); status += pipeline->registerGElement(&clusterL1, {regionE0}, "clutesrL1", 1); //61 int n = 10; //修改嵌套次数 GElementPtr regionI0 = createRegionI_recursion(n, pipeline, {}, "RegionJ0", {0}); status += pipeline->registerGElement(®ionI0, {regionE0}, "regionJ0", 1); //61 + 110 + n * 16 GElementPtr regionE1 = createRegionE(pipeline, {}, "RegionE1", {1, 2, 3, 4, 5, 6, 7}); status += pipeline->registerGElement(®ionE1, {conditionF0, clusterL1, regionI0}, "regionD0", 1); //61 + 110 + n * 16 + 28 = 199 + n * 16 status += pipeline->process(); GPipelineFactory::remove(pipeline); } int main () { tutorial_test(); return 0; }