From: Alexander Schmidt Date: Thu, 11 Oct 2012 13:12:29 +0000 (+0200) Subject: ... X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/commitdiff_plain/44862121803df9a22a5b88b8df2167f5f4afe6b1 ... --- diff --git a/paraq.cpp b/paraq.cpp index 3f7eb29..e66f138 100644 --- a/paraq.cpp +++ b/paraq.cpp @@ -1,41 +1,65 @@ #include "paraq.h" +#include +#include +#include + +using namespace std; + paraq::paraq(int _nprocs, const int _rank) { - lastjob = -1; + thisjob = -1; nprocs = _nprocs; rank = _rank; + masterdefault = 0; } void paraq::addRange(const string& paraid, double min, double max, double step) { - double *range = new double[3]; - range[0] = min; - range[1] = max; - range[2] = step; + for( double paraval = min; paraval <= max+0.5*step; paraval += step+(step==0) ) + if( ! inParas(paraMap[paraid], paraval) ) paraMap[paraid].push_back( paraval ); +} - paraMap[paraid].push_back( range ); +bool paraq::inParas( vector& paraVec, double& tofind ) +{ + for( vector::iterator it = paraVec.begin(); it < paraVec.end(); ++it) + if( fabs(*it - tofind) < 0.0000000001 ) return true; + return false; } -map* paraq::nextParas() +int paraq::nextParas() { - if( lastjob == -1 ) { - lastjob = 0; - - for( map< string, vector< double* > >::iterator paraIt = paraMap.begin(); paraIt != paraMap.end(); ++paraIt ) { - for( vector< map >::iterator jobIt = jobList.begin(); jobIt != jobList.end(); ++jobIt) { - for( vector::iterator rangeIt = paraIt->second.begin(); rangeIt != paraIt->second.end(); ++rangeIt ) { - - for( double paraval = *rangeIt[0]; paraval < *rangeIt[1]; paraval += *rangeIt[2] ) { + if( thisjob == -1 ) { + map jobZero; + jobList.push_back( jobZero ); - //if( paraval == *rangeIt[0] ) - //else + for( map< string, vector< double > >::iterator paraIt = paraMap.begin(); paraIt != paraMap.end(); ++paraIt ) + while( jobList.begin()->find(paraIt->first) == jobList.begin()->end() ) { + for( vector::iterator valIt = paraIt->second.begin(); valIt != paraIt->second.end(); ++valIt ) { + jobList.push_back( *jobList.begin() ); + jobList.back()[paraIt->first] = *valIt; + } + jobList.erase( jobList.begin() ); + } - } + thisjob = rank; + } + else + thisjob += nprocs; - } + if( thisjob < jobList.size() ) return 1; + else + return 0; +} - } - } +double& paraq::operator[] (string paraid) { + if( jobList[thisjob].find(paraid) != jobList[thisjob].end() ) { + return jobList[thisjob][paraid]; } + + if( defaultPara.find(paraid) != defaultPara.end() ) { + return defaultPara[paraid]; + } + + return masterdefault; } diff --git a/paraq.h b/paraq.h index 9aaf1d0..7108974 100644 --- a/paraq.h +++ b/paraq.h @@ -11,13 +11,19 @@ class paraq { public: paraq(int nprocs, int rank); void addRange(const string& paraid, double min, double max, double step); - map* nextParas(); + int nextParas(); + double& operator[] (string paraid); + void addRange(const string& paraid, double range[3]) { addRange(paraid, range[0], range[1], range[2]); } + void setDefault(const string& paraid, double value) { defaultPara[paraid] = value; } private: int nprocs, rank; - int lastjob; - map< string, vector< double* > > paraMap; + int thisjob; + map defaultPara; + map< string, vector > paraMap; vector< map > jobList; + bool inParas(vector& paraVec, double& tofind); + double masterdefault; }; #endif