Fixed and Added.

This commit is contained in:
Saturneic 2019-01-14 18:45:35 +08:00
parent b9f8ddaaf7
commit 5f0d9e17ef
5 changed files with 136 additions and 89 deletions

View File

@ -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 = "<group>"; };
925A13A721EC973000CBD427 /* cmap.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cmap.cpp; sourceTree = "<group>"; };
925A13A821EC973000CBD427 /* cmap.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cmap.h; sourceTree = "<group>"; };
925A13AB21EC9DB900CBD427 /* cthread.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = cthread.cpp; sourceTree = "<group>"; };
925A13AC21EC9DB900CBD427 /* cthread.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = cthread.h; sourceTree = "<group>"; };
/* 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 = "<group>";
@ -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;
};

View File

@ -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;
// 去掉源文件的后缀

81
cthread.cpp Normal file
View File

@ -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<void *> args,args_out;
rargs.insert(pair<string,vector<void *>>((*k).first,args));
rargs_out.insert(pair<string,vector<void *>>((*k).first,args_out));
}
for(auto k = p_map->cparts.begin(); k != p_map->cparts.end(); k++){
ifsolved.insert(pair<string,bool>((*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<void *> args = rargs.find(name)->second;
vector<void *> &args_out = rargs_out.find(name)->second;
vector<int> fargs = (*pcp)->fargs_in;
vector<int> fargs_out = (*pcp)->fargs_out;
vector<void *> &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>(*((int *)(*arg)));
}
else if(fargs[cout] == DOUBLE){
(*pcp)->addArgsIn<double>(*((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);
}
}
}
}
}

48
cthread.h Normal file
View File

@ -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 <list>
using std::list;
//计算进程管理结构
class CThread{
public:
// 对应的图结构管理结构
CMap *p_map;
// 计算模块处理队列
list<CPart *> line;
// 此计算进程中计算模块的传入参数数据列表
map<string,vector<void *>> rargs;
// 此计算进程的计算模块的传出参数数据列表
map<string,vector<void *>> rargs_out;
// 计算模块是否已经执行
map<string,bool> ifsolved;
// 使用图结构管理结构来构造计算进程管理结构
CThread(CMap *tp_map);
template<class T>
// 添加相关计算模块的传入参数
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 */

88
net.h
View File

@ -180,94 +180,6 @@ public:
class CThread{
public:
CMap *p_map;
list<CPart *> line;
map<string,vector<void *>> rargs;
map<string,vector<void *>> rargs_out;
map<string,bool> ifsolved;
CThread(CMap *tp_map):p_map(tp_map){
for(auto k = p_map->cparts.begin(); k != p_map->cparts.end(); k++){
vector<void *> args,args_out;
rargs.insert(pair<string,vector<void *>>((*k).first,args));
rargs_out.insert(pair<string,vector<void *>>((*k).first,args_out));
}
for(auto k = p_map->cparts.begin(); k != p_map->cparts.end(); k++){
ifsolved.insert(pair<string,bool>((*k).first,false));
}
}
template<class T>
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 "<<k->second->name<<endl;
}
}
}
}
}
void DoLine(void){
for(auto pcp = line.begin(); pcp != line.end(); pcp++){
string name = (*pcp)->name;
cout<<(*pcp)->name<<" "<<(*pcp)->libname<<endl;
vector<void *> args = rargs.find(name)->second;
vector<void *> &args_out = rargs_out.find(name)->second;
vector<int> fargs = (*pcp)->fargs_in;
vector<int> fargs_out = (*pcp)->fargs_out;
vector<void *> &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>(*((int *)(*arg)));
}
else if(fargs[cout] == DOUBLE){
(*pcp)->addArgsIn<double>(*((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;