This repository has been archived by the owner on Feb 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMAPRED.m
65 lines (48 loc) · 1.67 KB
/
MAPRED.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function MAPRED()
%%% project: hapod - Hierarchical Approximate POD ( https://git.io/hapod )
%%% version: 3.2 (2021-05-05)
%%% authors: C. Himpe (0000-0003-2194-6754), S. Rave (0000-0003-0439-7212)
%%% license: BSD 2-Clause License (opensource.org/licenses/BSD-2-Clause)
%%% summary: Basic test of (parallel) distributed HAPOD via MapReduce
%% Generate Test Data
randn('seed',1009);
n = 32;
N = n*n;
[a,~,c] = svd(randn(N,N));
b = logspace(0,-16,N)';
S = a*diag(b)*c';
E = sqrt(eps);
w = 0.5;
%% MapReduce Setup
% Define datastore
ds = arrayDatastore(S,'IterationDimension',2,'ReadSize',n);
% Define mapper
function hapod_mapper(data,info,intermKVStore)
[u,~,c] = hapod(data',E,'dist_1',w);
add(intermKVStore,'leaf',{u,c});
end
% Define reducer
function hapod_reducer(intermKey,intermValIter,outKVStore)
u = {};
c = {};
while hasnext(intermValIter)
value = getnext(intermValIter);
u{end+1} = value{1};
c{end+1} = value{2};
end%while
[U,D,C] = hapod(u,E,'dist_r',w,c);
addmulti(outKVStore,{'root_singvec','root_singval','root_info'},{U,D,C});
end
% Apply map and reduce
mr = mapreduce(ds,@hapod_mapper,@hapod_reducer).readall();
singvals = mr.Value{find(strcmp(mr.Key,'root_singval'))};
%% Plot Results
figure;
semilogy(1:numel(singvals),b(1:numel(singvals)),'LineWidth',2);
hold on;
semilogy(1:numel(singvals),singvals,'LineWidth',2,'LineStyle','--');
hold off;
xlim([1,numel(singvals)]);
ylabel('Singular Values');
legend('Exact','Distributed HAPOD','Location','SouthOutside');
end