-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.asv
108 lines (95 loc) · 1.89 KB
/
main.asv
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
clear;
%tic;
a=randi([1,100000],1,80000);
% initialising matlabpool with 4 workers
matlabpool open 4
% initialising spmd tool to distribute jobs over
% all 4 labs for parallel processing
%tic;
spmd
% distributing inputs to each lab
p=codistributed(a);
P=getLocalPart(p);
len=length(P);
B=zeros(size(P));
% calling radixSort() method to sort elements
% and storing result from individual lab
%into distributed array B
B=radixSort(P);
end
% taking results from each lab
input1=B{1}; %lab 1
input2=B{2}; %lab 2
input3=B{3}; %lab 3
input4=B{4}; %lab 4
%tot=toc;
matlabpool close
%creating a cell with all sorted arrays from each lab
cell={input1,input2,input3,input4};
%merging results from each lab
matlabpool(2)
tic;
spmd(0,2)
dcell=codistributed(cell);
lcell=getLocalPart(dcell);
i=1;
j=1;
k=1;
while i<=length(lcell{1}) & j<=length(lcell{2})
if(lcell{1}(i)<=lcell{2}(j))
result(k)=lcell{1}(i);
i=i+1;
else
result(k)=lcell{2}(j);
j=j+1;
end
k=k+1;
end
while(i<=length(lcell{1}))
result(k)=lcell{1}(i);
i=i+1;
k=k+1;
end
while(j<=length(lcell{2}))
result(k)=lcell{2}(j);
j=j+1;
k=k+1;
end
%disp(result);
end
disp(toc);
%sortData=
%merging(result{1},result{2});
result1=result{1};
result2=result{2};
matlabpool close
tic;
i=1;
j=1;
k=1;
while i<=length(result1) & j<=length(result2)
if(result1(i)<=result2(j))
fresult(k)=result1(i);
i=i+1;
else
fresult(k)=result2(j);
j=j+1;
end
k=k+1;
end
while(i<=length(result1))
fresult(k)=result1(i);
i=i+1;
k=k+1;
end
while(j<=length(result2))
fresult(k)=result2(j);
j=j+1;
k=k+1;
end
disp(toc);
%tot=tot+toc;
%disp(tot);
%displaying resultant sorted array
%disp(sortData);
%disp(toc);