Skip to content
Snippets Groups Projects
Commit 86dfc202 authored by Max's avatar Max
Browse files

Code, basierend auf Testscript aus Masterarbeit

parents
Branches
Tags
No related merge requests found
Pipeline #
% Vergleich von parallel berechneter Simulation mit sequentiell erechneter
% Simulation
% fr Matlab R2012b
matlabpool close force
% Eingangsdaten
N=20;
input = linspace(0,1,N);
% Singlecore
t_single = tic;
y_single=zeros(N,1);
for i=1:N
y_single(i) = myfunction(input(i));
end
t_single = toc(t_single);
% Parallel
% Folgende Funktion macht die Initialisierung und einige Workarounds.
% wenn alles korrekt konfiguriert ist, geht stattdessen auch: matlabpool(4)
init_matlabpool_workaround
t_par = tic;
y_par = zeros(N,1);
parfor i=1:N
y_par(i) = myfunction(input(i));
end
t_par = toc(t_par);
assert(all(y_par == y_single))
disp('Test erfolgreich, parallel liefert gleiches Ergebnis.')
fprintf('Zeiten Singlecore: %f s, Parallel: %f s\n', t_single, t_par);
fprintf('Beschleunigung um Faktor %f\n', t_single/t_par);
\ No newline at end of file
% Initialisiere matlabpool, mit Workarounds fr 2012b
tic;
setenv('LM_LICENSE_FILE','')
dctconfig('hostname', '127.0.0.1')
distcomp.feature( 'LocalUseMpiexec', false)
setenv('MPICH_INTERFACE_HOSTNAME', '127.0.0.1')
matlabpool close force
matlabpool size
disp('starte Pool, dies kann bei Firewallproblemen bis zu 25min dauern');
disp('wenn es garnicht funktioniert, muss man matlab per Kommandozeile starten und dabei die Lizenzdatei angeben: matlab -c "C:\...\Matlab\licenses\...Lizenzdatei.lic"')
matlabpool(4)
disp('teste Pool')
test_matlabpool_a=zeros(1,4);
parfor i=1:4
test_matlabpool_a(i) = mean(sin(1:100000)) + 1;
end
for tmp=test_matlabpool_a
assert(abs(tmp - 1) < 1e-4)
end
spmd
test_matlabpool_b = labindex;
end
for i=1:4
assert(test_matlabpool_b{i}==i)
end
clear test_matlabpool_a
clear test_matlabpool_b
disp('okay')
toc;
\ No newline at end of file
function [ y ] = myfunction( x )
% Zeit verschwenden und dabei irgendwas ausrechnen
for i=1:10000000
x=sin(1337*x);
end
y=x;
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment