X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/d3e332b13eccd2fa7e467770f6d973b4f34904cf..d945435d46acac2f758c23f0a5ae99cbb9894b91:/paraq.cpp?ds=inline diff --git a/paraq.cpp b/paraq.cpp index 3f7eb29..d512c9c 100644 --- a/paraq.cpp +++ b/paraq.cpp @@ -1,41 +1,184 @@ #include "paraq.h" +#include +#include +#include +#include +#include + +using namespace std; + paraq::paraq(int _nprocs, const int _rank) { - lastjob = -1; + thisjob = -1; nprocs = _nprocs; rank = _rank; + masterdefault = 0; + jobListInitialized = false; } -void paraq::addRange(const string& paraid, double min, double max, double step) +void paraq::addRange(const string& paraid, char *range) { - double *range = new double[3]; - range[0] = min; - range[1] = max; - range[2] = step; + int nargs=0; + double goodrange[3]; - paraMap[paraid].push_back( range ); + for( int pos=0; pos* paraq::nextParas() +string paraq::rangeString() { - 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] ) { + stringstream rangestring; - //if( paraval == *rangeIt[0] ) - //else + for( map< string, vector >::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 (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::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + if (linkit->first == defIt->first) { + linkedpara = true; + break; } - } + if (!linkedpara) + 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 ) +{ + for( vector::iterator it = paraVec.begin(); it < paraVec.end(); ++it) + if( fabs(*it - tofind) < 0.0000000001 ) return true; + return false; +} + +void paraq::initJobList() +{ + 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 ) { + jobList.push_back( *jobList.begin() ); + + jobList.back()[paraIt->first] = *valIt; + + /* also set linked parameters */ + for (vector::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + if (linkit->second == paraIt->first) + jobList.back()[linkit->first] = linkTypeFunction(*valIt, linkit->linktype); + } + jobList.erase( jobList.begin() ); + } + jobListInitialized = true; } } + +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 ) { + initJobList(); + thisjob = rank; + } + else + thisjob += nprocs; + + if( jobList.begin()->size() == 0 ) return 0; + + 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]; + } + + cerr << "PARAQ: Parameter " << paraid << " does not exist!" << endl << flush; + exit(1); +} + +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); +} + +string paraq::getParaNames() { + stringstream paranames; + + for (vector::iterator parait = allParaIds.begin(); parait != allParaIds.end(); ++parait) + paranames << *parait << ":"; + + return paranames.str(); +} + +string paraq::getParaVals() { + stringstream paravals; + + for (vector::iterator parait = allParaIds.begin(); parait != allParaIds.end(); ++parait) { + if ( parait != allParaIds.begin() ) + paravals << "\t"; + paravals << (*this)[*parait]; + } + + return paravals.str(); +}