Changes related to the multithreaded mex files (part III). Moved

set_dynare_threads  in ./matlab/thread/multi (the  user has  no access
to this function if mex files are compiled without the openmp flag).


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2551 ac1d8469-bf42-47a9-8791-bf33cf982152
time-shift
stepan 2009-04-03 11:12:21 +00:00
parent 8ab8d2f067
commit 91a25ebead
1 changed files with 0 additions and 73 deletions

View File

@ -1,73 +0,0 @@
function not = set_dynare_threads(n)
% This function sets the number of threads used by dynare's mex files.
%
% INPUTS
% o n [integer] scalar specifying the number of threads to be used.
%
% OUTPUTS
% o not [integer] scalar, number of threads.
%
% REMARKS The default value of n is the number of processors on the platform.
% Copyright (C) 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/>.
not = 1;
if ~isopenmp()% This version of Dynare does not use multithreaded mex files!
disp(' ')
disp('Multithreading is not available on your platform!')
disp(' ')
return
end
MaxNumberOfThreads = maxNumCompThreads();
if ~nargin% Default.
not = MaxNumberOfThreads;
setenv('DYNARE_NUM_THREADS',int2str(MaxNumberOfThreads));
else
if (n>MaxNumberOfThreads)
disp(['You want to use ' int2str(n) ' threads but your platform has only ' int2str(MaxNumberOfThreads) ' processors!'])
reply = input(['Do you really want to use ' int2str(n) ' threads ? Yes/[No]: '],'s');
if isempty(reply)
reply = 'No';
end
if strcmpi(reply,'No')
nn = input(['Choose a number of threads between 1 and [' int2str(MaxNumberOfThreads) ']: ']);
if isempty(nn)
nn = MaxNumberOfThreads;
end
if (nn>MaxNumberOfThreads)
disp(['To my knowledge ' int2str(nn) ' is greater than ' int2str(MaxNumberOfThreads) '!...'])
disp(' ')
not = set_dynare_threads(n);
return
end
not = nn;
setenv('DYNARE_NUM_THREADS',int2str(nn));
elseif strcmpi(reply,'Yes')
not = n;
setenv('DYNARE_NUM_THREADS',int2str(n));
else
disp(['You have to answer by Yes or No...'])
disp(' ')
not = set_dynare_threads(n);
return
end
else
not = n;
setenv('DYNARE_NUM_THREADS',int2str(n));
end
end