Skip to content

Commit 94861b5

Browse files
author
Alex
committed
Parallel config added.
1 parent c4db094 commit 94861b5

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

config.m

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
%% Configure parameters
55
%Polar-Code values
66
capacity = 0.5; %I(W), Channel's W Capacity
7-
n_values = [4,5,6,7,8,9,10]; %value of N
7+
n_values = [4,5,6,7,8]; %value of N
88
code_rate = 1/4;
99
%EbNo
1010
EbNo_dB = 0:5; %AWGN -4:2 %Fading 0:2:10
@@ -28,6 +28,30 @@
2828
NbitsPerSymbol = 1; %modulation parameter
2929
constDims = 1; %modulation parameter
3030
snrdb_values =EbNo_dB+10*log10(double(code_rate*NbitsPerSymbol*2/constDims));
31+
%% Parfor configuration
32+
FLAG_Enable_parpool=1; % 0: Disable, 1: Enable
33+
parcore_nums = 4;
34+
if FLAG_Enable_parpool
35+
% determine the number of physical cores
36+
corenum = feature('numcores');
37+
parcorenum = parcore_nums;
38+
% parcorenum = 15; % # of workers
39+
p = gcp('nocreate'); % Not create new pool if it does not exist
40+
if isempty(p)
41+
p = parcluster('local');
42+
p.NumWorkers = parcorenum;
43+
parpool(p, p.NumWorkers);
44+
end
45+
if p.NumWorkers ~= parcorenum
46+
delete(p);
47+
p = parcluster('local');
48+
p.NumWorkers = parcorenum;
49+
parpool(p, p.NumWorkers);
50+
end
51+
parallel_frames = 100*parcorenum;
52+
else
53+
parallel_frames = 10;
54+
end
3155
%% Variable Initializations
3256
bit_error_rate = zeros(length(n_values),length(snrdb_values));
3357
fer_error_rate = zeros(length(n_values),length(snrdb_values));

main.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
codewords_tmp = 0;fer_errors = 0;bit_errors = 0;
1616
snr = snrdb_values(i_index);
1717
while (fer_errors<min_fer_errors || codewords_tmp<min_codewords)
18-
codewords_tmp = codewords_tmp + 1;
18+
bit_errors_parfor = zeros(1,parallel_frames);
19+
fer_errors_parfor = zeros(1,parallel_frames);
20+
% for frame = 1:parallel_frames
21+
parfor frame = 1:parallel_frames
1922
inputs = rand(1,K)>0.5; %write random inputs
2023
%transform inputs
2124
inputs_to_encode = transform_inputs(inputs,frozen_bits,N);
@@ -38,8 +41,12 @@
3841
%Calculate temporary bit/frame errors
3942
final_outputs = transform_outputs(outputs,frozen_bits,N);
4043
temp_bit_errors = size(find(final_outputs ~= inputs),2);
41-
bit_errors = bit_errors + temp_bit_errors;
42-
fer_errors = fer_errors + (temp_bit_errors>0);
44+
bit_errors_parfor(frame) = temp_bit_errors;
45+
fer_errors_parfor(frame) = (temp_bit_errors>0);
46+
end
47+
codewords_tmp = codewords_tmp + parallel_frames;
48+
bit_errors = bit_errors + sum(bit_errors_parfor);
49+
fer_errors = fer_errors + sum(fer_errors_parfor);
4350
end
4451
%Calculate snr bit/frame errors
4552
bit_error_rate(index_n,i_index) = bit_errors/(codewords_tmp*K);

0 commit comments

Comments
 (0)