diff --git a/Net.xcodeproj/project.pbxproj b/Net.xcodeproj/project.pbxproj index 4f35040..cefcd82 100644 --- a/Net.xcodeproj/project.pbxproj +++ b/Net.xcodeproj/project.pbxproj @@ -10,6 +10,7 @@ 9221DA1121EB5FB8007310A7 /* net.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 9221DA1021EB5FB8007310A7 /* net.cpp */; }; 925A13A621EC68D500CBD427 /* cpart.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 925A13A421EC67C900CBD427 /* cpart.cpp */; }; 925A13A921EC973000CBD427 /* cmap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 925A13A721EC973000CBD427 /* cmap.cpp */; }; + 925A13AD21EC9DB900CBD427 /* cthread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 925A13AB21EC9DB900CBD427 /* cthread.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -33,6 +34,8 @@ 925A13A421EC67C900CBD427 /* cpart.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cpart.cpp; sourceTree = ""; }; 925A13A721EC973000CBD427 /* cmap.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cmap.cpp; sourceTree = ""; }; 925A13A821EC973000CBD427 /* cmap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cmap.h; sourceTree = ""; }; + 925A13AB21EC9DB900CBD427 /* cthread.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cthread.cpp; sourceTree = ""; }; + 925A13AC21EC9DB900CBD427 /* cthread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cthread.h; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -70,6 +73,7 @@ 9221DA1621EB8C02007310A7 /* pcs.map */, 925A13A421EC67C900CBD427 /* cpart.cpp */, 925A13A721EC973000CBD427 /* cmap.cpp */, + 925A13AB21EC9DB900CBD427 /* cthread.cpp */, ); name = Net; sourceTree = ""; @@ -77,6 +81,7 @@ 925A13AA21EC989500CBD427 /* include */ = { isa = PBXGroup; children = ( + 925A13AC21EC9DB900CBD427 /* cthread.h */, 9221DA0F21EB5FB8007310A7 /* net.h */, 9221DA1421EB62F6007310A7 /* cpart.h */, 925A13A821EC973000CBD427 /* cmap.h */, @@ -143,6 +148,7 @@ 9221DA1121EB5FB8007310A7 /* net.cpp in Sources */, 925A13A621EC68D500CBD427 /* cpart.cpp in Sources */, 925A13A921EC973000CBD427 /* cmap.cpp in Sources */, + 925A13AD21EC9DB900CBD427 /* cthread.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/cpart.cpp b/cpart.cpp index a52ee35..ee02053 100644 --- a/cpart.cpp +++ b/cpart.cpp @@ -16,7 +16,7 @@ @param name 计算模块的名字 @param ffresh 每次建立该结构都重新编译一次源文件 */ -CPart::CPart(string src_path,string src_name,string name,bool ffresh = true){ +CPart::CPart(string src_path,string src_name,string name,bool ffresh){ this->src_path = src_path; this->name = name; // 去掉源文件的后缀 diff --git a/cthread.cpp b/cthread.cpp new file mode 100644 index 0000000..320bf4e --- /dev/null +++ b/cthread.cpp @@ -0,0 +1,81 @@ +// +// cthread.cpp +// Net +// +// Created by 胡一兵 on 2019/1/14. +// Copyright © 2019年 Bakantu. All rights reserved. +// + +#include "cthread.h" + +CThread::CThread(CMap *tp_map):p_map(tp_map){ + for(auto k = p_map->cparts.begin(); k != p_map->cparts.end(); k++){ + vector args,args_out; + rargs.insert(pair>((*k).first,args)); + rargs_out.insert(pair>((*k).first,args_out)); + } + for(auto k = p_map->cparts.begin(); k != p_map->cparts.end(); k++){ + ifsolved.insert(pair((*k).first,false)); + } +} + +void CThread::Analyse(void){ + for(auto k = p_map->cparts.begin(); k != p_map->cparts.end(); k++){ + auto cpart_depends = (*k).second->depends; + if(cpart_depends.size()){ + bool if_ok = true; + for(auto ditem = cpart_depends.begin(); ditem != cpart_depends.end(); ditem++){ + string name = ditem->t_cpart->name; + if(!(ifsolved.find(name)->second)){ + if_ok = false; + } + } + if(if_ok) line.push_back((*k).second); + } + else{ + string name = (*k).second->name; + if(rargs.find(k->second->name)->second.size() == k->second->fargs_in.size()){ + if(ifsolved.find(name)->second == false){ + line.push_back(k->second); + } + } + + } + } +} + +void CThread::DoLine(void){ + for(auto pcp = line.begin(); pcp != line.end(); pcp++){ + string name = (*pcp)->name; + + vector args = rargs.find(name)->second; + vector &args_out = rargs_out.find(name)->second; + vector fargs = (*pcp)->fargs_in; + vector fargs_out = (*pcp)->fargs_out; + vector &argso = (*pcp)->args_out; + (*pcp)->Clear(); + int cout = 0; + for(auto arg = args.begin(); arg != args.end(); arg++,cout++){ + if(fargs[cout] == INT){ + (*pcp)->addArgsIn(*((int *)(*arg))); + } + else if(fargs[cout] == DOUBLE){ + (*pcp)->addArgsIn(*((double *)(*arg))); + } + } + if(!(*pcp)->Run()){ + ifsolved.find(name)->second = true; + int cout = 0; + for(auto argo = argso.begin(); argo != argso.end(); argo++,cout++){ + if(fargs_out[cout] == INT){ + int *p_value = new int(*((int *)(*argo))); + args_out.push_back((void *)p_value); + } + else if(fargs_out[cout] == DOUBLE){ + double *p_value = new double(*((double *)(*argo))); + args_out.push_back((double *)p_value); + } + } + } + } +} diff --git a/cthread.h b/cthread.h new file mode 100644 index 0000000..af4444b --- /dev/null +++ b/cthread.h @@ -0,0 +1,48 @@ +// +// cthread.hpp +// Net +// +// Created by 胡一兵 on 2019/1/14. +// Copyright © 2019年 Bakantu. All rights reserved. +// + +#ifndef cthread_h +#define cthread_h + +#include "cpart.h" +#include "cmap.h" + +#include + +using std::list; + +//计算进程管理结构 +class CThread{ +public: +// 对应的图结构管理结构 + CMap *p_map; +// 计算模块处理队列 + list line; +// 此计算进程中计算模块的传入参数数据列表 + map> rargs; +// 此计算进程的计算模块的传出参数数据列表 + map> rargs_out; +// 计算模块是否已经执行 + map ifsolved; +// 使用图结构管理结构来构造计算进程管理结构 + CThread(CMap *tp_map); + template +// 添加相关计算模块的传入参数 + void AddArgs(string name, T value){ + auto k = rargs.find(name); + T *p_value = new T(); + *p_value = value; + (*k).second.push_back((void *)p_value); + } +// 分析图结构来构造处理队列 + void Analyse(void); +// 执行处理队列 + void DoLine(void); +}; + +#endif /* cthread_h */ diff --git a/net.h b/net.h index 2889939..30d2ad4 100644 --- a/net.h +++ b/net.h @@ -180,94 +180,6 @@ public: -class CThread{ -public: - CMap *p_map; - list line; - map> rargs; - map> rargs_out; - map ifsolved; - CThread(CMap *tp_map):p_map(tp_map){ - for(auto k = p_map->cparts.begin(); k != p_map->cparts.end(); k++){ - vector args,args_out; - rargs.insert(pair>((*k).first,args)); - rargs_out.insert(pair>((*k).first,args_out)); - } - for(auto k = p_map->cparts.begin(); k != p_map->cparts.end(); k++){ - ifsolved.insert(pair((*k).first,false)); - } - } - template - void AddArgs(string name, T value){ - auto k = rargs.find(name); - T *p_value = new T(); - *p_value = value; - (*k).second.push_back((void *)p_value); - } - void Analyse(void){ - for(auto k = p_map->cparts.begin(); k != p_map->cparts.end(); k++){ - auto cpart_depends = (*k).second->depends; - if(cpart_depends.size()){ - bool if_ok = true; - for(auto ditem = cpart_depends.begin(); ditem != cpart_depends.end(); ditem++){ - string name = ditem->t_cpart->name; - if(!(ifsolved.find(name)->second)){ - if_ok = false; - } - } - if(if_ok) line.push_back((*k).second); - } - else{ - string name = (*k).second->name; - if(rargs.find(k->second->name)->second.size() == k->second->fargs_in.size()){ - if(ifsolved.find(name)->second == false){ - line.push_back(k->second); - cout<<"ADD "<second->name<name; - - cout<<(*pcp)->name<<" "<<(*pcp)->libname< args = rargs.find(name)->second; - vector &args_out = rargs_out.find(name)->second; - vector fargs = (*pcp)->fargs_in; - vector fargs_out = (*pcp)->fargs_out; - vector &argso = (*pcp)->args_out; - (*pcp)->Clear(); - int cout = 0; - for(auto arg = args.begin(); arg != args.end(); arg++,cout++){ - if(fargs[cout] == INT){ - (*pcp)->addArgsIn(*((int *)(*arg))); - } - else if(fargs[cout] == DOUBLE){ - (*pcp)->addArgsIn(*((double *)(*arg))); - } - } - if(!(*pcp)->Run()){ - ifsolved.find(name)->second = true; - int cout = 0; - for(auto argo = argso.begin(); argo != argso.end(); argo++,cout++){ - if(fargs_out[cout] == INT){ - int *p_value = new int(*((int *)(*argo))); - args_out.push_back((void *)p_value); - } - else if(fargs_out[cout] == DOUBLE){ - double *p_value = new double(*((double *)(*argo))); - args_out.push_back((double *)p_value); - } - } - } - } - } -}; - struct pcs_result{ char *name[16]; uint32_t in_size;