bugfix: Windows compatibility of 'apply' and 'eoEvalUserTimeThrowException'
This commit is contained in:
parent
7ac6662090
commit
6cb15cfecf
3 changed files with 62 additions and 10 deletions
1
eo/NEWS
1
eo/NEWS
|
|
@ -1,4 +1,5 @@
|
||||||
* current version
|
* current version
|
||||||
|
- fixed compilation issues in Microsoft Visual C++
|
||||||
|
|
||||||
* release 1.2 (16. May. 2011)
|
* release 1.2 (16. May. 2011)
|
||||||
- fixed the incremental allocation issue in variation operators which were
|
- fixed the incremental allocation issue in variation operators which were
|
||||||
|
|
|
||||||
|
|
@ -58,14 +58,26 @@ void apply(eoUF<EOT&, void>& _proc, std::vector<EOT>& _pop)
|
||||||
if (!eo::parallel.isDynamic())
|
if (!eo::parallel.isDynamic())
|
||||||
{
|
{
|
||||||
#pragma omp parallel for if(eo::parallel.isEnabled()) //default(none) shared(_proc, _pop, size)
|
#pragma omp parallel for if(eo::parallel.isEnabled()) //default(none) shared(_proc, _pop, size)
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
//Visual Studio supports only OpenMP version 2.0 in which
|
||||||
|
//an index variable must be of a signed integral type
|
||||||
|
for (long long i = 0; i < size; ++i) { _proc(_pop[i]); }
|
||||||
|
#else // _MSC_VER
|
||||||
for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); }
|
for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); }
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#pragma omp parallel for schedule(dynamic) if(eo::parallel.isEnabled())
|
#pragma omp parallel for schedule(dynamic) if(eo::parallel.isEnabled())
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
//Visual Studio supports only OpenMP version 2.0 in which
|
||||||
|
//an index variable must be of a signed integral type
|
||||||
|
for (long long i = 0; i < size; ++i) { _proc(_pop[i]); }
|
||||||
|
#else // _MSC_VER
|
||||||
//doesnot work with gcc 4.1.2
|
//doesnot work with gcc 4.1.2
|
||||||
//default(none) shared(_proc, _pop, size)
|
//default(none) shared(_proc, _pop, size)
|
||||||
for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); }
|
for (size_t i = 0; i < size; ++i) { _proc(_pop[i]); }
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( eo::parallel.enableResults() )
|
if ( eo::parallel.enableResults() )
|
||||||
|
|
|
||||||
|
|
@ -21,27 +21,30 @@ Authors:
|
||||||
Johann Dréo <johann.dreo@thalesgroup.com>
|
Johann Dréo <johann.dreo@thalesgroup.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __unix__
|
#if !defined(__unix__) && !defined(_WINDOWS)
|
||||||
#warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX systems (defining 'rusage' in 'sys/resource.h'), contributions for other systems are welcomed."
|
#warning "Warning: class 'eoEvalUserTimeThrowException' is only available under UNIX (defining 'rusage' in 'sys/resource.h') or Win32 (defining 'GetProcessTimes' in 'WinBase.h') systems, contributions for other systems are welcomed."
|
||||||
#else
|
#else //!defined(__unix__) && !defined(_WINDOWS)
|
||||||
|
|
||||||
#ifndef __EOEVALUSERTIMETHROWEXCEPTION_H__
|
#ifndef __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||||
#define __EOEVALUSERTIMETHROWEXCEPTION_H__
|
#define __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||||
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <sys/resource.h>
|
|
||||||
|
|
||||||
#include <eoExceptions.h>
|
|
||||||
|
|
||||||
/** Check at each evaluation if a given CPU user time contract has been reached.
|
/** Check at each evaluation if a given CPU user time contract has been reached.
|
||||||
*
|
*
|
||||||
* Throw an eoMaxTimeException if the given max time has been reached.
|
* Throw an eoMaxTimeException if the given max time has been reached.
|
||||||
* Usefull if you want to end the search independently of generations.
|
* Usefull if you want to end the search independently of generations.
|
||||||
* This class uses (almost-)POSIX headers.
|
* This class uses (almost-)POSIX or Win32 headers, depending on the platform.
|
||||||
* It uses a computation of the user time used on the CPU. For a wallclock time measure, see eoEvalTimeThrowException
|
* It uses a computation of the user time used on the CPU. For a wallclock time measure, see eoEvalTimeThrowException
|
||||||
*
|
*
|
||||||
* @ingroup Evaluation
|
* @ingroup Evaluation
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <eoExceptions.h>
|
||||||
|
|
||||||
|
#ifdef __unix__
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
|
|
||||||
template< class EOT >
|
template< class EOT >
|
||||||
class eoEvalUserTimeThrowException : public eoEvalFuncCounter< EOT >
|
class eoEvalUserTimeThrowException : public eoEvalFuncCounter< EOT >
|
||||||
{
|
{
|
||||||
|
|
@ -68,5 +71,41 @@ protected:
|
||||||
struct rusage _usage;
|
struct rusage _usage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
#ifdef _WINDOWS
|
||||||
|
//here _WINDOWS is defined
|
||||||
|
|
||||||
|
#include <WinBase.h>
|
||||||
|
|
||||||
|
template< class EOT >
|
||||||
|
class eoEvalUserTimeThrowException : public eoEvalFuncCounter< EOT >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
eoEvalUserTimeThrowException( eoEvalFunc<EOT> & func, const long max ) : eoEvalFuncCounter<EOT>( func, "CPU-user"), _max(max) {}
|
||||||
|
|
||||||
|
virtual void operator() ( EOT & eo )
|
||||||
|
{
|
||||||
|
if( eo.invalid() ) {
|
||||||
|
FILETIME dummy;
|
||||||
|
GetProcessTimes(GetCurrentProcess(), &dummy, &dummy, &dummy, &_usage);
|
||||||
|
|
||||||
|
ULARGE_INTEGER current;
|
||||||
|
current.LowPart = _usage.dwLowDateTime;
|
||||||
|
current.HighPart = _usage.dwHighDateTime;
|
||||||
|
if( current.QuadPart >= _max ) {
|
||||||
|
throw eoMaxTimeException( current.QuadPart );
|
||||||
|
} else {
|
||||||
|
func(eo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
const long _max;
|
||||||
|
FILETIME _usage;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // _WINDOWS
|
||||||
|
#endif //__unix__
|
||||||
#endif // __EOEVALUSERTIMETHROWEXCEPTION_H__
|
#endif // __EOEVALUSERTIMETHROWEXCEPTION_H__
|
||||||
#endif // __UNIX__
|
#endif //!defined(__unix__) && !defined(_WINDOWS)
|
||||||
|
|
|
||||||
Reference in a new issue