[Coin-discuss] COIN on a Mac

Laszlo Ladanyi ladanyi at us.ibm.com
Mon Jan 6 21:12:00 EST 2003


On Mon, 6 Jan 2003 ScottWelz at aol.com wrote:

> Rob,
> 
> This is the problem I was having with sys/time.h.   If you add:
> 
> #include <sys/time.h>
> 
> before the:
> 
> #include <sys/resource.h>
> 
> in OsiClpSolverInterface.cpp you should be up and running.
> 
> Regards, Scott
> 

Since time measurement will probably be used in pretty much every component I
suggest that there should be a CoinTime.hpp header and we should all use
CoinCpuTime(). The code below compiles and runs fine on Linux. I'll test it
later on AIX. Could someone take it and modify it as necessary to get it
running on other platforms (Mac, Sun, etc.)?

Thanks,
--Laci



// Copyright (C) 2002, International Business Machines
// Corporation and others.  All Rights Reserved.

#ifndef _CoinTime_hpp
#define _CoinTime_hpp

//#############################################################################

#include <ctime>
#if defined(_MSC_VER)
// Turn off compiler warning about long names
#  pragma warning(disable:4786)
#else
#include <sys/resource.h>
#endif

//#############################################################################

static inline double CoinCpuTime()
{
  double cpu_temp;
#if defined(_MSC_VER)
  unsigned int ticksnow;        /* clock_t is same as int */
  
  ticksnow = (unsigned int)clock();
  
  cpu_temp = (double)((double)ticksnow/CLOCKS_PER_SEC);
#else
  struct rusage usage;
  getrusage(RUSAGE_SELF,&usage);
  cpu_temp = usage.ru_utime.tv_sec;
  cpu_temp += 1.0e-6*((double) usage.ru_utime.tv_usec);
#endif
  return cpu_temp;
}

//#############################################################################

#endif




More information about the Coin-discuss mailing list