2 % Copyright (C) 2009-2015 Peter Rakyta, Ph.D.
4 % This program is free software: you can redistribute it and/or modify
5 % it under the terms of the GNU General Public License as published by
6 % the Free Software Foundation, either version 3 of the License, or
7 % (at your option) any later version.
9 % This program is distributed in the hope that it will be useful,
10 % but WITHOUT ANY WARRANTY; without even the implied warranty of
11 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 % GNU General Public License
for more details.
14 % You should have received a copy of the GNU General Public License
15 % along with
this program. If not, see http:
17 %> @addtogroup basic Basic Functionalities
20 %> @brief A
class for controlling the parallel pool
for paralell computations. (compatble only wih MATLAB)
22 %> @brief A
class for controlling the parallel pool for paralell computations. (compatble only wih MATLAB)
24 %> EQuUs v4.6 or later
29 properties ( Access =
protected )
30 %>The parallel.Pool object, see the documentation
for more details.
32 %>Number of attempts to open the parallel pool.
34 %>Maximal number of attemts to open the parallel pool.
36 %>A period to wait between the attempts to open the parallel pool.
40 properties ( Access =
public )
46 %% Contructor of the
class 47 %> @brief Constructor of the
class.
49 %> @
return An instance of the
class 54 obj.try2open_max = 20;
59 %> @brief Opens a parallel pool
for parallel computations.
60 function openPool( obj )
63 % Parallell computation of EQuUs is not yet supported in octave
68 obj.try2open = obj.try2open + 1;
70 %
try to open the parallel pool
74 poolobj = gcp('nocreate');
76 if ~isempty(obj.
Opt.workers) && obj.
Opt.workers>0
77 obj.poolobj = parpool(obj.
Opt.workers);
78 obj.NumWorkers = obj.poolobj.NumWorkers;
79 elseif (~isempty(obj.
Opt.workers) && obj.
Opt.workers<=0) || isempty(obj.
Opt.workers)
83 obj.poolobj = parpool();
84 obj.NumWorkers = obj.poolobj.NumWorkers;
87 % if parallel pool is already opened, nothing is done here
89 obj.NumWorkers = poolobj.NumWorkers;
92 if 0 == matlabpool('size')
93 if ~isempty(obj.
Opt.workers) && obj.
Opt.workers>0
94 matlabpool(obj.
Opt.workers);
95 obj.poolobj = struct('NumWorkers', obj.
Opt.workers);
96 elseif (~isempty(obj.
Opt.workers) && obj.
Opt.workers<=0) || isempty(obj.
Opt.workers)
100 obj.poolobj = struct('NumWorkers', matlabpool('size'));
103 % if parallel pool is already opened, nothing is done here
106 obj.NumWorkers = matlabpool('size');
109 % try to open the parallel pool again
111 if obj.try2open >= obj.try2open_max
112 err = MException('
Parallel:openPool', 'Error occured when opening the parallel pool.');
113 err = addCause(err, errCause);
114 save('Error_Parallel_openPool.mat');
117 obj.display( ['Failed to open the parallel pool. Try to open again in ', num2str(obj.waitsec), ' seconds.'], 1)
118 pause( obj.waitsec );
128 %> @brief Closes a parallel pool.
130 if ~isempty(obj.poolobj)
A class containing methodes for displaying several standard messages.
A class for controlling the parallel pool for paralell computations.
Structure Opt contains the basic computational parameters used in EQuUs.
function Transport(Energy, B)
Calculates the conductance at a given energy value.
A class containing common basic functionalities.
Structure param contains data structures describing the physical parameters of the scattering center ...