From: Alex Schmidt Date: Mon, 12 Aug 2013 12:39:30 +0000 (+0200) Subject: added linktype feature to paralinks. X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/074bd4d5f4b73c85da8f105ba3bfca00bf490ac8 added linktype feature to paralinks. --- diff --git a/paraq.cpp b/paraq.cpp index 773beb4..d512c9c 100644 --- a/paraq.cpp +++ b/paraq.cpp @@ -43,14 +43,14 @@ string paraq::rangeString() for( vector::iterator rangeIt = paraIt->second.begin(); rangeIt != paraIt->second.end(); ++rangeIt) rangestring << "-" << paraIt->first << (*rangeIt)[0] << "_" << (*rangeIt)[1] << "_" << (*rangeIt)[2]; - for (vector< pair >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) - rangestring << "-" << linkit->first << "--" << linkit->second; + for (vector::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + rangestring << "-" << linkit->first << "--" << linkit->linktype << "--" << linkit->second; for( map::iterator defIt = defaultPara.begin(); defIt != defaultPara.end(); ++defIt ) if( rangeMap.find(defIt->first) == rangeMap.end() ) { bool linkedpara = false; - for (vector< pair >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + for (vector::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) if (linkit->first == defIt->first) { linkedpara = true; break; @@ -98,9 +98,9 @@ void paraq::initJobList() jobList.back()[paraIt->first] = *valIt; /* also set linked parameters */ - for (vector< pair >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + for (vector::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) if (linkit->second == paraIt->first) - jobList.back()[linkit->first] = *valIt; + jobList.back()[linkit->first] = linkTypeFunction(*valIt, linkit->linktype); } jobList.erase( jobList.begin() ); } @@ -108,6 +108,18 @@ void paraq::initJobList() } } +double paraq::linkTypeFunction (double linkval, int linktype) { + switch (linktype) { + + case LINK_1TO1: + return linkval; + + case LINK_NEGATIVE: + return -linkval; + + } +} + int paraq::nextParas() { if( thisjob == -1 ) { diff --git a/paraq.h b/paraq.h index 0167bcb..70070f3 100644 --- a/paraq.h +++ b/paraq.h @@ -5,9 +5,19 @@ #include #include +#define LINK_1TO1 0 +#define LINK_NEGATIVE 1 + using namespace std; class paraq { + private: + struct paralink { + string first; + string second; + int linktype; + }; + public: paraq(int nprocs, int rank); void addRange(const string& paraid, double min, double max, double step); @@ -17,7 +27,16 @@ class paraq { void addRange(const string& paraid, char *range); void setDefault(const string& paraid, double value) { defaultPara[paraid] = value; uniqueAllParaIdsAdd(paraid); } - void linkParas(const string& paraid1, const string ¶id2) { linkedParas.push_back( make_pair(paraid1,paraid2) ); } + void linkParas(const string& paraid1, const string ¶id2, int linktype=LINK_1TO1) { + paralink tmpLink; + + tmpLink.first = paraid1; + tmpLink.second = paraid2; + tmpLink.linktype = linktype; + + linkedParas.push_back( tmpLink ); + //linkedParas.push_back( make_pair(paraid1,paraid2) ); + } int getTotalJobs(); string rangeString(); vector allParaIds; @@ -30,13 +49,14 @@ class paraq { map defaultPara; map< string, vector > paraMap; map< string, vector > rangeMap; - vector< pair > linkedParas; + vector linkedParas; vector< map > jobList; void initJobList(); bool inParas(vector& paraVec, double& tofind); double masterdefault; bool jobListInitialized; void uniqueAllParaIdsAdd(const string& paraid); + double linkTypeFunction (double linkval, int linktype); }; #endif