29 #define drand48() (double(rand()) / RAND_MAX)
30 #define isnan(x) _isnan(x)
31 #define round(x) OsCall::roundToNearestInt(x)
32 #define srand48(seed) srand(seed)
43 #include <sys/types.h>
54 #include <sys/types.h>
60 #ifdef SINGLE_PRECISION
61 #define REAL_TYPE float
62 #define REAL_TYPE_STRING "float"
63 #define REAL_MAX FLT_MAX
65 #define REAL_TYPE double
66 #define REAL_TYPE_STRING "double"
67 #define REAL_MAX DBL_MAX
70 #define DBL_SIGNIFICANT_DIGITS 14
71 #define FLT_SIGNIFICANT_DIGITS 7
73 #ifdef SINGLE_PRECISION
74 #define REAL_SIGNIFICANT_DIGITS FLT_SIGNIFICANT_DIGITS
76 #define REAL_SIGNIFICANT_DIGITS DBL_SIGNIFICANT_DIGITS
79 #define M_PI 3.14159265358979323846
86 #ifdef SINGLE_PRECISION
100 directoryPath = _getcwd(NULL, 0);
102 directoryPath = getcwd(NULL, PATH_MAX);
104 directoryPath +=
"/";
113 stringstream procFileName;
114 procFileName <<
"/proc/" << getpid() <<
"/statm";
116 ifstream procFile(procFileName.str().data(), ios::in);
119 procFile >> memoryUsage;
121 return memoryUsage/1024.0;
129 return omp_get_num_procs();
136 LARGE_INTEGER frequency;
137 QueryPerformanceFrequency(&frequency);
140 QueryPerformanceCounter(&temp);
142 return (
double) temp.QuadPart/frequency.QuadPart;
146 struct timeval stamp;
147 gettimeofday(&stamp, NULL);
148 return (stamp.tv_sec*1000000 + stamp.tv_usec)/1000000.0;
152 struct timeval stamp;
153 gettimeofday(&stamp, NULL);
154 return (stamp.tv_sec*1000000 + stamp.tv_usec)/1000000.0;
159 const string &directoryName,
const string &extension){
161 vector< string > filesInDir;
163 WIN32_FIND_DATA FindFileData;
165 buffer = _getcwd( NULL, 0 );
166 if((buffer = _getcwd( NULL, 0 )) == NULL)
167 perror(
"_getcwd error" );
172 HANDLE hFind = FindFirstFile(directoryName.data(), &FindFileData);
173 if(hFind == INVALID_HANDLE_VALUE){
175 msg <<
"[Os] Could not open directory `"
176 << directoryName <<
"'. Error: "<< GetLastError() << endl;
178 d.
dMsg(cerr, msg.str(), 0);
181 string entryExtension(FindFileData.cFileName);
183 entryExtension.substr(entryExtension.find_last_of(
'.') + 1);
185 if(entryExtension == extension)
186 filesInDir.push_back(
string(FindFileData.cFileName));
187 string dir = directoryName;
188 dir.resize(dir.size()-1);
189 while(FindNextFile(hFind, &FindFileData)){
190 if(extension.size()){
191 string entryExtension(FindFileData.cFileName);
192 entryExtension = entryExtension.substr(
193 entryExtension.find_last_of(
'.') + 1);
194 if(entryExtension == extension)
195 filesInDir.push_back(dir
196 +
string(FindFileData.cFileName));
199 if((
string(FindFileData.cFileName) !=
".")
200 &&(
string(FindFileData.cFileName) !=
"..")){
201 filesInDir.push_back(directoryName
203 +
string(FindFileData.cFileName));
210 DIR *d = opendir((directoryName +
"/").data());
214 <<
"[Os] Could not open directory `"
215 << directoryName <<
"'..." << endl;
217 d.
dMsg(cerr, msg.str(), 0);
220 struct dirent *dirEntry;
221 while((dirEntry = readdir(d)) != NULL){
222 if(extension.size()){
223 string entryExtension(dirEntry->d_name);
225 entryExtension.substr(entryExtension.find_last_of(
'.') + 1);
226 if(entryExtension == extension)
227 filesInDir.push_back(directoryName
229 +
string(dirEntry->d_name));
232 if((
string(dirEntry->d_name) !=
".")
233 &&(
string(dirEntry->d_name) !=
".."))
234 filesInDir.push_back(directoryName
236 +
string(dirEntry->d_name));
243 sort(filesInDir.begin(), filesInDir.end());
248 inline static int mkDir(
const string &directoryName){
250 return _mkdir(directoryName.data());
252 return mkdir(directoryName.data(), 0777);
258 const double upperBound = ceil( x );
259 const double lowerBound = floor( x );
261 if( upperBound-x <= x-lowerBound )
262 return (
int)upperBound;
264 return (
int)lowerBound;
271 inline static int rmDir(
const string &directoryName){
276 return _rmdir(directoryName.data());
279 cmd <<
"rm -R " << directoryName <<
" 2> /dev/null";
280 return system(cmd.str().data());
284 inline static int rmFile(
const string &fileName){
294 cmd <<
" " << fileName;
297 cmd <<
" 2> /dev/null";
300 return system(cmd.str().data());
305 const double upperBound = ceil(val);
306 const double lowerBound = floor(val);
308 if(upperBound - val <= val - lowerBound){
309 return (
int)upperBound;
312 return (
int)lowerBound;
328 Memory(){ initialMemory_ = OsCall::getMemoryInstantUsage();};
331 return initialMemory_;
335 return OsCall::getMemoryInstantUsage();
339 return OsCall::getMemoryInstantUsage() - initialMemory_;
344 float initialMemory_;
352 start_ = getTimeStamp();
361 double end = getTimeStamp();
370 start_ = getTimeStamp();
377 return OsCall::getTimeStamp();
static int roundToNearestInt(const double &val)
Definition: Os.h:303
static int getCurrentDirectory(string &directoryPath)
Definition: Os.h:98
double getStartTime()
Definition: Os.h:365
float getElapsedUsage()
Definition: Os.h:338
Memory()
Definition: Os.h:328
static int nearbyint(const double &x)
Definition: Os.h:256
static vector< string > listFilesInDirectory(const string &directoryName, const string &extension)
Definition: Os.h:158
static float getMemoryInstantUsage()
Definition: Os.h:109
static int rmFile(const string &fileName)
Definition: Os.h:284
virtual const int dMsg(ostream &stream, string msg, const int &debugLevel=infoMsg) const
Definition: Debug.cpp:52
static int mkDir(const string &directoryName)
Definition: Os.h:248
Timer(const Timer &other)
Definition: Os.h:355
double getElapsedTime()
Definition: Os.h:359
Os-specifics.
Definition: Os.h:93
double start_
Definition: Os.h:378
static double getTimeStamp()
Definition: Os.h:134
static int getNumberOfCores()
Definition: Os.h:127
Timer()
Definition: Os.h:351
Minimalist debugging class.
Definition: Debug.h:39
void reStart()
Definition: Os.h:369
float getInstantUsage()
Definition: Os.h:334
Definition: CommandLineParser.h:13
const double getTimeStamp()
Definition: Os.h:376
static int rmDir(const string &directoryName)
Definition: Os.h:271
double real
Definition: Os.h:89
float getInitialMemoryUsage()
Definition: Os.h:330