X-Git-Url: http://git.treefish.org/~alex/phys/latlib.git/blobdiff_plain/03a0d20d92b54e75ac862b9e41ede061b1918498..46e492935d31a36641b8e8a5cd27bd86e7df96c4:/paraq.cpp?ds=inline diff --git a/paraq.cpp b/paraq.cpp index 1bd57b3..93496fc 100644 --- a/paraq.cpp +++ b/paraq.cpp @@ -3,6 +3,8 @@ #include #include #include +#include +#include using namespace std; @@ -15,10 +17,64 @@ paraq::paraq(int _nprocs, const int _rank) 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 (vector< pair >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + rangestring << "-" << linkit->first << "->" << 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) + 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 ) @@ -38,7 +94,13 @@ void paraq::initJobList() 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< pair >::iterator linkit = linkedParas.begin(); linkit != linkedParas.end(); ++linkit) + if (linkit->second == paraIt->first) + jobList.back()[linkit->first] = *valIt; } jobList.erase( jobList.begin() ); } @@ -71,10 +133,40 @@ double& paraq::operator[] (string paraid) { return defaultPara[paraid]; } - return masterdefault; + 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(); +}