* Added back korderpert DLL to build system

* Fixes to Dynare++ for special LAPACK/BLAS integers in MATLAB
* Fixes to korderpert DLL for cross-platform compatibility


git-svn-id: https://www.dynare.org/svn/dynare/trunk@3009 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
sebastien 2009-10-02 10:23:49 +00:00
parent fdaf7a9921
commit 1443f112bb
17 changed files with 139 additions and 90 deletions

View File

@ -61,8 +61,9 @@ CPPFLAGS="$CPPFLAGS_SAVED"
# Don't use deprecated hash structures
AC_DEFINE([BOOST_NO_HASH])
# Libtool test for dlopen, disabled for the moment
#LT_LIB_DLLOAD
# Check for dlopen(), needed by korderpert DLL
AC_CHECK_LIB([dl], [dlopen], [LIBADD_DLOPEN="-ldl"], [])
AC_SUBST([LIBADD_DLOPEN])
AC_CHECK_PROG([PDFTEX], [pdftex], [pdftex])
AM_CONDITIONAL([HAVE_PDFTEX], [test "x$PDFTEX" != "x"])

View File

@ -164,12 +164,12 @@ void GaussConverterFunction::calcCholeskyFactor(const GeneralMatrix& vcov)
{
A = vcov;
int rows = A.numRows();
lapack_int rows = A.numRows();
for (int i = 0; i < rows; i++)
for (int j = i+1; j < rows; j++)
A.get(i,j) = 0.0;
int info;
lapack_int info;
dpotrf("L", &rows, A.base(), &rows, &info);
// todo: raise if |info!=1|
}

View File

@ -604,11 +604,11 @@ not work for semidefinite matrices.
void RandomShockRealization::choleskyFactor(const TwoDMatrix& v)
{
factor = v;
int rows = factor.nrows();
lapack_int rows = factor.nrows();
for (int i = 0; i < rows; i++)
for (int j = i+1; j < rows; j++)
factor.get(i,j) = 0.0;
int info;
lapack_int info;
dpotrf("L", &rows, factor.base(), &rows, &info);
KORD_RAISE_IF(info != 0,

View File

@ -20,7 +20,7 @@ double qz_criterium = 1.000001;
to select (return true) the pairs for which $\alpha<\beta$.
@<|order_eigs| function code@>=
int order_eigs(const double* alphar, const double* alphai, const double* beta)
lapack_int order_eigs(const double* alphar, const double* alphai, const double* beta)
{
return (*alphar * *alphar + *alphai * *alphai < *beta * *beta * qz_criterium);
}
@ -165,7 +165,7 @@ the same. The difference is only numerical error.
@
@<form matrix $D$@>=
int n = ypart.ny()+ypart.nboth;
lapack_int n = ypart.ny()+ypart.nboth;
TwoDMatrix matD(n, n);
matD.zeros();
matD.place(fypzero, 0, 0);
@ -189,15 +189,18 @@ the same. The difference is only numerical error.
@<solve generalized Schur@>=
TwoDMatrix vsl(n, n);
TwoDMatrix vsr(n, n);
int lwork = 100*n+16;
lapack_int lwork = 100*n+16;
Vector work(lwork);
IntSequence bwork(n);
int info;
lapack_int *bwork = new lapack_int[n];
lapack_int info;
lapack_int sdim2 = sdim;
dgges("N", "V", "S", order_eigs, &n, matE.getData().base(), &n,
matD.getData().base(), &n, &sdim, alphar.base(), alphai.base(),
matD.getData().base(), &n, &sdim2, alphar.base(), alphai.base(),
beta.base(), vsl.getData().base(), &n, vsr.getData().base(), &n,
work.base(), &lwork, &(bwork[0]), &info);
work.base(), &lwork, bwork, &info);
sdim = sdim2;
bk_cond = (sdim == ypart.nys());
delete[] bwork;
@ Here we setup submatrices of the matrix $Z$.

View File

@ -8,8 +8,6 @@
#include "kord_exception.h"
#include "korder.h"
#include <dynlapack.h>
@<|PLUMatrix| copy constructor@>;
@<|PLUMatrix::calcPLU| code@>;
@<|PLUMatrix::multInv| code@>;
@ -24,9 +22,9 @@
@
@<|PLUMatrix| copy constructor@>=
PLUMatrix::PLUMatrix(const PLUMatrix& plu)
: TwoDMatrix(plu), inv(plu.inv), ipiv(new int[nrows()])
: TwoDMatrix(plu), inv(plu.inv), ipiv(new lapack_int[nrows()])
{
memcpy(ipiv, plu.ipiv, nrows()*sizeof(int));
memcpy(ipiv, plu.ipiv, nrows()*sizeof(lapack_int));
}
@ -37,8 +35,8 @@ the end of their constructors.
@<|PLUMatrix::calcPLU| code@>=
void PLUMatrix::calcPLU()
{
int info;
int rows = nrows();
lapack_int info;
lapack_int rows = nrows();
inv = (const Vector&)getData();
dgetrf(&rows, &rows, inv.base(), &rows, ipiv, &info);
}
@ -50,9 +48,9 @@ void PLUMatrix::multInv(TwoDMatrix& m) const
{
KORD_RAISE_IF(m.nrows() != ncols(),
"The matrix is not square in PLUMatrix::multInv");
int info;
int mcols = m.ncols();
int mrows = m.nrows();
lapack_int info;
lapack_int mcols = m.ncols();
lapack_int mrows = m.nrows();
double* mbase = m.getData().base();
dgetrs("N", &mrows, &mcols, inv.base(), &mrows, ipiv,
mbase, &mrows, &info);

View File

@ -76,6 +76,8 @@ classes, which are defined here. These include: |PartitionY|,
#include "kord_exception.h"
#include "GeneralSylvester.h"
#include <dynlapack.h>
#include <cmath>
#define TYPENAME typename
@ -186,14 +188,14 @@ public:@;
PLUMatrix(int n)
: TwoDMatrix(n,n),
inv(nrows()*ncols()),
ipiv(new int[nrows()]) {}
ipiv(new lapack_int[nrows()]) {}
PLUMatrix(const PLUMatrix& plu);
virtual ~PLUMatrix()
{delete [] ipiv;}
void multInv(TwoDMatrix& m) const;
private:@;
Vector inv;
int* ipiv;
lapack_int* ipiv;
protected:@;
void calcPLU();
};

View File

@ -21,7 +21,7 @@ dynare___SOURCES = \
nlsolve.h \
$(GENERATED_FILES)
dynare___CPPFLAGS = -I../sylv/cc -I../tl/cc -I../kord -I../integ/cc -I.. -DDYNVERSION=\"$(PACKAGE_VERSION)\" -DPOSIX_THREADS
dynare___CPPFLAGS = -I../sylv/cc -I../tl/cc -I../kord -I../integ/cc -I.. -I$(top_srcdir)/mex/sources -DDYNVERSION=\"$(PACKAGE_VERSION)\" -DPOSIX_THREADS
dynare___LDADD = ../kord/libkord.a ../integ/cc/libinteg.a ../tl/cc/libtl.a ../parser/cc/libparser.a ../utils/cc/libutils.a ../sylv/cc/libsylv.a $(noinst_LIBRARIES) $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) $(PTHREAD_LIBS)
dynare___CXXFLAGS = $(PTHREAD_CFLAGS)

View File

@ -411,7 +411,7 @@ void ConstGeneralMatrix::multInvLeft(const char* trans, int mrows, int mcols, in
GeneralMatrix inv(*this);
lapack_int* ipiv = new lapack_int[rows];
lapack_int info;
lapack_int rows2 = rows, mrows2 = mrows, mcols2 = mcols, mld2 = mld;
lapack_int rows2 = rows, mcols2 = mcols, mld2 = mld;
dgetrf(&rows2, &rows2, inv.getData().base(), &rows2, ipiv, &info);
dgetrs(trans, &rows2, &mcols2, inv.base(), &rows2, ipiv, d,
&mld2, &info);

View File

@ -21,27 +21,27 @@ SymSchurDecomp::SymSchurDecomp(const GeneralMatrix& mata)
const char* jobz = "V";
const char* range = "A";
const char* uplo = "U";
int n = mata.numRows();
lapack_int n = mata.numRows();
GeneralMatrix tmpa(mata);
double* a = tmpa.base();
int lda = tmpa.getLD();
lapack_int lda = tmpa.getLD();
double dum;
double* vl = &dum;
double* vu = &dum;
int idum;
int* il = &idum;
int* iu = &idum;
lapack_int idum;
lapack_int* il = &idum;
lapack_int* iu = &idum;
double abstol = 0.0;
int m = n;
lapack_int m = n;
double* w = lambda.base();
double* z = q.base();
int ldz = q.getLD();
int* isuppz = new int[2*std::max(1,m)];
lapack_int ldz = q.getLD();
lapack_int* isuppz = new lapack_int[2*std::max(1,(int) m)];
double tmpwork;
int lwork = -1;
int tmpiwork;
int liwork = -1;
int info;
lapack_int lwork = -1;
lapack_int tmpiwork;
lapack_int liwork = -1;
lapack_int info;
// query for lwork and liwork
dsyevr(jobz, range, uplo, &n, a, &lda, vl, vu, il, iu, &abstol,
@ -50,7 +50,7 @@ SymSchurDecomp::SymSchurDecomp(const GeneralMatrix& mata)
liwork = tmpiwork;
// allocate work arrays
double* work = new double[lwork];
int* iwork = new int[liwork];
lapack_int* iwork = new lapack_int[liwork];
// do the calculation
dsyevr(jobz, range, uplo, &n, a, &lda, vl, vu, il, iu, &abstol,

View File

@ -12,14 +12,13 @@ if HAVE_BLAS
if HAVE_LAPACK
if HAVE_PTHREAD
if HAVE_MEXOPTS
#SUBDIRS += korderpert/matlab korderpert/tests
SUBDIRS += korderpert/matlab korderpert/tests
endif
if HAVE_MKOCTFILE
#SUBDIRS += korderpert/octave
SUBDIRS += korderpert/octave
endif
endif
endif
endif
EXTRA_DIST = mex.def mexFunction-MacOSX.map

View File

@ -1,40 +1,91 @@
vpath %.cpp $(top_srcdir)/mex/sources/korderpert
vpath %.cpp $(top_srcdir)/mex/sources/gensylv
vpath %.cpp $(top_srcdir)/mex/sources/korderpert $(top_srcdir)/dynare++/sylv/cc $(top_srcdir)/dynare++/tl/cc $(top_srcdir)/dynare++/kord $(top_srcdir)/dynare++/integ/cc $(top_srcdir)/dynare++/src
noinst_PROGRAMS = korderpert
#check_PROGRAMS = ramst1_dynamic fs2000k_dynamic
# Can't use korderpert_CPPFLAGS, because it interacts badly with VPATH
CPPFLAGS += -I$(top_srcdir)/dynare++/src -I$(top_srcdir)/dynare++/kord -I$(top_srcdir)/dynare++/tl/cc -I$(top_srcdir)/dynare++/utils/cc -I$(top_srcdir)/dynare++/sylv/cc
CPPFLAGS += -I$(top_srcdir)/dynare++/src -I$(top_srcdir)/dynare++/kord -I$(top_srcdir)/dynare++/tl/cc -I$(top_srcdir)/dynare++/utils/cc -I$(top_srcdir)/dynare++/sylv/cc -I$(top_srcdir)/dynare++/integ/cc -I$(top_srcdir)/mex/sources
# For Dynare++ thread implementation in tensor library
CPPFLAGS += -DPOSIX_THREADS
# For Dynare++ gensylv (so that it uses the right prototypes for BLAS/LAPACK)
CPPFLAGS += -DMATLAB
# So that we have mexFunction() in the library
CPPFLAGS += -DMATLAB_MEX_FILE
DEFS += -DPOSIX_THREADS
CXXFLAGS += $(PTHREAD_CFLAGS)
LIBS += $(LIBADD_DLOPEN) $(PTHREAD_LIBS) $(top_srcdir)/dynare++/kord/libkord.a $(top_srcdir)/dynare++/tl/cc/libtl.a $(top_srcdir)/dynare++/sylv/cc/libsylv.a $(top_srcdir)/dynare++/src/libnsolve.a
LIBS += $(LIBADD_DLOPEN)
KORD_SRCS = \
faa_di_bruno.cpp \
korder_stoch.cpp \
journal.cpp \
decision_rule.cpp \
dynamic_model.cpp \
random.cpp \
first_order.cpp \
normal_conjugate.cpp \
approximation.cpp \
global_check.cpp \
korder.cpp
SYLV_SRCS = \
IterativeSylvester.cpp \
QuasiTriangular.cpp \
QuasiTriangularZero.cpp \
GeneralMatrix.cpp \
GeneralSylvester.cpp \
SimilarityDecomp.cpp \
SylvException.cpp \
SchurDecompEig.cpp \
Vector.cpp \
TriangularSylvester.cpp \
SylvParams.cpp \
BlockDiagonal.cpp \
KronVector.cpp \
SylvMemory.cpp \
SymSchurDecomp.cpp \
SylvMatrix.cpp \
SchurDecomp.cpp \
KronUtils.cpp
TL_SRCS = \
normal_moments.cpp \
int_sequence.cpp \
tensor.cpp \
ps_tensor.cpp \
pyramid_prod2.cpp \
equivalence.cpp \
fine_container.cpp \
kron_prod.cpp \
t_polynomial.cpp \
symmetry.cpp \
stack_container.cpp \
twod_matrix.cpp \
sparse_tensor.cpp \
sthread.cpp \
gs_tensor.cpp \
pyramid_prod.cpp \
fs_tensor.cpp \
permutation.cpp \
rfs_tensor.cpp \
t_container.cpp \
tl_static.cpp
INTEG_SRCS = \
product.cpp \
quadrature.cpp \
quasi_mcarlo.cpp \
smolyak.cpp \
vector_function.cpp
nodist_korderpert_SOURCES = \
k_order_perturbation.cpp \
k_ord_dynare.cpp \
k_ord_dynare.h \
dynamic_dll.cpp \
dynamic_dll.h
dynamic_dll.h \
$(KORD_SRCS) \
$(TL_SRCS) \
$(SYLV_SRCS) \
$(INTEG_SRCS) \
nlsolve.cpp
#BUILT_SOURCES = ramst1_dynamic.c fs2000k_dynamic.c
#nodist_ramst1_dynamic_SOURCES = ramst1_dynamic.c
#nodist_fs2000k_dynamic_SOURCES = fs2000k_dynamic.c
#ramst1_dynamic.c: tests/ramst1.mod
# $(top_srcdir)/preprocessor/dynare_m $(top_srcdir)/mex/sources/korderpert/tests/ramst1.mod
#fs2000k_dynamic.c: tests/fs2000k.mod
# $(top_srcdir)/preprocessor/dynare_m $(top_srcdir)/mex/sources/korderpert/tests/fs2000k.mod
noinst_LIBRARIES = libkorderpert.a
nodist_libkorderpert_a_SOURCES = $(nodist_korderpert_SOURCES)

View File

@ -1,24 +1,19 @@
VPATH = $(top_srcdir)/mex/sources/korderpert:$(top_srcdir)/mex/sources/korderpert/tests
vpath %.cpp $(top_srcdir)/mex/sources/korderpert/tests
check_PROGRAMS = k_order_test_main
CPPFLAGS += -DPOSIX_THREADS -I$(top_srcdir)/dynare++/src -I$(top_srcdir)/dynare++/kord -I$(top_srcdir)/dynare++/tl/cc -I$(top_srcdir)/dynare++/utils/cc -I$(top_srcdir)/dynare++/sylv/cc -I$(MATLAB)/extern/include -I$(top_srcdir)/mex/sources/korderpert
CPPFLAGS += -I$(top_srcdir)/dynare++/src -I$(top_srcdir)/dynare++/kord -I$(top_srcdir)/dynare++/tl/cc -I$(top_srcdir)/dynare++/utils/cc -I$(top_srcdir)/dynare++/sylv/cc -I$(MATLAB)/extern/include -I$(top_srcdir)/mex/sources/korderpert -I$(top_srcdir)/mex/sources
CPPFLAGS += -DMEXEXT=\"$(MEXEXT)\"
CPPFLAGS += $(MATLAB_CPPFLAGS)
DEFS += -DPOSIX_THREADS -DMATLAB_MEX_FILE $(MATLAB_DEFS)
CXXFLAGS += $(PTHREAD_CFLAGS)
LIBS += $(LIBADD_DLOPEN) $(top_srcdir)/dynare++/kord/libkord.a $(top_srcdir)/dynare++/tl/cc/libtl.a $(top_srcdir)/dynare++/sylv/cc/libsylv.a $(top_srcdir)/dynare++/src/libnsolve.a $(MATLAB_LIBS)
LDFLAGS += $(subst -shared,,$(MATLAB_LDFLAGS))
LDFLAGS += -Wl,-rpath,$(MATLAB)/bin/$(MATLAB_ARCH)
nodist_k_order_test_main_SOURCES = \
k_order_test_main.cpp \
k_order_perturbation.cpp \
k_ord_dynare.cpp \
k_ord_dynare.h \
dynamic_dll.cpp \
dynamic_dll.h
nodist_k_order_test_main_SOURCES = k_order_test_main.cpp
k_order_test_main_LDADD = ../matlab/libkorderpert.a $(MATLAB_LIBS) $(LIBADD_DLOPEN)

View File

@ -92,7 +92,7 @@ DynamicModelDLL::DynamicModelDLL(const char *modName, const int y_length, const
{
if (sExt == NULL)
sExt = MEXEXT;
#ifdef WINDOWS
#ifdef _WIN32
HINSTANCE dynamicHinstance;
// dynamicHinstance=::LoadLibraryEx(strcat(fNname,"_.dll"),NULL,DONT_RESOLVE_DLL_REFERENCES);//sExt); //"_.dll");
dynamicHinstance = ::LoadLibrary(strcat(fName, sExt)); //.dll); //"_.dll");
@ -109,14 +109,14 @@ DynamicModelDLL::DynamicModelDLL(const char *modName, const int y_length, const
if ((dynamicHinstance == NULL) || dlerror())
{
cerr << dlerror() << endl;
mexPrintf("MexPrintf:Error loading DLL: %s", dlerror);
mexPrintf("MexPrintf:Error loading DLL");
throw 1;
}
Dynamic = (DynamicFn) dlsym(dynamicHinstance, "Dynamic");
if ((Dynamic == NULL) || dlerror())
{
cerr << dlerror() << endl;
mexPrintf("MexPrintf:Error finding DLL function: %s", dlerror);
mexPrintf("MexPrintf:Error finding DLL function");
throw 2;
}
#endif
@ -142,7 +142,7 @@ DynamicModelDLL::DynamicModelDLL(const char *modName, const int y_length, const
int
DynamicModelDLL::close()
{
#ifdef WINDOWS
#ifdef _WIN32
// MS FreeLibrary returns non 0 if OK, 0 if fails.
bool rb = FreeLibrary(dynamicHinstance);
if (rb)

View File

@ -24,7 +24,7 @@
// K_ORDER_PERTURBATION_API functions as being imported from a DLL, wheras this DLL sees symbols
// defined with this macro as being exported.
#ifdef WINDOWS
#ifdef _WIN32
# ifdef K_ORDER_PERTURBATION_EXPORTS
# define K_ORDER_PERTURBATION_API __declspec(dllexport)
# else
@ -38,10 +38,10 @@
#endif
#include <string>
#include "mex.h"
#include <dynmex.h>
// <model>_Dynamic DLL pointer
#ifdef WINDOWS
#ifdef _WIN32
typedef void *(DynamicFn)
#else // linux
typedef void (*DynamicFn)
@ -62,7 +62,7 @@ const int MAX_MODEL_NAME = 100;
class DynamicModelDLL
{
private:
#ifdef WINDOWS
#ifdef _WIN32
DynamicFn *Dynamic; // pointer to the Dynamic function in DLL
#else
DynamicFn Dynamic; // pointer to the Dynamic function in DLL
@ -72,7 +72,7 @@ private:
const int nMax_lag; // no of lags
const int nExog; // no of exogenous
// const char * sExt; // dynamic file extension: dll, mexw32, ...
#ifdef WINDOWS
#ifdef _WIN32
HINSTANCE dynamicHinstance; // DLL instance pointer in Windows
#else // linux
void *dynamicHinstance; // and in Linux

View File

@ -24,7 +24,7 @@
#include "k_ord_dynare.h"
#include "dynamic_dll.h"
#include "mex.h"
#include <dynmex.h>
#include "memory_file.h"

View File

@ -83,7 +83,7 @@ CK_order_perturbation::CK_order_perturbation()
#endif // _MSC_VER && WINDOWS
#ifdef MATLAB_MEX_FILE // exclude mexFunction for other applications
#if defined(MATLAB_MEX_FILE) || defined(OCTAVE_MEX_FILE) // exclude mexFunction for other applications
extern "C" {
// mexFunction: Matlab Inerface point and the main application driver

View File

@ -34,7 +34,7 @@ main(int argc, char *argv[])
double qz_criterium = 1+1e-6;
const int check_flag = 0;
const char *fName = "fs2000k"; //mxArrayToString(mFname);
const char *fName = "./fs2000k"; //mxArrayToString(mFname);
const char *dfExt = NULL; //Dyanamic file extension, e.g.".dll";
#ifdef DEBUG