X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/44862121803df9a22a5b88b8df2167f5f4afe6b1..7ba7584af501689c899b1b311286140d88e23b25:/paraq.cpp?ds=inline diff --git a/paraq.cpp b/paraq.cpp index e66f138..381941f 100644 --- a/paraq.cpp +++ b/paraq.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include using namespace std; @@ -12,12 +14,54 @@ paraq::paraq(int _nprocs, const int _rank) nprocs = _nprocs; rank = _rank; masterdefault = 0; + jobListInitialized = false; +} + +void paraq::addRange(const string& paraid, char *range) +{ + int nargs=0; + double goodrange[3]; + + for( int pos=0; pos >::iterator paraIt = rangeMap.begin(); paraIt != rangeMap.end(); ++paraIt ) + if( paraIt->second.size() > 0 ) + for( vector::iterator rangeIt = paraIt->second.begin(); rangeIt != paraIt->second.end(); ++rangeIt) + rangestring << "-" << paraIt->first << (*rangeIt)[0] << "_" << (*rangeIt)[1] << "_" << (*rangeIt)[2]; + + for( map::iterator defIt = defaultPara.begin(); defIt != defaultPara.end(); ++defIt ) + if( rangeMap.find(defIt->first) == rangeMap.end() ) + rangestring << "-" << defIt->first << defIt->second; + + return rangestring.str(); } void paraq::addRange(const string& paraid, double min, double max, double step) { + double *newrange = new double[3]; + newrange[0] = min; + newrange[1] = max; + newrange[2] = step; + rangeMap[paraid].push_back( newrange ); + for( double paraval = min; paraval <= max+0.5*step; paraval += step+(step==0) ) if( ! inParas(paraMap[paraid], paraval) ) paraMap[paraid].push_back( paraval ); + + uniqueAllParaIdsAdd(paraid); } bool paraq::inParas( vector& paraVec, double& tofind ) @@ -27,12 +71,12 @@ bool paraq::inParas( vector& paraVec, double& tofind ) return false; } -int paraq::nextParas() +void paraq::initJobList() { - if( thisjob == -1 ) { + if( ! jobListInitialized ) { map jobZero; jobList.push_back( jobZero ); - + 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 ) { @@ -41,12 +85,21 @@ int paraq::nextParas() } jobList.erase( jobList.begin() ); } + jobListInitialized = true; + } +} +int paraq::nextParas() +{ + if( thisjob == -1 ) { + initJobList(); thisjob = rank; } else thisjob += nprocs; + if( jobList.begin()->size() == 0 ) return 0; + if( thisjob < jobList.size() ) return 1; else return 0; @@ -63,3 +116,16 @@ double& paraq::operator[] (string paraid) { return masterdefault; } + +int paraq::getTotalJobs() { + initJobList(); + return jobList.size(); +} + +void paraq::uniqueAllParaIdsAdd(const string& paraid) { + for (vector::iterator allparait = allParaIds.begin(); allparait != allParaIds.end(); ++allparait) + if ( *allparait == paraid ) + return; + + allParaIds.push_back(paraid); +}