Commit 295f9985 authored by sebastien's avatar sebastien

Dynare++ and k_order_perturbation DLL:

* support Microsoft Visual C++ 2008 compiler (necessary for 64-bit 
platforms)
* use standard C++ headers for C Standard Library support


git-svn-id: https://www.dynare.org/svn/dynare/trunk@3121 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 3a137c3e
......@@ -6,7 +6,7 @@
@c
#include "quasi_mcarlo.h"
#include <math.h>
#include <cmath>
@<|RadicalInverse| constructor code@>;
@<|RadicalInverse::eval| code@>;
......
......@@ -9,9 +9,9 @@
#include <dynlapack.h>
#include <math.h>
#include <cmath>
#include <string.h>
#include <cstring>
#include <algorithm>
@<|ParameterSignal| constructor code@>;
......@@ -155,7 +155,11 @@ void GaussConverterFunction::eval(const Vector& point, const ParameterSignal& si
@<|GaussConverterFunction::multiplier| code@>=
double GaussConverterFunction::calcMultiplier() const
{
#ifndef _MSC_VER
return sqrt(pow(M_PI, -1*indim()));
#else
return sqrt(pow(3.14159265358979323846, -1*indim()));
#endif
}
@
......
......@@ -12,7 +12,7 @@
#include "integ/cc/product.h"
#include <getopt.h>
#include <stdio.h>
#include <cstdio>
#include <cmath>
......
......@@ -14,10 +14,10 @@
#include "product.h"
#include "quasi_mcarlo.h"
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <sys/time.h>
#include <math.h>
#include <cmath>
const int num_threads = 2; // does nothing if DEBUG defined
......
......@@ -683,7 +683,11 @@ void GenShockRealization::get(int n, Vector& out)
Vector r(numShocks());
RandomShockRealization::get(n, r);
for (int j = 0; j < numShocks(); j++)
#ifndef _MSC_VER
if (! isfinite(out[j]))
#else
if (!_finite(out[j]))
#endif
out[j] = r[j];
}
......
......@@ -631,7 +631,13 @@ damp by one half.
if (fnorm <= flastnorm)
urelax_found = true;
else
#ifndef _MSC_VER
urelax *= std::min(0.5, flastnorm/fnorm);
#else
/* MSVC doesn't define std::min() (should be in <algorithm>),
but instead has a macro in <windows.h> */
urelax *= min(0.5, flastnorm/fnorm);
#endif
}
......
......@@ -10,7 +10,7 @@
#include "faa_di_bruno.h"
#include "fine_container.h"
#include <math.h>
#include <cmath>
double FaaDiBruno::magic_mult = 1.5;
@<|FaaDiBruno::calculate| folded sparse code@>;
......
......@@ -295,7 +295,11 @@ void FirstOrder::journalEigs()
}
JournalRecord jr(journal);
double mod = sqrt(alphar[i]*alphar[i]+alphai[i]*alphai[i]);
#ifndef _MSC_VER
mod = mod/round(100000*std::abs(beta[i]))*100000;
#else // MSVC doesn't respect C99 standard and doesn't define round(); use floor(x+0.5) instead
mod = mod/floor(100000*std::abs(beta[i])+0.5)*100000;
#endif
jr << i << "\t(" << alphar[i] << "," << alphai[i] << ") / " << beta[i]
<< " \t" << mod << endrec;
}
......
......@@ -373,7 +373,11 @@ f^i(x_1,\ldots,x_i) &=
for (qmcpit run = beg; run != end; ++run, icol++) {
Vector ycol(ymat, icol);
Vector x(run.point());
#ifndef _MSC_VER
x.mult(2*M_PI);
#else
x.mult(2*3.14159265358979323846);
#endif
ycol[0] = 1;
for (int i = 0; i < d; i++) {
Vector subsphere(ycol, 0, i+1);
......
......@@ -7,19 +7,65 @@
#include "journal.h"
#include "kord_exception.h"
#ifndef __MINGW32__
#if !defined(__MINGW32__) && !defined(_MSC_VER)
# include <sys/resource.h>
# include <sys/utsname.h>
#endif
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
#include <cstdlib>
#ifndef _MSC_VER
# include <unistd.h>
#endif
#include <ctime>
SystemResources _sysres;
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(_MSC_VER)
@<|sysconf| Win32 implementation@>;
#endif
#ifdef _MSC_VER
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag = 0;
if (NULL != tv)
{
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
tmpres /= 10; /*convert into microseconds*/
/*converting file time to unix epoch*/
tmpres -= 11644473600000000ULL;
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
if (NULL != tz)
{
if (!tzflag)
{
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}
#endif
@<|SystemResources| constructor code@>;
@<|SystemResources::pageSize| code@>;
@<|SystemResources::physicalPages| code@>;
......@@ -83,7 +129,7 @@ void SystemResources::getRUS(double& load_avg, long int& pg_avail,
gettimeofday(&now, NULL);
elapsed = now.tv_sec-start.tv_sec + (now.tv_usec-start.tv_usec)*1.0e-6;
#ifndef __MINGW32__
#if !defined(__MINGW32__) && !defined(_MSC_VER)
struct rusage rus;
getrusage(RUSAGE_SELF, &rus);
utime = rus.ru_utime.tv_sec+rus.ru_utime.tv_usec*1.0e-6;
......@@ -97,7 +143,7 @@ void SystemResources::getRUS(double& load_avg, long int& pg_avail,
majflt = -1;
#endif
#if !defined(__MINGW32__) && !defined(__CYGWIN32__)
#if !defined(__MINGW32__) && !defined(_MSC_VER) && !defined(__CYGWIN32__)
getloadavg(&load_avg, 1);
#else
load_avg = -1.0;
......@@ -209,7 +255,7 @@ void Journal::printHeader()
(*this)<< "General Public License, see http://www.gnu.org/license/gpl.html\n";
(*this)<< "\n\n";
#if !defined(__MINGW32__)
#if !defined(__MINGW32__) && !defined(_MSC_VER)
utsname info;
uname(&info);
(*this)<< "System info: ";
......@@ -249,33 +295,13 @@ Number of online processors is not implemented and returns -1, since
Windows kernel32 |GetSystemInfo| call is too complicated.
@<|sysconf| Win32 implementation@>=
#include <Windows.h>
#define _SC_PAGESIZE 1
#define _SC_PHYS_PAGES 2
#define _SC_AVPHYS_PAGES 3
#define _SC_NPROCESSORS_ONLN 4
@#
struct Win32MemoryStatus {
unsigned long dwLength;
unsigned long dwMemoryLoad;
unsigned int dwTotalPhys;
unsigned int dwAvailPhys;
unsigned int dwTotalPageFile;
unsigned int dwAvailPageFile;
unsigned int dwTotalVirtual;
unsigned int dwAvailVirtual;
Win32MemoryStatus();
};
@#
extern "C" {
void __stdcall GlobalMemoryStatus(Win32MemoryStatus *);
};
@#
Win32MemoryStatus::Win32MemoryStatus()
{
dwLength = sizeof(Win32MemoryStatus);
GlobalMemoryStatus(this);
}
@#
long sysconf(int name)
{
switch (name) {
......@@ -283,12 +309,14 @@ long sysconf(int name)
return 1024;
case _SC_PHYS_PAGES:@;
{
Win32MemoryStatus memstat;
MEMORYSTATUS memstat;
GlobalMemoryStatus(&memstat);
return memstat.dwTotalPhys/1024;
}
case _SC_AVPHYS_PAGES:@;
{
Win32MemoryStatus memstat;
MEMORYSTATUS memstat;
GlobalMemoryStatus(&memstat);
return memstat.dwAvailPhys/1024;
}
case _SC_NPROCESSORS_ONLN:@;
......
......@@ -17,8 +17,12 @@
#include "int_sequence.h"
#include <sys/time.h>
#include <stdio.h>
#ifdef _MSC_VER
# include <Winsock2.h>
#else
# include <sys/time.h>
#endif
#include <cstdio>
#include <iostream>
#include <fstream>
......
......@@ -10,8 +10,8 @@ This is a simple code defining an exception and two convenience macros.
#ifndef KORD_EXCEPTION_H
#define KORD_EXCEPTION_H
#include <string.h>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#define KORD_RAISE(mes) \
throw KordException(__FILE__, __LINE__, mes);
......
......@@ -16,7 +16,7 @@ and Geoff Kuenning.
#define MERSENNE_TWISTER_H
#include "random.h"
#include <string.h>
#include <cstring>
@<|MersenneTwister| class declaration@>;
@<|MersenneTwister| inline method definitions@>;
......
......@@ -6,7 +6,7 @@
#include "random.h"
#include <stdlib.h>
#include <cstdlib>
#include <limits>
#include <cmath>
......@@ -42,7 +42,7 @@ double RandomGenerator::normal()
@<|SystemRandomGenerator::uniform| code@>=
double SystemRandomGenerator::uniform()
{
#ifndef __MINGW32__
#if !defined(__MINGW32__) && !defined(_MSC_VER)
return drand48();
#else
return ((double)rand())/RAND_MAX;
......@@ -53,7 +53,7 @@ double SystemRandomGenerator::uniform()
@<|SystemRandomGenerator::initSeed| code@>=
void SystemRandomGenerator::initSeed(int seed)
{
#ifndef __MINGW32__
#if !defined(__MINGW32__) && !defined(_MSC_VER)
srand48(seed);
#else
srand(seed);
......
......@@ -5,8 +5,8 @@
#include "utils/cc/exception.h"
#include "dynamic_atoms.h"
#include <string.h>
#include <limits.h>
#include <cstring>
#include <climits>
using namespace ogp;
......
......@@ -4,7 +4,7 @@
#include "namelist.h"
#include <string.h>
#include <cstring>
using namespace ogp;
......
......@@ -6,8 +6,7 @@
#include "tree.h"
#include <stdlib.h>
#include <math.h>
#include <cstdlib>
#include <cmath>
#include <limits>
......
......@@ -10,7 +10,7 @@
#include "planner_builder.h"
#include "forw_subst_builder.h"
#include <stdlib.h>
#include <cstdlib>
#include <string>
#include <cmath>
......
......@@ -4,8 +4,8 @@
#include "dynare_params.h"
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
const char* help_str =
"usage: dynare++ [--help] [--version] [options] <model file>\n"
......
......@@ -7,6 +7,11 @@
#include <cmath>
#ifdef _MSC_VER
// For _finite()
# include <cfloat>
#endif
using namespace ogu;
/** This should not be greater than DBL_EPSILON^(1/2). */
......@@ -32,7 +37,11 @@ double GoldenSectionSearch::search(OneDFunction& f, double x1, double x2)
else
x = b + dx;
double fx = f.eval(x);
#ifndef _MSC_VER
if (! std::isfinite(fx))
#else
if (! _finite(fx))
#endif
return x1;
if (b-x1 > x2-b) {
// x is on the left from b
......@@ -69,7 +78,11 @@ double GoldenSectionSearch::search(OneDFunction& f, double x1, double x2)
bool GoldenSectionSearch::init_bracket(OneDFunction& f, double x1, double& x2, double& b)
{
double f1 = f.eval(x1);
#ifndef _MSC_VER
if (! std::isfinite(f1))
#else
if (! _finite(f1))
#endif
throw DynareException(__FILE__, __LINE__,
"Safer point not finite in GoldenSectionSearch::init_bracket");
......@@ -86,7 +99,11 @@ bool GoldenSectionSearch::init_bracket(OneDFunction& f, double x1, double& x2, d
double bsym = 2*x2 - b;
double fbsym = f.eval(bsym);
// now we know that f1, f2, and fb are finite
#ifndef _MSC_VER
if (std::isfinite(fbsym)) {
#else
if (_finite(fbsym)) {
#endif
// we have four numbers f1, fb, f2, fbsym, we test for the
// following combinations to find the bracket:
// [f1,f2,fbsym], [f1,fb,fbsym] and [f1,fb,fbsym]
......@@ -145,7 +162,11 @@ bool GoldenSectionSearch::search_for_finite(OneDFunction& f, double x1, double&
double f2 = f.eval(x2);
b = (1-golden)*x1 + golden*x2;
double fb = f.eval(b);
#ifndef _MSC_VER
found = std::isfinite(f2) && std::isfinite(fb);
#else
found = _finite(f2) && _finite(fb);
#endif
if (! found)
x2 = b;
cnt++;
......
......@@ -4,8 +4,8 @@
#include "BlockDiagonal.h"
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
BlockDiagonal::BlockDiagonal(const double* d, int d_size)
: QuasiTriangular(d, d_size),
......
......@@ -9,9 +9,9 @@
#include <dynblas.h>
#include <dynlapack.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <limits>
......
......@@ -8,7 +8,7 @@
#include "TriangularSylvester.h"
#include "IterativeSylvester.h"
#include <time.h>
#include <ctime>
GeneralSylvester::GeneralSylvester(int ord, int n, int m, int zero_cols,
const double* da, const double* db,
......
......@@ -8,7 +8,7 @@
#include <dynblas.h>
#include <stdio.h>
#include <cstdio>
#include <cmath>
using namespace std;
......
......@@ -7,7 +7,7 @@
#include "SylvMatrix.h"
#include "SylvException.h"
#include <stdio.h>
#include <cstdio>
QuasiTriangularZero::QuasiTriangularZero(int num_zeros, const double* d,
int d_size)
......
......@@ -4,8 +4,8 @@
#include "SylvException.h"
#include <string.h>
#include <stdio.h>
#include <cstring>
#include <cstdio>
SylvException::SylvException(const char* f, int l, const SylvException* s)
{
......
......@@ -8,8 +8,8 @@
#include <dynblas.h>
#include <dynlapack.h>
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#include <cmath>
void SylvMatrix::multLeftI(const SqSylvMatrix& m)
......
......@@ -10,9 +10,9 @@
# include <dynmex.h>
#endif
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
/**********************************************************/
/* SylvMemoryPool */
......
......@@ -5,8 +5,8 @@
#ifndef SYLV_PARAMS_H
#define SYLV_PARAMS_H
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
#if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE)
# include <dynmex.h>
......
......@@ -7,7 +7,7 @@
#include "KronUtils.h"
#include "BlockDiagonal.h"
#include <stdio.h>
#include <cstdio>
#include <cmath>
double TriangularSylvester::diag_zero = 1.e-15;
......
......@@ -9,9 +9,9 @@
#include <dynblas.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <limits>
......
......@@ -9,7 +9,7 @@
* to avoid running virtual method invokation mechanism. Some
* members, and methods are thus duplicated */
#include <stdio.h>
#include <cstdio>
class GeneralMatrix;
class ConstVector;
......
......@@ -4,8 +4,8 @@
#include "MMMatrix.h"
#include <stdio.h>
#include <string.h>
#include <cstdio>
#include <cstring>
MMMatrixIn::MMMatrixIn(const char* fname)
{
......
......@@ -18,9 +18,9 @@
#include "MMMatrix.h"
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cmath>
......
......@@ -8,7 +8,7 @@
#include "permutation.h"
#include "tl_exception.h"
#include <string.h>
#include <cstring>
@<|OrdSequence| method codes@>;
@<|Equivalence| method codes@>;
......
......@@ -6,7 +6,7 @@
@c
#include "fine_container.h"
#include <math.h>
#include <cmath>
@<|SizeRefinement| constructor code@>;
......@@ -21,7 +21,11 @@ SizeRefinement::SizeRefinement(const IntSequence& s, int nc, int max)
int nr = s[i]/max;
if (s[i] % max != 0)
nr++;
#ifndef _MSC_VER
int ss = (nr>0) ? (int)round(((double)s[i])/nr) : 0;
#else // MSVC doesn't respect C99 standard and doesn't define round(); use floor(x+0.5) instead
int ss = (nr>0) ? (int)floor((((double)s[i])/nr) + 0.5) : 0;
#endif
for (int j = 0; j < nr - 1; j++) {
rsizes.push_back(ss);
ind_map.push_back(i);
......
......@@ -8,8 +8,8 @@
#include "symmetry.h"
#include "tl_exception.h"
#include <stdio.h>
#include <limits.h>
#include <cstdio>
#include <climits>
@<|IntSequence| constructor code 1@>;
@<|IntSequence| constructor code 2@>;
......
......@@ -30,7 +30,7 @@ some instances do destroy the underlying data, and some not.
#define INT_SEQUENCE_H
#include <string.h>
#include <cstring>
#include <vector>
using namespace std;
......
......@@ -6,7 +6,7 @@
#include "kron_prod.h"
#include "tl_exception.h"
#include <stdio.h>
#include <cstdio>
@<|KronProdDimens| constructor code@>;
@<|KronProd::checkDimForMult| code@>;
......
......@@ -10,6 +10,11 @@
#include <cmath>
#ifdef _MSC_VER
// For _finite()
# include <cfloat>
#endif
@<|SparseTensor::insert| code@>;
@<|SparseTensor::isFinite| code@>;
@<|SparseTensor::getFoldIndexFillFactor| code@>;
......@@ -34,8 +39,13 @@ void SparseTensor::insert(const IntSequence& key, int r, double c)
"Row number out of dimension of tensor in SparseTensor::insert");
TL_RAISE_IF(key.size() != dimen(),
"Wrong length of key in SparseTensor::insert");
#ifndef _MSC_VER
TL_RAISE_IF(! std::isfinite(c),
"Insertion of non-finite value in SparseTensor::insert");
#else
TL_RAISE_IF(! _finite(c),
"Insertion of non-finite value in SparseTensor::insert");
#endif
iterator first_pos = m.lower_bound(key);
@<check that pair |key| and |r| is unique@>;
......@@ -62,7 +72,11 @@ bool SparseTensor::isFinite() const
bool res = true;
const_iterator run = m.begin();
while (res && run != m.end()) {
#ifndef _MSC_VER
if (! std::isfinite((*run).second.second))
#else
if (! _finite((*run).second.second))
#endif
res = false;
++run;
}
......
......@@ -89,7 +89,7 @@ member of |thread_group| and |detach_thread_group| classes.
# define pthread_cond_t void *
#endif
#include <stdio.h>
#include <cstdio>
#include <list>
#include <map>
......
......@@ -7,7 +7,7 @@
#include "symmetry.h"
#include "permutation.h"
#include <stdio.h>
#include <cstdio>
@<|Symmetry| constructor code@>;
@<|Symmetry::findClass| code@>;
......
......@@ -15,8 +15,8 @@ for this.
#ifndef TL_EXCEPTION_H
#define TL_EXCEPTION_H
#include <string.h>
#include <stdio.h>
#include <cstring>
#include <cstdio>
@<body of tl\_exception header@>;
......
......@@ -26,7 +26,7 @@ to allow submatrix construction from const reference arguments.
#include "GeneralMatrix.h"
#include <stdio.h>
#include <cstdio>
class TwoDMatrix;
@<|ConstTwoDMatrix| class declaration@>;
......
......@@ -4,7 +4,7 @@
#include "factory.h"
#include <cstdlib>
#include <math.h>
#include <cmath>
void Factory::init(const Symmetry& s, const IntSequence& nvs)