k-order perturbation DLL:
* removed existing build system * reorganized source: separated test files from the rest, removed obsolete test files * incorporated the DLL and the standalone test executable to the new build system * minor fixes to ensure compilation git-svn-id: https://www.dynare.org/svn/dynare/trunk@2959 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
45acc68b8b
commit
02640c3e43
|
@ -1,4 +1,4 @@
|
||||||
SUBDIRS = preprocessor doc tests mex/build
|
SUBDIRS = preprocessor doc tests
|
||||||
|
|
||||||
if HAVE_BLAS
|
if HAVE_BLAS
|
||||||
if HAVE_LAPACK
|
if HAVE_LAPACK
|
||||||
|
@ -8,6 +8,9 @@ endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# MEX must be built after dynare++ (because of kordepert)
|
||||||
|
SUBDIRS += mex/build
|
||||||
|
|
||||||
ACLOCAL_AMFLAGS = -I m4
|
ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
|
|
20
configure.ac
20
configure.ac
|
@ -25,6 +25,8 @@ AM_INIT_AUTOMAKE([-Wall -Werror foreign])
|
||||||
AC_PROG_CC
|
AC_PROG_CC
|
||||||
AC_PROG_CXX
|
AC_PROG_CXX
|
||||||
|
|
||||||
|
AC_CANONICAL_HOST
|
||||||
|
|
||||||
# Use C++ for testing headers
|
# Use C++ for testing headers
|
||||||
AC_LANG([C++])
|
AC_LANG([C++])
|
||||||
|
|
||||||
|
@ -32,8 +34,19 @@ CXXFLAGS="$CXXFLAGS -Wall"
|
||||||
|
|
||||||
AC_PROG_RANLIB
|
AC_PROG_RANLIB
|
||||||
|
|
||||||
|
AC_MSG_CHECKING([for compiler flag to generate position independent code])
|
||||||
|
case ${host_os} in
|
||||||
|
*cygwin* | *mingw*)
|
||||||
|
PICFLAG=""
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
PICFLAG="-fPIC"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
AC_MSG_RESULT($PICFLAG)
|
||||||
|
AC_SUBST(PICFLAG)
|
||||||
|
|
||||||
AC_PROG_LN_S
|
AC_PROG_LN_S
|
||||||
AC_CANONICAL_HOST
|
|
||||||
case ${host_os} in
|
case ${host_os} in
|
||||||
*cygwin*)
|
*cygwin*)
|
||||||
LN_S="cp -p" # Cygwin symbolic links are not understood by MATLAB
|
LN_S="cp -p" # Cygwin symbolic links are not understood by MATLAB
|
||||||
|
@ -60,6 +73,8 @@ CPPFLAGS="$CPPFLAGS_SAVED"
|
||||||
# Don't use deprecated hash structures
|
# Don't use deprecated hash structures
|
||||||
AC_DEFINE([BOOST_NO_HASH])
|
AC_DEFINE([BOOST_NO_HASH])
|
||||||
|
|
||||||
|
LT_LIB_DLLOAD
|
||||||
|
|
||||||
AC_CHECK_PROG([PDFTEX], [pdftex], [pdftex])
|
AC_CHECK_PROG([PDFTEX], [pdftex], [pdftex])
|
||||||
AM_CONDITIONAL([HAVE_PDFTEX], [test "x$PDFTEX" != "x"])
|
AM_CONDITIONAL([HAVE_PDFTEX], [test "x$PDFTEX" != "x"])
|
||||||
|
|
||||||
|
@ -195,6 +210,9 @@ AC_CONFIG_FILES([Makefile
|
||||||
mex/build/gensylv/matlab/Makefile
|
mex/build/gensylv/matlab/Makefile
|
||||||
mex/build/bytecode/octave/Makefile
|
mex/build/bytecode/octave/Makefile
|
||||||
mex/build/bytecode/matlab/Makefile
|
mex/build/bytecode/matlab/Makefile
|
||||||
|
mex/build/korderpert/octave/Makefile
|
||||||
|
mex/build/korderpert/matlab/Makefile
|
||||||
|
mex/build/korderpert/tests/Makefile
|
||||||
])
|
])
|
||||||
|
|
||||||
# Construct final output message
|
# Construct final output message
|
||||||
|
|
|
@ -56,6 +56,9 @@ libkord_a_SOURCES = $(CWEBSRC) $(GENERATED_FILES)
|
||||||
libkord_a_CPPFLAGS = -I../sylv/cc -I../tl/cc -I../integ/cc -DPOSIX_THREADS
|
libkord_a_CPPFLAGS = -I../sylv/cc -I../tl/cc -I../integ/cc -DPOSIX_THREADS
|
||||||
libkord_a_CXXFLAGS = $(PTHREAD_CFLAGS)
|
libkord_a_CXXFLAGS = $(PTHREAD_CFLAGS)
|
||||||
|
|
||||||
|
# Generate position independent code for k-order DLL
|
||||||
|
libkord_a_CXXFLAGS += $(PICFLAG)
|
||||||
|
|
||||||
BUILT_SOURCES = $(GENERATED_FILES)
|
BUILT_SOURCES = $(GENERATED_FILES)
|
||||||
|
|
||||||
EXTRA_DIST = main.web
|
EXTRA_DIST = main.web
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
bin_PROGRAMS = dynare++
|
bin_PROGRAMS = dynare++
|
||||||
|
|
||||||
|
noinst_LIBRARIES = libnsolve.a
|
||||||
|
|
||||||
GENERATED_FILES = dynglob_ll.cc dynglob_tab.cc dynglob_tab.hh
|
GENERATED_FILES = dynglob_ll.cc dynglob_tab.cc dynglob_tab.hh
|
||||||
|
|
||||||
dynare___SOURCES = \
|
dynare___SOURCES = \
|
||||||
|
@ -12,19 +14,22 @@ dynare___SOURCES = \
|
||||||
dynare3.h \
|
dynare3.h \
|
||||||
dynare_exception.h \
|
dynare_exception.h \
|
||||||
dynare_params.cpp \
|
dynare_params.cpp \
|
||||||
nlsolve.cpp \
|
|
||||||
planner_builder.h \
|
planner_builder.h \
|
||||||
dynare_atoms.cpp \
|
dynare_atoms.cpp \
|
||||||
dynare_model.cpp \
|
dynare_model.cpp \
|
||||||
dynare_params.h \
|
dynare_params.h \
|
||||||
forw_subst_builder.cpp \
|
forw_subst_builder.cpp \
|
||||||
nlsolve.h \
|
|
||||||
$(GENERATED_FILES)
|
$(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.. -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 $(LAPACK_LIBS) $(BLAS_LIBS) $(LIBS) $(FLIBS) $(PTHREAD_LIBS)
|
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)
|
dynare___CXXFLAGS = $(PTHREAD_CFLAGS)
|
||||||
|
|
||||||
|
# Put nlsolve in a separate library, with position independent code, for k-order DLL
|
||||||
|
libnsolve_a_SOURCES = nlsolve.cpp nlsolve.h
|
||||||
|
libnsolve_a_CPPFLAGS = $(dynare___CPPFLAGS)
|
||||||
|
libnsolve_a_CXXFLAGS = $(PICFLAG)
|
||||||
|
|
||||||
BUILT_SOURCES = $(GENERATED_FILES)
|
BUILT_SOURCES = $(GENERATED_FILES)
|
||||||
EXTRA_DIST = dynglob.lex dynglob.y
|
EXTRA_DIST = dynglob.lex dynglob.y
|
||||||
|
|
||||||
|
|
|
@ -40,3 +40,6 @@ libsylv_a_SOURCES = \
|
||||||
SchurDecomp.cpp \
|
SchurDecomp.cpp \
|
||||||
KronVector.h \
|
KronVector.h \
|
||||||
KronUtils.cpp
|
KronUtils.cpp
|
||||||
|
|
||||||
|
# Generate position independent code for k-order DLL
|
||||||
|
libsylv_a_CXXFLAGS = $(PICFLAG)
|
||||||
|
|
|
@ -94,6 +94,9 @@ libtl_a_SOURCES = $(CWEBSRC) $(GENERATED_FILES)
|
||||||
libtl_a_CPPFLAGS = -I../../sylv/cc -DPOSIX_THREADS
|
libtl_a_CPPFLAGS = -I../../sylv/cc -DPOSIX_THREADS
|
||||||
libtl_a_CXXFLAGS = $(PTHREAD_CFLAGS)
|
libtl_a_CXXFLAGS = $(PTHREAD_CFLAGS)
|
||||||
|
|
||||||
|
# Generate position independent code for k-order DLL
|
||||||
|
libtl_a_CXXFLAGS += $(PICFLAG)
|
||||||
|
|
||||||
BUILT_SOURCES = $(GENERATED_FILES)
|
BUILT_SOURCES = $(GENERATED_FILES)
|
||||||
|
|
||||||
EXTRA_DIST = main.web
|
EXTRA_DIST = main.web
|
||||||
|
|
|
@ -167,6 +167,15 @@ else
|
||||||
end
|
end
|
||||||
disp([ message 'Bytecode evaluation.' ])
|
disp([ message 'Bytecode evaluation.' ])
|
||||||
|
|
||||||
|
% Test if k-order perturbation DLL is present
|
||||||
|
if exist('korderpert') == 3
|
||||||
|
remove_path_to_mex = 0;
|
||||||
|
message = '[mex] ';
|
||||||
|
else
|
||||||
|
message = '[no] ';
|
||||||
|
end
|
||||||
|
disp([ message 'k-order perturbation.' ])
|
||||||
|
|
||||||
if remove_path_to_mex
|
if remove_path_to_mex
|
||||||
rmpath(path_to_mex_files);
|
rmpath(path_to_mex_files);
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,4 +8,18 @@ if HAVE_MEXOPTS
|
||||||
SUBDIRS += mjdgges/matlab kronecker/matlab gensylv/matlab bytecode/matlab
|
SUBDIRS += mjdgges/matlab kronecker/matlab gensylv/matlab bytecode/matlab
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
if HAVE_BLAS
|
||||||
|
if HAVE_LAPACK
|
||||||
|
if HAVE_PTHREAD
|
||||||
|
if HAVE_MEXOPTS
|
||||||
|
SUBDIRS += korderpert/matlab korderpert/tests
|
||||||
|
endif
|
||||||
|
if HAVE_MKOCTFILE
|
||||||
|
SUBDIRS += korderpert/octave
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
|
||||||
EXTRA_DIST = mex.def
|
EXTRA_DIST = mex.def
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
CC := gcc
|
|
||||||
DEBUG := yes
|
|
||||||
MATLAB := 1
|
|
||||||
DYNAREPPDIR = /home/michel/dynare/svn/dynare++/dynare++
|
|
||||||
# George
|
|
||||||
#MATLAB_PATH := c:/"Program Files"/MATLAB_SV71
|
|
||||||
#MEX_SUFFIX := dll
|
|
||||||
#LDFLAGS := -Wl,-L"c:/Program Files"/MATLAB_SV71/extern/lib/win32/microsoft/ \
|
|
||||||
# -Wl,-llibmex -Wl,-llibmx -Wl,-llibmwlapack -Wl,-llibdflapack \
|
|
||||||
# -lg2c -lmingw32 -lstdc++
|
|
||||||
# Michel
|
|
||||||
MATLAB_PATH := /home/michel/usr/bin/matlab
|
|
||||||
#MATLAB_PATH := /home/michel/usr/local/bin/matlab7.8
|
|
||||||
MEX = $(MATLAB_PATH)/bin/mex
|
|
||||||
MEX_SUFFIX := mexa64
|
|
||||||
CXXFLAGS := -fPIC -I$(DYNAREPPDIR)/tl/cc -I$(DYNAREPPDIR)/kord -I$(DYNAREPPDIR)/sylv/cc -I$(DYNAREPPDIR)/utils/cc -I$(DYNAREPPDIR)/src -I$(MATLAB_PATH)/extern/include -DDEBUG -DPOSIX_THREADS
|
|
||||||
LDFLAGS := -Wl,-L$(MATLAB_PATH)/bin/glnxa64 -lmwlapack -lmwblas
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
k_order_perturbation project status
|
||||||
|
|
||||||
|
NOTE: The dll (mexw32 or so) is called from new Matlab Dynare function dr1_k_order
|
||||||
|
derived from dr1, after set_state_space as:
|
||||||
|
|
||||||
|
[ysteady, ghx_u]=k_ord_dynare_perturbation(dr,task,M_,options_, oo_, ['.' mexext])
|
||||||
|
|
||||||
|
where last term is optional but it will default to .dll on windows and .so on linux.
|
||||||
|
|
||||||
|
dr1_k_order is called by amended resol.m:
|
||||||
|
|
||||||
|
elseif(options_.use_k_order==1)&& (check_flag == 0)
|
||||||
|
[dr,info,M_,options_,oo_] = dr1_k_order(dr,check_flag,M_,options_,oo_);
|
||||||
|
else
|
||||||
|
|
||||||
|
and requirese options to be set
|
||||||
|
|
||||||
|
options_.use_k_order=1;
|
||||||
|
|
||||||
|
==================
|
||||||
|
Tests:
|
||||||
|
|
||||||
|
first_order.m is matlab emulation of Dynare++ c++ first_order.cpp for testing pruposes
|
||||||
|
|
||||||
|
|
||||||
|
==================
|
||||||
|
ToDO:
|
||||||
|
==================
|
||||||
|
1) amend <model>.m to use Dynamic_mexopts.bat
|
||||||
|
|
||||||
|
mex -f Dynamic_mexopts.bat -O fs2000k_no_both_UR_dynamic.c
|
||||||
|
|
||||||
|
or amend preprocessor to make mex to export Dynamic() function as well as mexFunction() as the Dynamic_mexopts.bat does, e.g.:
|
||||||
|
|
||||||
|
set LINKFLAGS=/dll /export:Dynamic /export:%ENTRYPOINT% /MAP ....
|
||||||
|
|
||||||
|
2) make k_order_perturbation handle models which have the "both" variables (i.e. variables that appear both as lag and as lead)
|
|
@ -90,8 +90,9 @@ DynamicModelDLL::DynamicModelDLL(const char *modName, const int y_length, const
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (sExt == NULL)
|
||||||
|
sExt = MEXEXT;
|
||||||
#ifdef WINDOWS
|
#ifdef WINDOWS
|
||||||
if (sExt == NULL) sExt = (".dll");
|
|
||||||
HINSTANCE dynamicHinstance;
|
HINSTANCE dynamicHinstance;
|
||||||
// dynamicHinstance=::LoadLibraryEx(strcat(fNname,"_.dll"),NULL,DONT_RESOLVE_DLL_REFERENCES);//sExt); //"_.dll");
|
// dynamicHinstance=::LoadLibraryEx(strcat(fNname,"_.dll"),NULL,DONT_RESOLVE_DLL_REFERENCES);//sExt); //"_.dll");
|
||||||
dynamicHinstance = ::LoadLibrary(strcat(fName, sExt)); //.dll); //"_.dll");
|
dynamicHinstance = ::LoadLibrary(strcat(fName, sExt)); //.dll); //"_.dll");
|
||||||
|
@ -104,7 +105,6 @@ DynamicModelDLL::DynamicModelDLL(const char *modName, const int y_length, const
|
||||||
Dynamic = (DynamicFn *) ::GetProcAddress(dynamicHinstance, "Dynamic");
|
Dynamic = (DynamicFn *) ::GetProcAddress(dynamicHinstance, "Dynamic");
|
||||||
|
|
||||||
#else // __linux__
|
#else // __linux__
|
||||||
if (sExt == NULL) sExt = (".so");
|
|
||||||
dynamicHinstance = dlopen(strcat(fName, sExt), RTLD_NOW);
|
dynamicHinstance = dlopen(strcat(fName, sExt), RTLD_NOW);
|
||||||
if ((dynamicHinstance == NULL) || dlerror())
|
if ((dynamicHinstance == NULL) || dlerror())
|
||||||
{
|
{
|
|
@ -103,7 +103,7 @@ public:
|
||||||
/*********************************************/
|
/*********************************************/
|
||||||
// The following only implements DynamicModel with help of ogdyn::DynareModel
|
// The following only implements DynamicModel with help of ogdyn::DynareModel
|
||||||
// instantiation of pure abstract DynamicModel decl. in dynamic_model.h
|
// instantiation of pure abstract DynamicModel decl. in dynamic_model.h
|
||||||
//class DynamicModelDLL;
|
class DynamicModelDLL;
|
||||||
class KordpJacobian;
|
class KordpJacobian;
|
||||||
class KordpDynare : public DynamicModel
|
class KordpDynare : public DynamicModel
|
||||||
{
|
{
|
|
@ -347,7 +347,7 @@ extern "C" {
|
||||||
|
|
||||||
/* Write derivative outputs into memory map */
|
/* Write derivative outputs into memory map */
|
||||||
map<string, ConstTwoDMatrix> mm;
|
map<string, ConstTwoDMatrix> mm;
|
||||||
app.getFoldDecisionRule().writeMMap(&mm);
|
app.getFoldDecisionRule().writeMMap(mm, string());
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
app.getFoldDecisionRule().print();
|
app.getFoldDecisionRule().print();
|
|
@ -1,52 +0,0 @@
|
||||||
include ../Makefile.include
|
|
||||||
all: k_orddbgtest
|
|
||||||
#all: k_order_perturbation.mexa64
|
|
||||||
|
|
||||||
k_order_test_main.o: k_order_test_main.cpp
|
|
||||||
gcc -DMATLAB_MEX_FILE -g -DDEBUG -DPOSIX_THREADS -I$(MATLAB_PATH)/extern/include -I $(DYNAREPPDIR)/src -I $(DYNAREPPDIR)/kord -I $(DYNAREPPDIR)/tl/cc -I $(DYNAREPPDIR)/utils/cc/ -I $(DYNAREPPDIR)/sylv/cc/ -c k_order_test_main.cpp
|
|
||||||
|
|
||||||
k_ord_dynare.o: k_ord_dynare.cpp k_ord_dynare.h dynamic_dll.h
|
|
||||||
gcc -DMATLAB_MEX_FILE -g -DDEBUG -DPOSIX_THREADS -I$(MATLAB_PATH)/extern/include -I $(DYNAREPPDIR)/src -I $(DYNAREPPDIR)/kord -I $(DYNAREPPDIR)/tl/cc -I $(DYNAREPPDIR)/utils/cc/ -I $(DYNAREPPDIR)/sylv/cc/ -fPIC -c k_ord_dynare.cpp
|
|
||||||
|
|
||||||
k_order_perturbation.o: k_order_perturbation.cpp dynamic_dll.h
|
|
||||||
gcc -DMATLAB_MEX_FILE -g -DDEBUG -DPOSIX_THREADS -I$(MATLAB_PATH)/extern/include -I $(DYNAREPPDIR)/src -I $(DYNAREPPDIR)/kord -I $(DYNAREPPDIR)/tl/cc -I $(DYNAREPPDIR)/utils/cc/ -I $(DYNAREPPDIR)/sylv/cc/ -fPIC -c k_order_perturbation.cpp
|
|
||||||
|
|
||||||
dynamic_dll.o: dynamic_dll.cpp dynamic_dll.h
|
|
||||||
gcc -DMATLAB_MEX_FILE -g -DDEBUG -DPOSIX_THREADS -I$(MATLAB_PATH)/extern/include -I $(DYNAREPPDIR)/src -I $(DYNAREPPDIR)/kord -I $(DYNAREPPDIR)/tl/cc -I $(DYNAREPPDIR)/utils/cc/ -I $(DYNAREPPDIR)/sylv/cc/ -fPIC -c k_order_perturbation.cpp
|
|
||||||
|
|
||||||
nlsolve.o: $(DYNAREPPDIR)/src/nlsolve.cpp
|
|
||||||
gcc -DMATLAB_MEX_FILE -g -DDEBUG -DPOSIX_THREADS -I$(MATLAB_PATH)/extern/include -I $(DYNAREPPDIR)/src -I $(DYNAREPPDIR)/kord -I $(DYNAREPPDIR)/tl/cc -I $(DYNAREPPDIR)/utils/cc/ -I $(DYNAREPPDIR)/sylv/cc/ -fPIC -c k_order_test_main.cpp -c k_ord_dynare.cpp -c k_order_perturbation.cpp -c $(DYNAREPPDIR)/src/nlsolve.cpp
|
|
||||||
|
|
||||||
|
|
||||||
fs2000a_dynamic.o: fs2000a_dynamic.c
|
|
||||||
gcc -g -c -I$(MATLAB_PATH)/extern/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "fs2000a_dynamic.c"
|
|
||||||
|
|
||||||
mexversion.o: $(MATLAB_PATH)/extern/src/mexversion.c
|
|
||||||
gcc -c -I$(MATLAB_PATH)/extern/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "$(MATLAB_PATH)/extern/src/mexversion.c"
|
|
||||||
|
|
||||||
fs2000a_dynamic.so: fs2000a_dynamic.o mexversion.o dynamic.map
|
|
||||||
# gcc -O -pthread -shared -Wl,--version-script,dynamic.map -Wl,--no-undefined -o "fs2000a_dynamic.so" fs2000a_dynamic.o mexversion.o -Wl,-rpath-link,$(MATLAB_PATH)/bin/glnxa64 -L$(MATLAB_PATH)/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
|
|
||||||
gcc -O -pthread -shared -Wl,--no-undefined -o "fs2000a_dynamic.so" fs2000a_dynamic.o mexversion.o -Wl,-rpath-link,$(MATLAB_PATH)/bin/glnxa64 -L$(MATLAB_PATH)/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
|
|
||||||
|
|
||||||
fs2000k_dynamic.o: fs2000k_dynamic.c
|
|
||||||
gcc -g -c -I$(MATLAB_PATH)/extern/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "fs2000k_dynamic.c"
|
|
||||||
|
|
||||||
fs2000k_dynamic.so: fs2000k_dynamic.o mexversion.o dynamic.map
|
|
||||||
# gcc -O -pthread -shared -Wl,--version-script,dynamic.map -Wl,--no-undefined -o "fs2000k_dynamic.so" fs2000k_dynamic.o mexversion.o -Wl,-rpath-link,$(MATLAB_PATH)/bin/glnxa64 -L$(MATLAB_PATH)/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
|
|
||||||
gcc -O -pthread -shared -Wl,--no-undefined -o "fs2000k_dynamic.so" fs2000k_dynamic.o mexversion.o -Wl,-rpath-link,$(MATLAB_PATH)/bin/glnxa64 -L$(MATLAB_PATH)/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
|
|
||||||
|
|
||||||
ramst1_dynamic.o: ramst1_dynamic.c
|
|
||||||
gcc -g -c -I$(MATLAB_PATH)/extern/include -DMATLAB_MEX_FILE -ansi -D_GNU_SOURCE -fexceptions -fPIC -fno-omit-frame-pointer -pthread -DMX_COMPAT_32 -O -DNDEBUG "ramst1_dynamic.c"
|
|
||||||
|
|
||||||
ramst1_dynamic.mexa64: ramst1_dynamic.o mexversion.o dynamic.map
|
|
||||||
gcc -O -pthread -shared -Wl,--no-undefined -o "ramst1_dynamic.mexa64" ramst1_dynamic.o mexversion.o -Wl,-rpath-link,$(MATLAB_PATH)/bin/glnxa64 -L$(MATLAB_PATH)/bin/glnxa64 -lmx -lmex -lmat -lm -lstdc++
|
|
||||||
|
|
||||||
|
|
||||||
k_orddbgtest: k_order_test_main.o k_ord_dynare.o dynamic_dll.o k_order_perturbation.o nlsolve.o dynarelib.a
|
|
||||||
gcc -DMATLAB_MEX_FILE -g -DDEBUG -DPOSIX_THREADS -o k_orddbgtest k_order_test_main.o k_ord_dynare.o k_order_perturbation.o nlsolve.o dynarelib.a -Wl,-rpath,$(MATLAB_PATH)/bin/glnxa64 -Wl,-rpath,$(MATLAB_PATH)/sys/os/glnxa64 -Wl,-rpath,. -L$(MATLAB_PATH)/bin/glnxa64 -lmex -lmx -lmwlapack -lmwblas -lmat -lm -lstdc++
|
|
||||||
|
|
||||||
k_orddbgtest_ramst1: k_order_test_main_ramst1.o k_ord_dynare.o dynamic_dll.o k_order_perturbation.o nlsolve.o dynarelib.a
|
|
||||||
gcc -DMATLAB_MEX_FILE -g -DDEBUG -DPOSIX_THREADS -o k_orddbgtest_ramst1 k_order_test_main_ramst1.o k_ord_dynare.o k_order_perturbation.o nlsolve.o dynarelib.a -Wl,-rpath,$(MATLAB_PATH)/bin/glnxa64 -Wl,-rpath,$(MATLAB_PATH)/sys/os/glnxa64 -Wl,-rpath,. -L$(MATLAB_PATH)/bin/glnxa64 -lmex -lmx -lmwlapack -lmwblas -lmat -lm -lstdc++
|
|
||||||
|
|
||||||
k_order_perturbation.mexa64: k_order_perturbation.o k_ord_dynare.o dynamic_dll.o nlsolve.o dynarelib.a
|
|
||||||
$(MEX) -v -DMATLAB_MEX_FILE -g -DDEBUG -DPOSIX_THREADS -I$(MATLAB_PATH)/extern/include -I$(DYNAREPPDIR)/src -I$(DYNAREPPDIR)/kord -I$(DYNAREPPDIR)/tl/cc -I$(DYNAREPPDIR)/utils/cc/ -I$(DYNAREPPDIR)/sylv/cc/ k_order_perturbation.cpp k_ord_dynare.o nlsolve.o dynarelib.a -lmwlapack -lmwblas -ldl -lstdc++ LDFLAGS='-pthread -shared -Wl,--version-script,$(MATLAB_PATH)/extern/lib/glnxa64/mexFunction.map -Wl,--no-undefined -Wl,-rpath,.'
|
|
|
@ -1,84 +0,0 @@
|
||||||
k_order_perturbation project status
|
|
||||||
|
|
||||||
Last upate: 3/3/09
|
|
||||||
|
|
||||||
Makefiles are not complete and in final verison yet
|
|
||||||
but they and C++ files are ready for creation of a library
|
|
||||||
that can be linked with the set of k_order_perturbation
|
|
||||||
Dynare extensions:
|
|
||||||
|
|
||||||
k_order_perturbation.cpp (and .h)
|
|
||||||
k_ord_dynare.cpp (and .h)
|
|
||||||
|
|
||||||
NOTE: at the moment the comp.bat compiles also:
|
|
||||||
k_order_test_main.cpp - exe test driver main function
|
|
||||||
nlsolv.cpp - i.e. not covered by the lib make files.
|
|
||||||
|
|
||||||
to create a debug, POSIX THREAD and Matlab Lapack verion of k_ord_dynarelib.a
|
|
||||||
k_ord_dynarelibML_PTRD_DB.a,
|
|
||||||
|
|
||||||
1) use cygwin shell to compile and create k_ord_lib.a under Windows
|
|
||||||
with MingW and MATLAB LAPACK:
|
|
||||||
|
|
||||||
go to Dynare_pp/extern/matlab assuming MATLAB is already defined with directory
|
|
||||||
and in your cygwin shell set
|
|
||||||
|
|
||||||
>WINDOWS=1
|
|
||||||
>DEBUG=1
|
|
||||||
>export WINDOWS DEBUG
|
|
||||||
|
|
||||||
and run
|
|
||||||
|
|
||||||
> make dynarelib.a
|
|
||||||
|
|
||||||
NOTE: At the momment the library still uses integ files too -
|
|
||||||
those may be removed at a later stage
|
|
||||||
|
|
||||||
|
|
||||||
Then:
|
|
||||||
2) Compile extensions with MingW using the temporary comp.bat:
|
|
||||||
go to the root src directory and run comp.bat
|
|
||||||
|
|
||||||
|
|
||||||
3) to link statically linked test exe driver k_orddbgtest.exe run
|
|
||||||
linkdbgexe.bat
|
|
||||||
|
|
||||||
4) to link Matlab callable DLL
|
|
||||||
linkDLL.bat
|
|
||||||
|
|
||||||
|
|
||||||
NOTE: The dll (mexw32 or so) is called from new Matlab Dynare function dr1_k_order
|
|
||||||
derived from dr1, after set_state_space as:
|
|
||||||
|
|
||||||
[ysteady, ghx_u]=k_ord_dynare_perturbation(dr,task,M_,options_, oo_, ['.' mexext])
|
|
||||||
|
|
||||||
where last term is optional but it will default to .dll on windows and .so on linux.
|
|
||||||
|
|
||||||
dr1_k_order is called by amended resol.m:
|
|
||||||
|
|
||||||
elseif(options_.use_k_order==1)&& (check_flag == 0)
|
|
||||||
[dr,info,M_,options_,oo_] = dr1_k_order(dr,check_flag,M_,options_,oo_);
|
|
||||||
else
|
|
||||||
|
|
||||||
and requirese options to be set
|
|
||||||
|
|
||||||
options_.use_k_order=1;
|
|
||||||
|
|
||||||
==================
|
|
||||||
Tests:
|
|
||||||
|
|
||||||
first_order.m is matlab emulation of Dynare++ c++ first_order.cpp for testing pruposes
|
|
||||||
|
|
||||||
|
|
||||||
==================
|
|
||||||
ToDO:
|
|
||||||
==================
|
|
||||||
1) amend <model>.m to use Dynamic_mexopts.bat
|
|
||||||
|
|
||||||
mex -f Dynamic_mexopts.bat -O fs2000k_no_both_UR_dynamic.c
|
|
||||||
|
|
||||||
or amend preprocessor to make mex to export Dynamic() function as well as mexFunction() as the Dynamic_mexopts.bat does, e.g.:
|
|
||||||
|
|
||||||
set LINKFLAGS=/dll /export:Dynamic /export:%ENTRYPOINT% /MAP ....
|
|
||||||
|
|
||||||
2) make k_order_perturbation handle models which have the "both" variables (i.e. variables that appear both as lag and as lead)
|
|
|
@ -1,25 +0,0 @@
|
||||||
// stdafx.h : include file for standard system include files,
|
|
||||||
// or project specific include files that are used frequently, but
|
|
||||||
// are changed infrequently
|
|
||||||
//
|
|
||||||
|
|
||||||
#if !defined(AFX_STDAFX_H__6D080F4C_4FEB_4290_90B5_6943DFBBE92A__INCLUDED_)
|
|
||||||
#define AFX_STDAFX_H__6D080F4C_4FEB_4290_90B5_6943DFBBE92A__INCLUDED_
|
|
||||||
|
|
||||||
#if _MSC_VER > 1000
|
|
||||||
# pragma once
|
|
||||||
#endif // _MSC_VER > 1000
|
|
||||||
|
|
||||||
// Insert your headers here
|
|
||||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
|
||||||
|
|
||||||
#include <windows.h>
|
|
||||||
#endif // _MSC_VER > 1000
|
|
||||||
|
|
||||||
// TODO: reference additional headers your program requires here
|
|
||||||
|
|
||||||
//{{AFX_INSERT_LOCATION}}
|
|
||||||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
|
|
||||||
|
|
||||||
//#endif // !defined(AFX_STDAFX_H__6D080F4C_4FEB_4290_90B5_6943DFBBE92A__INCLUDED_)
|
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
gcc -DMATLAB_MEX_FILE -mthreads -g -DWINDOWS -DPOSIX_THREADS -DDEBUG -shared -I"c:/Program Files"/MATLAB_SV71/extern/include -I Dyn_pp/src -I Dyn_pp/kord -I Dyn_pp/tl/cc -I Dyn_pp/utils/cc/ -I Dyn_pp/sylv/cc/ -I"f:/Pthreads/Pre-built.2/include" -I"f:/mingw/include" -c k_order_test_main.cpp -c k_ord_dynare.cpp -c k_order_perturbation.cpp -c Dyn_pp/src/nlsolve.cpp
|
|
|
@ -1,359 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2008-2009 Dynare Team
|
|
||||||
*
|
|
||||||
* This file is part of Dynare.
|
|
||||||
*
|
|
||||||
* Dynare is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* Dynare is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*************************************
|
|
||||||
* This main() is for testing k_order DLL entry point by linking to
|
|
||||||
* the k_ord library statically and passing its hard-coded data:
|
|
||||||
* parameters, covar, ysteady and the variable names from fs2000a.mod model
|
|
||||||
* The main has been derived from mxFunction used for K-Order DLL
|
|
||||||
***************************************/
|
|
||||||
|
|
||||||
//#include "stdafx.h"
|
|
||||||
#include "k_ord_dynare.h"
|
|
||||||
|
|
||||||
int
|
|
||||||
main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
|
|
||||||
double qz_criterium = 1+1e-6;
|
|
||||||
const int check_flag = 0;
|
|
||||||
const char *fName = "fs2000k"; //mxArrayToString(mFname);
|
|
||||||
const char *dfExt = NULL; //Dyanamic file extension, e.g.".dll";
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
mexPrintf("k_order_perturbation: check_flag = %d , fName = %s .\n", check_flag, fName);
|
|
||||||
#endif
|
|
||||||
int kOrder = 2;
|
|
||||||
int npar = 7; //(int)mxGetM(mxFldp);
|
|
||||||
double dparams[7] = { 0.3300,
|
|
||||||
0.9900,
|
|
||||||
0.0030,
|
|
||||||
1.0110,
|
|
||||||
0.7000,
|
|
||||||
0.7870,
|
|
||||||
0.0200};
|
|
||||||
Vector *modParams = new Vector(dparams, npar);
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
mexPrintf("k_ord_perturbation: nParams=%d .\n", npar);
|
|
||||||
for (int i = 0; i < npar; i++)
|
|
||||||
{
|
|
||||||
mexPrintf("k_ord_perturbation: dParams[%d]= %g.\n", i, dparams+i*(sizeof(double)));
|
|
||||||
}
|
|
||||||
for (int i = 0; i < npar; i++)
|
|
||||||
{
|
|
||||||
mexPrintf("k_ord_perturbation: Params[%d]= %g.\n", i, (*modParams)[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
double d2Dparams[4] = { //(double *) mxGetData(mxFldp);
|
|
||||||
0.1960e-3, 0.0,
|
|
||||||
0.0, 0.0250e-3
|
|
||||||
};
|
|
||||||
npar = 2; //(int)mxGetN(mxFldp);
|
|
||||||
TwoDMatrix *vCov = new TwoDMatrix(npar, npar, (d2Dparams));
|
|
||||||
double dYSparams [18] = { // 27 mxGetData(mxFldp);
|
|
||||||
// 1.0110, 2.2582, 5.8012, 0.5808,
|
|
||||||
1.0110, 1.0110, 2.2582, 2.2582, 0.4477, 1.0000,
|
|
||||||
4.5959, 1.0212, 5.8012, 0.8494,
|
|
||||||
0.1872, 0.8604, 1.0030, 1.0080,
|
|
||||||
0.5808, 1.0030, 2.2582, 0.4477
|
|
||||||
//, 1.0110, 2.2582, 0.4477, 1.0000, 0.1872, 2.2582, 0.4477
|
|
||||||
};
|
|
||||||
const int nSteady = 18; //27 //31;//29, 16 (int)mxGetM(mxFldp);
|
|
||||||
Vector *ySteady = new Vector(dYSparams, nSteady);
|
|
||||||
|
|
||||||
//mxFldp = mxGetField(dr, 0,"nstatic" );
|
|
||||||
const int nStat = 7; //(int)mxGetScalar(mxFldp);
|
|
||||||
// mxFldp = mxGetField(dr, 0,"npred" );
|
|
||||||
const int nPred = 4; //6 - nBoth (int)mxGetScalar(mxFldp);
|
|
||||||
//mxFldp = mxGetField(dr, 0,"nspred" );
|
|
||||||
const int nsPred = 4; //(int)mxGetScalar(mxFldp);
|
|
||||||
//mxFldp = mxGetField(dr, 0,"nboth" );
|
|
||||||
const int nBoth = 0; // (int)mxGetScalar(mxFldp);
|
|
||||||
//mxFldp = mxGetField(dr, 0,"nfwrd" );
|
|
||||||
const int nForw = 7; // 3 (int)mxGetScalar(mxFldp);
|
|
||||||
//mxFldp = mxGetField(dr, 0,"nsfwrd" );
|
|
||||||
const int nsForw = 7; //(int)mxGetScalar(mxFldp);
|
|
||||||
|
|
||||||
//mxFldp = mxGetField(M_, 0,"exo_nbr" );
|
|
||||||
const int nExog = 2; // (int)mxGetScalar(mxFldp);
|
|
||||||
//mxFldp = mxGetField(M_, 0,"endo_nbr" );
|
|
||||||
const int nEndo = 18; //16(int)mxGetScalar(mxFldp);
|
|
||||||
//mxFldp = mxGetField(M_, 0,"param_nbr" );
|
|
||||||
const int nPar = 7; //(int)mxGetScalar(mxFldp);
|
|
||||||
// it_ should be set to M_.maximum_lag
|
|
||||||
//mxFldp = mxGetField(M_, 0,"maximum_lag" );
|
|
||||||
const int nMax_lag = 1; //(int)mxGetScalar(mxFldp);
|
|
||||||
|
|
||||||
int var_order[] //[18]
|
|
||||||
= {
|
|
||||||
7, 8, 10, 12, 13, 14, 16, 2, 4, 9, 15,
|
|
||||||
1, 3, 5, 6, 11, 17, 18
|
|
||||||
// 5, 6, 8, 10, 11, 12, 16, 7, 13, 14, 15, 1, 2, 3, 4, 9, 17, 18
|
|
||||||
};
|
|
||||||
//Vector * varOrder = new Vector(var_order, nEndo);
|
|
||||||
vector<int> *var_order_vp = new vector<int>(nEndo); //nEndo));
|
|
||||||
for (int v = 0; v < nEndo; v++)
|
|
||||||
(*var_order_vp)[v] = var_order[v];
|
|
||||||
|
|
||||||
const double ll_incidence [] //[3][18]
|
|
||||||
= {
|
|
||||||
0, 5, 23,
|
|
||||||
1, 6, 0,
|
|
||||||
0, 7, 24,
|
|
||||||
2, 8, 0,
|
|
||||||
0, 9, 25,
|
|
||||||
0, 10, 26,
|
|
||||||
0, 11, 0,
|
|
||||||
0, 12, 0,
|
|
||||||
3, 13, 0,
|
|
||||||
0, 14, 0,
|
|
||||||
0, 15, 27,
|
|
||||||
0, 16, 0,
|
|
||||||
0, 17, 0,
|
|
||||||
0, 18, 0,
|
|
||||||
4, 19, 0,
|
|
||||||
0, 20, 0,
|
|
||||||
0, 21, 28,
|
|
||||||
0, 22, 29
|
|
||||||
};
|
|
||||||
TwoDMatrix *llincidence = new TwoDMatrix(3, nEndo, ll_incidence);
|
|
||||||
|
|
||||||
const int jcols = nExog+nEndo+nsPred+nsForw; // Num of Jacobian columns
|
|
||||||
#ifdef DEBUG
|
|
||||||
mexPrintf("k_order_perturbation: jcols= %d .\n", jcols);
|
|
||||||
#endif
|
|
||||||
//mxFldp= mxGetField(M_, 0,"endo_names" );
|
|
||||||
const int nendo = 18; //16(int)mxGetM(mxFldp);
|
|
||||||
const int widthEndo = 6; // (int)mxGetN(mxFldp);
|
|
||||||
const char *cNamesCharStr = "mmPPceWRkdnlggydPc 1 1 yp A22 __ oo bb ss ";
|
|
||||||
// const char** endoNamesMX= DynareMxArrayToString( mxFldp,nendo,widthEndo);
|
|
||||||
const char **endoNamesMX = DynareMxArrayToString(cNamesCharStr, nendo, widthEndo);
|
|
||||||
#ifdef DEBUG
|
|
||||||
for (int i = 0; i < nEndo; i++)
|
|
||||||
{
|
|
||||||
mexPrintf("k_ord_perturbation: EndoNameList[%d][0]= %s.\n", i, endoNamesMX[i]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
//mxFldp = mxGetField(M_, 0,"exo_names" );
|
|
||||||
const int nexo = 2; //(int)mxGetM(mxFldp);
|
|
||||||
const int widthExog = 3; //(int)mxGetN(mxFldp);
|
|
||||||
// const char** exoNamesMX= DynareMxArrayToString( mxFldp,nexo,widthExog);
|
|
||||||
const char *cExoNamesCharStr = "ee__am";
|
|
||||||
const char **exoNamesMX = DynareMxArrayToString(cExoNamesCharStr, nexo, widthExog);
|
|
||||||
#ifdef DEBUG
|
|
||||||
for (int i = 0; i < nexo; i++)
|
|
||||||
{
|
|
||||||
mexPrintf("k_ord_perturbation: ExoNameList[%d][0]= %s.\n", i, exoNamesMX[i]);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
if ((nEndo != nendo) || (nExog != nexo)) //(nPar != npar)
|
|
||||||
{
|
|
||||||
mexErrMsgTxt("Incorrect number of input parameters.\n");
|
|
||||||
//return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
for (int i = 0; i < nEndo; i++)
|
|
||||||
{
|
|
||||||
mexPrintf("k_ord_perturbation: EndoNameList[%d]= %s.\n", i, endoNamesMX[i]);
|
|
||||||
}
|
|
||||||
// for (int i = 0; i < nPar; i++) {
|
|
||||||
//, , mexPrintf("k_ord_perturbation: params_vec[%d]= %g.\n", i, params_vec[i] ); }
|
|
||||||
for (int i = 0; i < nPar; i++)
|
|
||||||
{
|
|
||||||
mexPrintf("k_ord_perturbation: Params[%d]= %g.\n", i, (*modParams)[i]);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < nSteady; i++)
|
|
||||||
{
|
|
||||||
mexPrintf("k_ord_perturbation: ysteady[%d]= %g.\n", i, (*ySteady)[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
mexPrintf("k_order_perturbation: nEndo = %d , nExo = %d .\n", nEndo, nExog);
|
|
||||||
#endif
|
|
||||||
/* Fetch time index */
|
|
||||||
// int it_ = (int) mxGetScalar(prhs[3]) - 1;
|
|
||||||
|
|
||||||
const int nSteps = 0; // Dynare++ solving steps, for time being default to 0 = deterministic steady state
|
|
||||||
const double sstol = 1.e-13; //NL solver tolerance from
|
|
||||||
|
|
||||||
THREAD_GROUP::max_parallel_threads = 1; //2 params.num_threads;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
// make journal name and journal
|
|
||||||
std::string jName(fName); //params.basename);
|
|
||||||
jName += ".jnl";
|
|
||||||
Journal journal(jName.c_str());
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
mexPrintf("k_order_perturbation: Call tls init\n");
|
|
||||||
#endif
|
|
||||||
tls.init(kOrder, nStat+2*nPred+3*nBoth+2*nForw+nExog);
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
mexPrintf("k_order_perturbation: Calling dynamicDLL constructor.\n");
|
|
||||||
#endif
|
|
||||||
// DynamicFn * pDynamicFn = loadModelDynamicDLL (fname);
|
|
||||||
DynamicModelDLL dynamicDLL(fName, nEndo, jcols, nMax_lag, nExog, dfExt);
|
|
||||||
#ifdef DEBUG
|
|
||||||
mexPrintf("k_order_perturbation: Calling dynare constructor.\n");
|
|
||||||
#endif
|
|
||||||
// make KordpDynare object
|
|
||||||
KordpDynare dynare(endoNamesMX, nEndo, exoNamesMX, nExog, nPar, // paramNames,
|
|
||||||
ySteady, vCov, modParams, nStat, nPred, nForw, nBoth,
|
|
||||||
jcols, nSteps, kOrder, journal, dynamicDLL, sstol, var_order_vp, //var_order
|
|
||||||
llincidence, qz_criterium);
|
|
||||||
// intiate tensor library
|
|
||||||
#ifdef DEBUG
|
|
||||||
// mexPrintf("k_order_perturbation: Call tls init\n");
|
|
||||||
#endif
|
|
||||||
/* tls.init(dynare.order(),
|
|
||||||
dynare.nstat()+2*dynare.npred()+3*dynare.nboth()+
|
|
||||||
2*dynare.nforw()+dynare.nexog());
|
|
||||||
*/
|
|
||||||
// construct main K-order approximation class
|
|
||||||
// FistOrderApproximation app(dynare, journal, nSteps);
|
|
||||||
#ifdef DEBUG
|
|
||||||
mexPrintf("k_order_perturbation: Call Approximation constructor \n");
|
|
||||||
#endif
|
|
||||||
Approximation app(dynare, journal, nSteps, false, qz_criterium);
|
|
||||||
// run stochastic steady
|
|
||||||
#ifdef DEBUG
|
|
||||||
mexPrintf("k_order_perturbation: Calling walkStochSteady.\n");
|
|
||||||
#endif
|
|
||||||
app.walkStochSteady();
|
|
||||||
|
|
||||||
// open mat file
|
|
||||||
std::string matfile(fName); //(params.basename);
|
|
||||||
matfile += ".mat";
|
|
||||||
FILE *matfd = NULL;
|
|
||||||
if (NULL == (matfd = fopen(matfile.c_str(), "wb")))
|
|
||||||
{
|
|
||||||
fprintf(stderr, "Couldn't open %s for writing.\n", matfile.c_str());
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string ss_matrix_name(fName); //params.prefix);
|
|
||||||
ss_matrix_name += "_steady_states";
|
|
||||||
ConstTwoDMatrix(app.getSS()).writeMat4(matfd, ss_matrix_name.c_str());
|
|
||||||
|
|
||||||
// write the folded decision rule to the Mat-4 file
|
|
||||||
app.getFoldDecisionRule().writeMat4(matfd, fName); //params.prefix);
|
|
||||||
|
|
||||||
fclose(matfd);
|
|
||||||
|
|
||||||
map<string, ConstTwoDMatrix> mm;
|
|
||||||
app.getFoldDecisionRule().writeMMap(&mm);
|
|
||||||
#ifdef DEBUG
|
|
||||||
app.getFoldDecisionRule().print();
|
|
||||||
mexPrintf("k_order_perturbation: Map print: \n");
|
|
||||||
for (map<string, ConstTwoDMatrix>::const_iterator cit = mm.begin();
|
|
||||||
cit != mm.end(); ++cit)
|
|
||||||
{
|
|
||||||
// const string& sym =(*cit).first;
|
|
||||||
mexPrintf("k_order_perturbation: Map print: string: %s , g:\n", (*cit).first.c_str());
|
|
||||||
// mexPrintf("k_order_perturbation: Map print: g: \n");
|
|
||||||
// if ((*cit).first==string("g_1"))
|
|
||||||
(*cit).second.print();
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// get latest ysteady
|
|
||||||
double *dYsteady = (dynare.getSteady().base());
|
|
||||||
ySteady = (Vector *)(&dynare.getSteady());
|
|
||||||
}
|
|
||||||
catch (const KordException &e)
|
|
||||||
{
|
|
||||||
printf("Caugth Kord exception: ");
|
|
||||||
e.print();
|
|
||||||
return 1; // e.code();
|
|
||||||
}
|
|
||||||
catch (const TLException &e)
|
|
||||||
{
|
|
||||||
printf("Caugth TL exception: ");
|
|
||||||
e.print();
|
|
||||||
return 2; // 255;
|
|
||||||
}
|
|
||||||
catch (SylvException &e)
|
|
||||||
{
|
|
||||||
printf("Caught Sylv exception: ");
|
|
||||||
e.printMessage();
|
|
||||||
return 3; // 255;
|
|
||||||
}
|
|
||||||
catch (const DynareException &e)
|
|
||||||
{
|
|
||||||
printf("Caught KordpDynare exception: %s\n", e.message());
|
|
||||||
return 4; // 255;
|
|
||||||
}
|
|
||||||
catch (const ogu::Exception &e)
|
|
||||||
{
|
|
||||||
printf("Caught ogu::Exception: ");
|
|
||||||
e.print();
|
|
||||||
return 5; // 255;
|
|
||||||
}
|
|
||||||
|
|
||||||
// bones for future developement of the output.
|
|
||||||
|
|
||||||
const int nrhs = 5;
|
|
||||||
const int nlhs = 2;
|
|
||||||
|
|
||||||
mxArray *prhs[nrhs];
|
|
||||||
mxArray *plhs[nlhs];
|
|
||||||
|
|
||||||
#ifdef DEBUG
|
|
||||||
mexPrintf("k_order_perturbation: Filling outputs.\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
double *dgy, *dgu, *ysteady;
|
|
||||||
int nb_row_x;
|
|
||||||
|
|
||||||
ysteady = NULL;
|
|
||||||
if (nlhs >= 1)
|
|
||||||
{
|
|
||||||
/* Set the output pointer to the output matrix ysteady. */
|
|
||||||
plhs[0] = mxCreateDoubleMatrix(nEndo, 1, mxREAL);
|
|
||||||
/* Create a C pointer to a copy of the output ysteady. */
|
|
||||||
ysteady = mxGetPr(plhs[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
dgy = NULL;
|
|
||||||
if (nlhs >= 2)
|
|
||||||
{
|
|
||||||
/* Set the output pointer to the output matrix gy. */
|
|
||||||
plhs[1] = mxCreateDoubleMatrix(nEndo, jcols, mxREAL);
|
|
||||||
// plhs[1] = (double*)(gy->getData())->base();
|
|
||||||
/* Create a C pointer to a copy of the output matrix gy. */
|
|
||||||
dgy = mxGetPr(plhs[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
dgu = NULL;
|
|
||||||
if (nlhs >= 3)
|
|
||||||
{
|
|
||||||
/* Set the output pointer to the output matrix gu. */
|
|
||||||
plhs[2] = mxCreateDoubleMatrix(nEndo, nExog, mxREAL);
|
|
||||||
// plhs[2] = (double*)((gu->getData())->base());
|
|
||||||
/* Create a C pointer to a copy of the output matrix gu. */
|
|
||||||
dgu = mxGetPr(plhs[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
gcc -DMATLAB_MEX_FILE -mthreads -shared -DWINDOWS -DPOSIX_THREADS -I"c:/Program Files"/MATLAB_SV71/extern/include -I Dynare_pp/src -I Dynare_pp/kord -I Dynare_pp/tl/cc -I Dynare_pp/utils/cc/ -I Dynare_pp/sylv/cc/ -I"f:/Pthreads/Pre-built.2/include" -I"f:/mingw/include" -o k_order_perturbation.dll k_ord_dynare.o k_order_perturbation.o dynamic_dll.o nlsolve.o "dynare_pp/extern/matlab"/dynarelib.a -Wl,-L"c:/Program Files"/MATLAB_SV71/extern/lib/win32/microsoft/ -Wl,-llibmex -Wl,-llibmx -Wl,-llibmwlapack -Wl,-llibdflapack -lg2c -lmingw32 -lstdc++ -L"f:/Pthreads/Pre-built.2/lib" -lpthreadGC2
|
|
|
@ -1 +0,0 @@
|
||||||
gcc -DMATLAB_MEX_FILE -mthreads -g -DWINDOWS -DPOSIX_THREADS -I"c:/Program Files"/MATLAB_SV71/extern/include -I Dynare_pp/src -I Dynare_pp/kord -I Dynare_pp/tl/cc -I Dynare_pp/utils/cc/ -I Dynare_pp/sylv/cc/ -I"f:/Pthreads/Pre-built.2/include" -I"f:/mingw/include" -o k_orddbgtest.exe k_order_test_main.o k_ord_dynare.o k_order_perturbation.o nlsolve.o dynamic_dll.o "dynare_pp/extern/matlab"/dynarelib.a -Wl,-L"c:/Program Files"/MATLAB_SV71/extern/lib/win32/microsoft/ -Wl,-llibmex -Wl,-llibmx -Wl,-llibmwlapack -Wl,-llibdflapack -lg2c -lmingw32 -lstdc++ -L"f:/Pthreads/Pre-built.2/lib" -lpthreadGC2
|
|
|
@ -1,31 +0,0 @@
|
||||||
var c k a;
|
|
||||||
varexo e;
|
|
||||||
|
|
||||||
parameters alpha delta beta rho;
|
|
||||||
|
|
||||||
alpha = 0.33;
|
|
||||||
delta = 0.025;
|
|
||||||
beta = 0.99;
|
|
||||||
rho = 0.9;
|
|
||||||
|
|
||||||
model;
|
|
||||||
1/c = beta*(1/c(+1))*(a(+1)*alpha*k^(alpha-1)+1-delta);
|
|
||||||
c+k = a*k(-1)^alpha + (1-delta)*k(-1);
|
|
||||||
log(a) = rho*log(a(-1))+e;
|
|
||||||
end;
|
|
||||||
|
|
||||||
initval;
|
|
||||||
c = 2;
|
|
||||||
k = 28;
|
|
||||||
a = 1;
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
steady;
|
|
||||||
|
|
||||||
shocks;
|
|
||||||
var e; stderr 0.01;
|
|
||||||
end;
|
|
||||||
|
|
||||||
options_.use_k_order=1;
|
|
||||||
stoch_simul(irf=0);
|
|
|
@ -1,121 +0,0 @@
|
||||||
/*
|
|
||||||
* ramst1_dynamic.c : Computes dynamic model for Dynare
|
|
||||||
*
|
|
||||||
* Warning : this file is generated automatically by Dynare
|
|
||||||
* from model file (.mod)
|
|
||||||
|
|
||||||
*/
|
|
||||||
#include <math.h>
|
|
||||||
#include "mex.h"
|
|
||||||
void Dynamic(double *y, double *x, int nb_row_x, double *params, int it_, double *residual, double *g1, double *g2)
|
|
||||||
{
|
|
||||||
double lhs, rhs;
|
|
||||||
|
|
||||||
/* Residual equations */
|
|
||||||
double
|
|
||||||
T19 = pow(y[3],params[0]-1),
|
|
||||||
T23 = 1+y[6]*params[0]*T19-params[1],
|
|
||||||
T29 = pow(y[0],params[0]),
|
|
||||||
T55 = (params[0]-1)*pow(y[3],params[0]-1-1),
|
|
||||||
T56 = y[6]*params[0]*T55,
|
|
||||||
T62 = params[0]*pow(y[0],params[0]-1);
|
|
||||||
lhs =1/y[2];
|
|
||||||
rhs =params[2]*1/y[5]*T23;
|
|
||||||
residual[0]= lhs-rhs;
|
|
||||||
lhs =y[2]+y[3];
|
|
||||||
rhs =y[4]*T29+y[0]*(1-params[1]);
|
|
||||||
residual[1]= lhs-rhs;
|
|
||||||
lhs =log(y[4]);
|
|
||||||
rhs =params[3]*log(y[1])+x[it_+0*nb_row_x];
|
|
||||||
residual[2]= lhs-rhs;
|
|
||||||
/* Jacobian */
|
|
||||||
if (g1 == NULL)
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g1[6]= g1[6]+(-1)/(y[2]*y[2]);
|
|
||||||
g1[15]= g1[15]+(-(T23*params[2]*(-1)/(y[5]*y[5])));
|
|
||||||
g1[18]= g1[18]+(-(params[2]*1/y[5]*params[0]*T19));
|
|
||||||
g1[9]= g1[9]+(-(params[2]*1/y[5]*T56));
|
|
||||||
g1[7]= g1[7]+1;
|
|
||||||
g1[10]= g1[10]+1;
|
|
||||||
g1[13]= g1[13]+(-T29);
|
|
||||||
g1[1]= g1[1]+(-(1-params[1]+y[4]*T62));
|
|
||||||
g1[14]= g1[14]+1/y[4];
|
|
||||||
g1[5]= g1[5]+(-(params[3]*1/y[1]));
|
|
||||||
g1[23]= g1[23]+(-1);
|
|
||||||
}
|
|
||||||
/* Hessian for endogenous and exogenous variables */
|
|
||||||
if (g2 == NULL)
|
|
||||||
return;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g2[54] = (y[2]+y[2])/(y[2]*y[2]*y[2]*y[2]);
|
|
||||||
g2[135] = (-(T23*params[2]*(y[5]+y[5])/(y[5]*y[5]*y[5]*y[5])));
|
|
||||||
g2[159] = (-(params[2]*(-1)/(y[5]*y[5])*params[0]*T19));
|
|
||||||
g2[87] = (-(params[2]*(-1)/(y[5]*y[5])*T56));
|
|
||||||
g2[90] = (-(params[2]*1/y[5]*params[0]*T55));
|
|
||||||
g2[81] = (-(params[2]*1/y[5]*y[6]*params[0]*(params[0]-1)*(params[0]-1-1)*pow(y[3],params[0]-1-1-1)));
|
|
||||||
g2[13] = (-T62);
|
|
||||||
g2[1] = (-(y[4]*params[0]*(params[0]-1)*pow(y[0],params[0]-1-1)));
|
|
||||||
g2[110] = (-1)/(y[4]*y[4]);
|
|
||||||
g2[29] = (-(params[3]*(-1)/(y[1]*y[1])));
|
|
||||||
g2[138] = g2[159];
|
|
||||||
g2[129] = g2[87];
|
|
||||||
g2[153] = g2[90];
|
|
||||||
g2[97] = g2[13];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* The gateway routine */
|
|
||||||
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
|
|
||||||
{
|
|
||||||
double *y, *x, *params;
|
|
||||||
double *residual, *g1, *g2;
|
|
||||||
int nb_row_x, it_;
|
|
||||||
|
|
||||||
/* Create a pointer to the input matrix y. */
|
|
||||||
y = mxGetPr(prhs[0]);
|
|
||||||
|
|
||||||
/* Create a pointer to the input matrix x. */
|
|
||||||
x = mxGetPr(prhs[1]);
|
|
||||||
|
|
||||||
/* Create a pointer to the input matrix params. */
|
|
||||||
params = mxGetPr(prhs[2]);
|
|
||||||
|
|
||||||
/* Fetch time index */
|
|
||||||
it_ = (int) mxGetScalar(prhs[3]) - 1;
|
|
||||||
|
|
||||||
/* Gets number of rows of matrix x. */
|
|
||||||
nb_row_x = mxGetM(prhs[1]);
|
|
||||||
|
|
||||||
residual = NULL;
|
|
||||||
if (nlhs >= 1)
|
|
||||||
{
|
|
||||||
/* Set the output pointer to the output matrix residual. */
|
|
||||||
plhs[0] = mxCreateDoubleMatrix(3,1, mxREAL);
|
|
||||||
/* Create a C pointer to a copy of the output matrix residual. */
|
|
||||||
residual = mxGetPr(plhs[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
g1 = NULL;
|
|
||||||
if (nlhs >= 2)
|
|
||||||
{
|
|
||||||
/* Set the output pointer to the output matrix g1. */
|
|
||||||
plhs[1] = mxCreateDoubleMatrix(3, 8, mxREAL);
|
|
||||||
/* Create a C pointer to a copy of the output matrix g1. */
|
|
||||||
g1 = mxGetPr(plhs[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
g2 = NULL;
|
|
||||||
if (nlhs >= 3)
|
|
||||||
{
|
|
||||||
/* Set the output pointer to the output matrix g2. */
|
|
||||||
plhs[2] = mxCreateDoubleMatrix(3, 64, mxREAL);
|
|
||||||
/* Create a C pointer to a copy of the output matrix g1. */
|
|
||||||
g2 = mxGetPr(plhs[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Call the C subroutines. */
|
|
||||||
Dynamic(y, x, nb_row_x, params, it_, residual, g1, g2);
|
|
||||||
}
|
|
|
@ -1,4 +1,5 @@
|
||||||
function [gy]=first_order(M_, dr, jacobia)
|
function [gy]=first_order(M_, dr, jacobia)
|
||||||
|
% Emulation of Dynare++ c++ first_order.cpp for testing pruposes
|
||||||
|
|
||||||
% Copyright (C) 2009 Dynare Team
|
% Copyright (C) 2009 Dynare Team
|
||||||
%
|
%
|
|
@ -257,7 +257,7 @@ main(int argc, char *argv[])
|
||||||
fclose(matfd);
|
fclose(matfd);
|
||||||
|
|
||||||
map<string, ConstTwoDMatrix> mm;
|
map<string, ConstTwoDMatrix> mm;
|
||||||
app.getFoldDecisionRule().writeMMap(&mm);
|
app.getFoldDecisionRule().writeMMap(mm, string());
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
app.getFoldDecisionRule().print();
|
app.getFoldDecisionRule().print();
|
||||||
mexPrintf("k_order_perturbation: Map print: \n");
|
mexPrintf("k_order_perturbation: Map print: \n");
|
Loading…
Reference in New Issue