Add MEXEXT define to build system, adapt relevant DLL and Windows packaging

Closes: #235
time-shift
Sébastien Villemot 2012-01-09 12:37:55 +01:00
parent 4a4c88de20
commit a66594caed
10 changed files with 49 additions and 57 deletions

View File

@ -111,8 +111,13 @@ if exist('OCTAVE_VERSION')
else
% Add win32 specific paths for Dynare Windows package
if strcmp(computer, 'PCWIN')
if matlab_ver_less_than('7.5')
mexpath = [dynareroot '../mex/matlab/win32-7.0-7.4'];
if matlab_ver_less_than('7.1')
mexpath = [dynareroot '../mex/matlab/win32-7.0-7.0.4'];
if exist(mexpath, 'dir')
addpath(mexpath)
end
elseif matlab_ver_less_than('7.5')
mexpath = [dynareroot '../mex/matlab/win32-7.1-7.4'];
if exist(mexpath, 'dir')
addpath(mexpath)
end

View File

@ -1,7 +1,7 @@
function [dr,info] = k_order_pert(dr,M,options,oo)
% Compute decision rules using the k-order DLL from Dynare++
% Copyright (C) 2009-2010 Dynare Team
% Copyright (C) 2009-2012 Dynare Team
%
% This file is part of Dynare.
%
@ -26,20 +26,17 @@ order = options.order;
switch(order)
case 1
[err, g_1] = k_order_perturbation(dr,M,options, ['.' ...
mexext]);
[err, g_1] = k_order_perturbation(dr,M,options);
mexErrCheck('k_order_perturbation', err);
dr.g_1 = g_1;
case 2
[err, g_0, g_1, g_2] = k_order_perturbation(dr,M,options, ['.' ...
mexext]);
[err, g_0, g_1, g_2] = k_order_perturbation(dr,M,options);
mexErrCheck('k_order_perturbation', err);
dr.g_0 = g_0;
dr.g_1 = g_1;
dr.g_2 = g_2;
case 3
[err, g_0, g_1, g_2, g_3] = k_order_perturbation(dr,M,options, ['.' ...
mexext]);
[err, g_0, g_1, g_2, g_3] = k_order_perturbation(dr,M,options);
mexErrCheck('k_order_perturbation', err);
dr.g_0 = g_0;
dr.g_1 = g_1;

View File

@ -5,6 +5,7 @@ CPPFLAGS += -I$(top_srcdir)/../../sources
DEFS += $(MATLAB_DEFS)
DEFS += -DMATLAB_MEX_FILE
DEFS += -DMEXEXT=\"$(MEXEXT)\"
LDFLAGS += $(MATLAB_LDFLAGS)
LIBS += $(MATLAB_LIBS)

View File

@ -3,6 +3,7 @@ CPPFLAGS += $(shell $(MKOCTFILE) -p INCFLAGS)
CPPFLAGS += -I$(top_srcdir)/../../sources
DEFS += -DOCTAVE_MEX_FILE
DEFS += -DMEXEXT=\".mex\"
CFLAGS += $(shell $(MKOCTFILE) -p CPICFLAG)
FFLAGS += $(shell $(MKOCTFILE) -p FPICFLAG)

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2011 Dynare Team
* Copyright (C) 2010-2012 Dynare Team
*
* This file is part of Dynare.
*
@ -624,7 +624,7 @@ sampleMHMC(LogPosteriorDensity &lpd, RandomWalkMetropolisHastings &rwmh,
}
int
logMCMCposterior(const VectorConstView &estParams, const MatrixConstView &data, const std::string &mexext,
logMCMCposterior(const VectorConstView &estParams, const MatrixConstView &data,
const size_t fblock, const size_t nBlocks, const VectorConstView &nMHruns, const MatrixConstView &D)
{
// Retrieve pointers to global variables
@ -638,7 +638,8 @@ logMCMCposterior(const VectorConstView &estParams, const MatrixConstView &data,
std::string resultsFileStem(fName);
std::string dynamicDllFile(fName);
mxFree(fName);
dynamicDllFile += "_dynamic." + mexext;
dynamicDllFile += "_dynamic";
dynamicDllFile += MEXEXT;
size_t n_endo = (size_t) *mxGetPr(mxGetField(M_, 0, "endo_nbr"));
size_t n_exo = (size_t) *mxGetPr(mxGetField(M_, 0, "exo_nbr"));
@ -745,8 +746,8 @@ void
mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
if (nrhs != 7)
DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly seven arguments are required.");
if (nrhs != 6)
DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly six arguments are required.");
if (nlhs != 2)
DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly two return arguments are required.");
@ -762,23 +763,16 @@ mexFunction(int nlhs, mxArray *plhs[],
MatrixConstView data(mxGetPr(prhs[1]), mxGetM(prhs[1]), mxGetN(prhs[1]), mxGetM(prhs[1]));
if (!mxIsChar(prhs[2]))
DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: Third argument must be a character string");
char *mexext_mx = mxArrayToString(prhs[2]);
std::string mexext(mexext_mx);
mxFree(mexext_mx);
size_t fblock = (size_t) mxGetScalar(prhs[3]);
size_t nBlocks = (size_t) mxGetScalar(prhs[4]);
VectorConstView nMHruns(mxGetPr(prhs[5]), mxGetM(prhs[5]), 1);
size_t fblock = (size_t) mxGetScalar(prhs[2]);
size_t nBlocks = (size_t) mxGetScalar(prhs[3]);
VectorConstView nMHruns(mxGetPr(prhs[4]), mxGetM(prhs[4]), 1);
assert(nMHruns.getSize() == nBlocks);
MatrixConstView D(mxGetPr(prhs[6]), mxGetM(prhs[6]), mxGetN(prhs[6]), mxGetM(prhs[6]));
MatrixConstView D(mxGetPr(prhs[5]), mxGetM(prhs[5]), mxGetN(prhs[5]), mxGetM(prhs[5]));
//calculate MHMCMC draws and get get last line run in the last MH block sub-array
try
{
int lastMHblockArrayLine = logMCMCposterior(estParams, data, mexext, fblock, nBlocks, nMHruns, D);
int lastMHblockArrayLine = logMCMCposterior(estParams, data, fblock, nBlocks, nMHruns, D);
plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
*mxGetPr(plhs[1]) = (double) lastMHblockArrayLine;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2010-2011 Dynare Team
* Copyright (C) 2010-2012 Dynare Team
*
* This file is part of Dynare.
*
@ -101,8 +101,7 @@ fillEstParamsInfo(const mxArray *estim_params_info, EstimatedParameter::pType ty
}
double
logposterior(const VectorConstView &estParams, const MatrixConstView &data,
const std::string &mexext)
logposterior(const VectorConstView &estParams, const MatrixConstView &data)
{
// Retrieve pointers to global variables
const mxArray *M_ = mexGetVariablePtr("global", "M_");
@ -114,7 +113,8 @@ logposterior(const VectorConstView &estParams, const MatrixConstView &data,
char *fName = mxArrayToString(mxGetField(M_, 0, "fname"));
std::string dynamicDllFile(fName);
mxFree(fName);
dynamicDllFile += "_dynamic." + mexext;
dynamicDllFile += "_dynamic";
dynamicDllFile += MEXEXT;
size_t n_endo = (size_t) *mxGetPr(mxGetField(M_, 0, "endo_nbr"));
size_t n_exo = (size_t) *mxGetPr(mxGetField(M_, 0, "exo_nbr"));
@ -211,8 +211,8 @@ void
mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
if (nrhs != 3 || nlhs != 2)
DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly three input arguments and two output arguments are required.");
if (nrhs != 2 || nlhs != 2)
DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: exactly two input arguments and two output arguments are required.");
// Check and retrieve the arguments
@ -225,19 +225,11 @@ mexFunction(int nlhs, mxArray *plhs[],
DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: Second argument must be a matrix of double-precision numbers");
MatrixConstView data(mxGetPr(prhs[1]), mxGetM(prhs[1]), mxGetN(prhs[1]), mxGetM(prhs[1]));
if (!mxIsChar(prhs[2]))
DYN_MEX_FUNC_ERR_MSG_TXT("logposterior: Third argument must be a character string");
char *mexext_mx = mxArrayToString(prhs[2]);
std::string
mexext(mexext_mx);
mxFree(mexext_mx);
// Compute and return the value
try
{
double lik = logposterior(estParams, data, mexext);
double lik = logposterior(estParams, data);
plhs[1] = mxCreateDoubleMatrix(1, 1, mxREAL);
*mxGetPr(plhs[1]) = lik;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2010 Dynare Team
* Copyright (C) 2008-2012 Dynare Team
*
* This file is part of Dynare.
*
@ -21,13 +21,13 @@
#include <sstream>
DynamicModelDLL::DynamicModelDLL(const string &modName, const string &sExt) throw (DynareException)
DynamicModelDLL::DynamicModelDLL(const string &modName) throw (DynareException)
{
string fName;
#if !defined(__CYGWIN32__) && !defined(_WIN32)
fName = "./";
#endif
fName += modName + "_dynamic" + sExt;
fName += modName + "_dynamic" + MEXEXT;
try
{

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2011 Dynare Team
* Copyright (C) 2008-2012 Dynare Team
*
* This file is part of Dynare.
*
@ -55,7 +55,7 @@ private:
public:
// construct and load Dynamic model DLL
DynamicModelDLL(const string &fname, const string &sExt) throw (DynareException);
DynamicModelDLL(const string &fname) throw (DynareException);
virtual ~DynamicModelDLL();
void eval(const Vector &y, const Vector &x, const Vector &params, const Vector &ySteady,

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2008-2011 Dynare Team
* Copyright (C) 2008-2012 Dynare Team
*
* This file is part of Dynare.
*
@ -24,7 +24,6 @@
1) dr
2) M_
3) options
4) string containing the MEX extension (with a dot at the beginning)
Outputs:
- if order == 1: only g_1
@ -69,8 +68,8 @@ extern "C" {
mexFunction(int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
if (nrhs != 4 || nlhs < 2)
DYN_MEX_FUNC_ERR_MSG_TXT("Must have exactly 4 input parameters and take at least 2 output parameters.");
if (nrhs != 3 || nlhs < 2)
DYN_MEX_FUNC_ERR_MSG_TXT("Must have exactly 3 input parameters and take at least 2 output parameters.");
const mxArray *dr = prhs[0];
const mxArray *M_ = prhs[1];
@ -82,8 +81,6 @@ extern "C" {
DYN_MEX_FUNC_ERR_MSG_TXT("Input must be of type char.");
string fName = mxArrayToString(mFname);
const mxArray *mexExt = prhs[3];
string dfExt = mxArrayToString(mexExt); // Dynamic file extension, e.g. ".dll" or ".mexw32"
int kOrder;
mxArray *mxFldp = mxGetField(options_, 0, "order");
@ -208,7 +205,7 @@ extern "C" {
DynamicModelAC *dynamicModelFile;
if (use_dll == 1)
dynamicModelFile = new DynamicModelDLL(fName, dfExt);
dynamicModelFile = new DynamicModelDLL(fName);
else
dynamicModelFile = new DynamicModelMFile(fName);

View File

@ -75,9 +75,14 @@ SectionEnd
SectionGroup "MEX files for MATLAB"
Section "MEX files for MATLAB 32-bit, version 7.0 to 7.4 (R14 to R2007a)"
SetOutPath $INSTDIR\mex\matlab\win32-7.0-7.4
File ..\mex\matlab\win32-7.0-7.4\*.dll
Section "MEX files for MATLAB 32-bit, version 7.0 to 7.0.4 (R14 to R14SP2)"
SetOutPath $INSTDIR\mex\matlab\win32-7.0-7.0.4
File ..\mex\matlab\win32-7.0-7.0.4\*.dll
SectionEnd
Section "MEX files for MATLAB 32-bit, version 7.1 to 7.4 (R14SP3 to R2007a)"
SetOutPath $INSTDIR\mex\matlab\win32-7.1-7.4
File ..\mex\matlab\win32-7.1-7.4\*.mexw32
SectionEnd
Section "MEX files for MATLAB 32-bit, version 7.5 to 7.13 (R2007b to R2011b)"