编译时遇到的问题:
windows下没有sys/times.H头文件,及相应库文件,而在cpuTime.H中嵌入的该文件
#include <sys/times.H>
解决方法:将该语句注释掉
在该类的实现代码里将相应的方法用其他函数替代掉:
对cpuTime.H的修改:
#ifndef cpuTime_H
#define cpuTime_H
#include <time.h>
//bioexploreModify deinclude the <sys/times.h> which is not found
//#include <sys/times.h>
////bioexploreModifyEnd
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam
{
/*---------------------------------------------------------------------------*\
Class cpuTime Declaration
\*---------------------------------------------------------------------------*/
class cpuTime
{
// Private data
//bioexploreModify change long to double
static double Hz_; //这里将long改成double型了,为了增加其容量
//bioexploreModifyEnd
//bioexploreModify struct tms===> clock_t
clock_t startTime_; //将tms结构改成time.H中定义的clock_t类型
mutable clock_t lastTime_;
mutable clock_t newTime_;
static void getTime(clock_t& t);
static double timeDifference
(
const clock_t& start,
const clock_t& end
);
//bioexploreModifyEnd
public:
// Constructors
//- Construct from components
cpuTime();
// Member Functions
// Access
//- Returns CPU time from start of run
double elapsedCpuTime() const;
//- Returns CPU time from last call of cpuTimeIncrement()
double cpuTimeIncrement() const;
};
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
} // End namespace Foam
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
#endif
以下是对该类实现代码进行的修改
// * * * * * * * * * * * * * * * Static Members * * * * * * * * * * * * * * //
//bioexploreModify sysconf(_SC_CLK_TCK)==>CLOCKS_PER_SEC and long==> double
double cpuTime::Hz_(CLOCKS_PER_SEC);
//bioexploreModifyEnd
// * * * * * * * * * * * * * Private Member Functions * * * * * * * * * * * //
//bioexploreModify change struct tms===>clock_t
void cpuTime::getTime(clock_t& t)
{
//bioexploreModify change times(&t)===>t=clock();
//times(&t);
t=clock();
//bioexploreModifyEnd
}
double cpuTime::timeDifference
(
const clock_t& start,
const clock_t& end
)
{
return
(
double
(
end
- start
)/Hz_
);
}
//bioexploreModifyEnd
评论