dynare_config.m 6.93 KB
Newer Older
1
function dynareroot = dynare_config(path_to_dynare)
2
%function dynareroot = dynare_config(path_to_dynare)
3
4
5
6
% This function tests the existence of valid mex files (for qz
% decomposition, solution to sylvester equation and kronecker
% products...) and, if needed, add paths to the matlab versions
% of these routines.
sebastien's avatar
sebastien committed
7
% Also adds other directories to the path.
8
9
10
11
12
13
14
15
16
%
% INPUTS
%   none
%             
% OUTPUTS
%   none
%        
% SPECIAL REQUIREMENTS
%   none
17

sebastien's avatar
trunk:    
sebastien committed
18
% Copyright (C) 2001-2009 Dynare Team
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
%
% 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/>.

35
36
37
if nargin
    addpath(path_to_dynare);
end
sebastien's avatar
sebastien committed
38
dynareroot = strrep(which('dynare'),'dynare.m','');
39

adjemian's avatar
v4.1:    
adjemian committed
40
addpath([dynareroot '/distributions/'])
41
addpath([dynareroot '/kalman/'])
42
addpath([dynareroot '/kalman/likelihood'])
sebastien's avatar
trunk:    
sebastien committed
43
addpath([dynareroot '/AIM/'])
44

45
46
47
48
49
50
% For functions that exist only under some Octave versions
% or some MATLAB versions, and for which we provide some replacement functions

if ~exist('OCTAVE_VERSION')
    % Replacements for rows() and columns() (inexistent under MATLAB)
    addpath([dynareroot '/missing/rows_columns'])
51
52
    % Replacement for vec() (inexistent under MATLAB)
    addpath([dynareroot '/missing/vec'])
sebastien's avatar
trunk:    
sebastien committed
53
54
    if isempty(ver('stats'))
        % Replacements for functions of the stats toolbox
55
        addpath([dynareroot '/missing/stats/'])
sebastien's avatar
trunk:    
sebastien committed
56
    end
57
58
end

59
60
61
62
63
% ordeig() was introducted in MATLAB 7.0.1, and doesn't exist in Octave
if exist('OCTAVE_VERSION') || matlab_ver_less_than('7.0.1')
    addpath([dynareroot '/missing/ordeig'])
end

64
% rcond() and bicgstable() were introduced in Octave 3.2.0
65
66
if exist('OCTAVE_VERSION') && octave_ver_less_than('3.2.0')
    addpath([dynareroot '/missing/rcond'])
67
    addpath([dynareroot '/missing/bicgstab'])
68
69
70
71
72
73
74
75
end

% orschur() is missing in Octave; we don't have a real replacement;
% the one we provide just exits with an error message
if exist('OCTAVE_VERSION')
    addpath([dynareroot '/missing/ordschur'])
end

sebastien's avatar
trunk:    
sebastien committed
76
% Add path to MEX files
77
if exist('OCTAVE_VERSION')
78
    addpath([dynareroot '../mex/octave/']);
79
else
80
81
82
    % Add win32 specific paths for Dynare Windows package
    if strcmp(computer, 'PCWIN')
        if matlab_ver_less_than('7.5')
83
            mexpath = [dynareroot '../mex/matlab/win32-6.5-7.4'];
84
85
86
87
88
89
90
91
92
            if exist(mexpath, 'dir')
                addpath(mexpath)
            end
        else
            mexpath = [dynareroot '../mex/matlab/win32-7.5-7.9'];
            if exist(mexpath, 'dir')
                addpath(mexpath)
            end
        end
93
    end
94
95
96

    % Add win64 specific paths for Dynare Windows package
    if strcmp(computer, 'PCWIN64')
97
98
99
100
101
102
103
        if matlab_ver_less_than('7.3')
            mexpath = [dynareroot '../mex/matlab/win64-7.2'];
            if exist(mexpath, 'dir')
                addpath(mexpath)
            end
        elseif matlab_ver_less_than('7.5')
            mexpath = [dynareroot '../mex/matlab/win64-7.3-7.4'];
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
            if exist(mexpath, 'dir')
                addpath(mexpath)
            end
        elseif matlab_ver_less_than('7.8')
            mexpath = [dynareroot '../mex/matlab/win64-7.5-7.7'];
            if exist(mexpath, 'dir')
                addpath(mexpath)
            end
        else
            mexpath = [dynareroot '../mex/matlab/win64-7.8-7.9'];
            if exist(mexpath, 'dir')
                addpath(mexpath)
            end
        end
    end

    % Add generic MATLAB path (with higher priority than the previous ones)
    addpath([dynareroot '../mex/matlab/']);
122
end
123

124
125
126
127
%% Set mex routine names
mex_status = cell(1,3);
mex_status(1,1) = {'mjdgges'};
mex_status(1,2) = {'qz'};
adjemian's avatar
adjemian committed
128
mex_status(1,3) = {'Generalized QZ'};
129
130
131
132
133
134
135
136
137
138
139
140
141
142
mex_status(2,1) = {'gensylv'};
mex_status(2,2) = {'gensylv'};
mex_status(2,3) = {'Sylvester equation solution'};
mex_status(3,1) = {'A_times_B_kronecker_C'};
mex_status(3,2) = {'kronecker'};
mex_status(3,3) = {'Kronecker products'};
mex_status(4,1) = {'sparse_hessian_times_B_kronecker_C'};
mex_status(4,2) = {'kronecker'};
mex_status(4,3) = {'Sparse kronecker products'};
number_of_mex_files = size(mex_status,1);
%% Remove some directories from matlab's path. This is necessary if the user has
%% added dynare_v4/matlab with the subfolders. Matlab has to ignore these
%% subfolders if valid mex files exist.
matlab_path = path;
143
144
145
146
147
148
149
150
151
152
test = strfind(matlab_path,[dynareroot 'threads/single']);
if length(test)
    rmpath([dynareroot 'threads/single']);
    matlab_path = path;
end
test = strfind(matlab_path,[dynareroot 'threads/multi']);
if length(test)
    rmpath([dynareroot 'threads/multi']);
    matlab_path = path;
end
153
for i=1:number_of_mex_files
adjemian's avatar
adjemian committed
154
    test = strfind(matlab_path,[dynareroot mex_status{i,2}]);
155
    action = length(test);
adjemian's avatar
adjemian committed
156
    if action
157
158
159
160
        rmpath([dynareroot mex_status{i,2}]);
        matlab_path = path;
    end
end
161
162
163
164
165
166
167
168
169
%% Test if multithread mex files are available.
if exist('isopenmp')==3
    addpath([dynareroot '/threads/multi/'])
    number_of_threads = set_dynare_threads();
    multithread_flag  = number_of_threads-1;
else
    addpath([dynareroot '/threads/single/'])
    multithread_flag = 0;
end
170
171
172
173
%% Test if valid mex files are available, if a mex file is not available
%% a matlab version of the routine is included in the path.
disp(' ')
disp('Configuring Dynare ...')
sebastien's avatar
sebastien committed
174

175
for i=1:number_of_mex_files
176
    test = (exist(mex_status{i,1},'file') == 3);
177
178
179
180
    if ~test
        addpath([dynareroot mex_status{i,2}]);
        message = '[m]   ';
    else
181
182
        if multithread_flag && ( strcmpi(mex_status(i,1),'sparse_hessian_times_B_kronecker_C') || ...
                                 strcmpi(mex_status(i,1),'A_times_B_kronecker_C') )
183
184
185
186
            message = [ '[mex][multithread version, ' int2str(multithread_flag+1) ' threads are used] ' ]; 
        else
            message = '[mex] ';
        end
187
188
189
    end
    disp([ message mex_status{i,3} '.' ])
end
190

191
% Test if bytecode DLL is present
192
if exist('bytecode', 'file') == 3
193
194
195
196
197
    if ~multithread_flag
        message = '[mex] ';
    else
        message = [ '[mex][multithread version, ' int2str(multithread_flag+1) ' threads are used] ' ];
    end
198
else
199
    message = '[no]  ';
200
end
201
disp([ message 'Bytecode evaluation.' ])
202

sebastien's avatar
sebastien committed
203
% Test if k-order perturbation DLL is present
204
if exist('k_order_perturbation', 'file') == 3
205
    message = '[mex] ';
sebastien's avatar
sebastien committed
206
else
207
    message = '[no]  ';
sebastien's avatar
sebastien committed
208
end
209
disp([ message 'k-order perturbation solver.' ])
sebastien's avatar
sebastien committed
210

211
% Test if dynare_simul_ DLL is present
212
if exist('dynare_simul_', 'file') == 3
213
    message = '[mex] ';
214
else
215
    message = '[no]  ';
216
217
218
219
end
disp([ message 'k-order solution simulation.' ])

disp(' ')