-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathParameters.h
139 lines (112 loc) · 2.48 KB
/
Parameters.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#ifndef __PARAMETERS_H__
#define __PARAMETERS_H__
#include "defines.h"
#include "charm++.h"
#include <iostream>
#include <stdio.h>
#include <string>
#include <map>
#include "pup_stl.h"
using namespace std;
struct Parameters {
string filename;
Real theta;
Real dtime;
Real dthf;
Real epssq;
Real tolsq;
int numTreePieces;
int numParticles;
int ppc;
int ppb;
int yieldPeriod;
int cacheLineSize;
int iterations;
//int branchFactor;
void pup(PUP::er &p){
p | filename;
p | numTreePieces;
p | numParticles;
p | dtime;
p | dthf;
p | tolsq;
p | epssq;
p | ppc;
p | ppb;
p | yieldPeriod;
p | theta;
p | cacheLineSize;
p | iterations;
}
void extractParameters(int argc, char **argv, map<string,string> &tab){
for(int i = 0; i < argc; i++){
string arg = string(argv[i]);
size_t pos = arg.find("=");
if(pos != string::npos){
size_t len = arg.length();
string key = arg.substr(1,pos-1);
string val = arg.substr(pos+1,len-pos-1);
tab[key] = val;
}
}
}
string getparam(string name, map<string,string> &table)
{
map<string,string>::iterator it = table.find(name);
if(it != table.end()){
return it->second;
}
return string();
}
/*
* GETIPARAM, ..., GETDPARAM: get int, long, bool, or double parameters.
*/
int getiparam(string name, int def, map<string,string> &tab)
{
string val;
val = getparam(name,tab);
if(val.empty())
return def;
else
return (atoi(val.c_str()));
}
long getlparam(string name, map<string,string> &tab)
{
string val;
val = getparam(name,tab);
if(val.empty())
return -1;
else
return (atol(val.c_str()));
}
bool getbparam(string name, map<string,string> &tab)
{
string val;
val = getparam(name,tab);
if (strchr("tTyY1", *(val.c_str())) != 0) {
return (true);
}
if (strchr("fFnN0", *(val.c_str())) != 0) {
return (false);
}
fprintf(stderr,"getbparam: %s=%s not bool\n", name.c_str(), val.c_str());
return false;
}
Real getrparam(string name, Real default_value, map<string,string> &tab)
{
string val;
val = getparam(name,tab);
if(val.empty())
return default_value;
else
return (atof(val.c_str()));
}
/*
* EXTRVALUE: extract value from name=value string.
*/
string getsparam(string arg, map<string,string> &tab)
{
return getparam(arg,tab);
}
};
#endif