#include "paraq.h"
+#include <algorithm>
+#include <iostream>
+#include <math.h>
+
+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)
{
- 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<double>& paraVec, double& tofind )
+{
+ for( vector<double>::iterator it = paraVec.begin(); it < paraVec.end(); ++it)
+ if( fabs(*it - tofind) < 0.0000000001 ) return true;
+ return false;
}
-map<string,double>* paraq::nextParas()
+void paraq::initJobList()
{
- if( lastjob == -1 ) {
- lastjob = 0;
+ if( ! jobListInitialized ) {
+ map<string,double> jobZero;
+ jobList.push_back( jobZero );
- for( map< string, vector< double* > >::iterator paraIt = paraMap.begin(); paraIt != paraMap.end(); ++paraIt ) {
- for( vector< map<string,double> >::iterator jobIt = jobList.begin(); jobIt != jobList.end(); ++jobIt) {
- for( vector<double*>::iterator rangeIt = paraIt->second.begin(); rangeIt != paraIt->second.end(); ++rangeIt ) {
-
- for( double paraval = *rangeIt[0]; paraval < *rangeIt[1]; paraval += *rangeIt[2] ) {
+ for( map< string, vector< double > >::iterator paraIt = paraMap.begin(); paraIt != paraMap.end(); ++paraIt )
+ while( jobList.begin()->find(paraIt->first) == jobList.begin()->end() ) {
+ for( vector<double>::iterator valIt = paraIt->second.begin(); valIt != paraIt->second.end(); ++valIt ) {
+ jobList.push_back( *jobList.begin() );
+ jobList.back()[paraIt->first] = *valIt;
+ }
+ jobList.erase( jobList.begin() );
+ }
+ jobListInitialized = true;
+ }
+}
+
+int paraq::nextParas()
+{
+ if( thisjob == -1 ) {
+ initJobList();
+ thisjob = rank;
+ }
+ else
+ thisjob += nprocs;
- //if( paraval == *rangeIt[0] )
- //else
+ 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];
}
+
+ return masterdefault;
+}
+
+int paraq::getTotalJobs() {
+ initJobList();
+ return jobList.size();
}