Skip to content

Commit 2353a78

Browse files
68412542+EagleAglow@users.noreply.github.com68412542+EagleAglow@users.noreply.github.com
authored andcommitted
Version 3.3
Option to use 1, 2 or 3 threads to read
1 parent a6cc057 commit 2353a78

File tree

5 files changed

+446
-44
lines changed

5 files changed

+446
-44
lines changed

entries/bfire/README.md

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,8 @@ An Entry to the One Billion Row Challenge in Object Pascal using Delphi 12 by [E
88

99
### Dependencies
1010

11-
Project uses Delphi units: `Classes`, `System.SysUtils`, `System.StrUtils` and `Math`.
12-
13-
### UTF8 vs. Windows Terminal
14-
15-
The text in the Windows Terminal console uses the system code page, which does not play well with `UTF8`.
16-
The only way to match the approved result is to write the output to a file, with resulting `SHA256` hash:\
17-
`4256d19d3e134d79cc6f160d428a1d859ce961167bd01ca528daca8705163910`
18-
19-
If the Windows console output is redirected to a file, some characters are mangled, and the resulting `SHA256` hash is:\
20-
`5c1942377034a69c7457f7cf671b5f8605df597ef18037c1baf4b9ead3c84678`
21-
22-
For the challenge, compiled for LINUX, the console result will (hopefully) be correct.
11+
Project uses Delphi System units: `Classes`, `SysUtils`, `StrUtils`, `Diagnostics`,
12+
`Threading` and `SyncObjs`.
2313

2414
### Execution
2515
```
@@ -30,6 +20,9 @@ For the challenge, compiled for LINUX, the console result will (hopefully) be co
3020
bfire -i <file_1> -o <file_2> | <file_1> contains Weather Data
3121
| <file_2> contains result
3222
If <file_2> is not defined, result goes to CONSOLE (STDOUT)
23+
24+
Select 1, 2 or 3 reading threads (use -r in addition to -o)
25+
bfire -i <file_1> -o <file_2> -r <n>
3326
```
3427

3528
#### Contest Mode
@@ -51,19 +44,23 @@ The list is initially unsorted and has linked objects for records holding accumu
5144
Finally, the TStringList is sorted and used to output sorted data.
5245

5346
Third version has a thread for the console (which waits for tabulation, then sorts and writes results),
54-
one thread to read file, four threads to tabulate stations (split by section of alphabet). File is read
55-
byte-wise into "classic" byte arrays for station name and temperature. The arrays are passed to one of
56-
four stacks, split by section of alphabet, for tabulation. Tabulation threads hash station name, use hash
57-
as index into a data array. After all data is read and tabulated, the four data arrays are added to an
47+
two threads to read file, five threads to tabulate stations. Stations are grouped into five separate stacks,
48+
so each tabulation thread has roughly the same work load. File is read byte-wise into "classic" byte array
49+
for each file line ending in ascii 10. Each of these arrays is queued as a record in a last-in-first-out stack.
50+
Tabulation threads split the data into station name and temperature, then hash station name and use hash
51+
as index into one of five data arrays. After all data is read and tabulated, the five data arrays are added to an
5852
initially unsorted TStringList that holds unsorted Unicode station name and has linked pointers to
5953
tabulated data for each station. Finally, the TStringList is sorted, and the data is output.
6054

6155
## History
6256

63-
- Version 1.0: First working version, based on TStringList.
64-
- Version 1.1: Modified rounding to new baseline.
65-
- Version 2.0: Use hashing, sort later.
66-
- Version 2.1: Minor speed tweaks.
67-
- Version 2.2: Try hash functions modification.
57+
- Version 1.0: first working version, based on TStringList.
58+
- Version 1.1: modified rounding to new baseline.
59+
- Version 2.0: use hashing, sort later.
60+
- Version 2.1: minor speed tweaks.
61+
- Version 2.2: try hash functions modification.
6862
- Version 3.0: Six threads: one to read, four to tabulate, one (console) to rule them all...
69-
- Version 3.1: Safer locking strategy
63+
- Version 3.1: Safer locking strategy - didn't work.
64+
- Version 3.2: Eight threads: two to read, five to tabulate, one (console) to rule them all...
65+
- Version 3.3: Use 1, 2 or 3 threads to read.
66+

entries/bfire/src/ConsoleUnit.pas

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ interface
1313
cShortOptVersion: Char = 'v';
1414
cShortOptInput: Char = 'i';
1515
cShortOptOutput: Char = 'o';
16-
cShortOptions: array of Char = ['h', 'v', 'i', 'o'];
16+
cShortOptReaders: Char = 'r';
17+
cShortOptions: array of Char = ['h', 'v', 'i', 'o', 'r'];
1718

1819
resourcestring
1920
rsAppTitle = 'One Billion Row Challenge Entry';
@@ -29,6 +30,7 @@ interface
2930
inputFilename: String = '';
3031
outputFilename: String = '';
3132
FParams: TStringList;
33+
ReadThreadCountParam: String = '2'; // unless changed to 1, below
3234

3335
function ParseConsoleParams: Boolean;
3436

@@ -45,6 +47,10 @@ procedure WriteHelp;
4547
WriteLn(' bfire -i <file_1> -o <file_2> | <file_1> contains Weather Data');
4648
WriteLn(' | <file_2> contains result');
4749
WriteLn(' If <file_2> is not defined, result goes to CONSOLE (STDOUT)');
50+
WriteLn;
51+
WriteLn('Debugging Options (use in addition to -o)');
52+
WriteLn(' bfire -i <file_1> -o <file_2> -r 1 | Use a single reading thread');
53+
4854
end;
4955

5056
function CheckShortParams(const AParam: Char): Boolean;
@@ -163,7 +169,6 @@ function ParseConsoleParams: Boolean;
163169
J := FParams.IndexOfName(cShortOptOutput);
164170
if J = -1 then // send to console
165171
begin
166-
// WriteLn(Format(rsErrorMessage, [rsMissingOutputFlag]));
167172
outputFilename := '';
168173
inc(valid);
169174
end
@@ -173,6 +178,37 @@ function ParseConsoleParams: Boolean;
173178
inc(valid);
174179
end;
175180

181+
// check for read thread count
182+
J := -1;
183+
J := FParams.IndexOfName(cShortOptReaders);
184+
if J > -1 then // test value
185+
begin
186+
if FParams.ValueFromIndex[J] = '1' then
187+
begin
188+
ReadThreadCountParam := '1';
189+
end
190+
else
191+
begin
192+
if FParams.ValueFromIndex[J] = '2' then
193+
begin
194+
ReadThreadCountParam := '2';
195+
end
196+
else
197+
begin
198+
if FParams.ValueFromIndex[J] = '3' then
199+
begin
200+
ReadThreadCountParam := '3';
201+
end
202+
else
203+
begin
204+
WriteLn('Invalid value for Read Thread Count: ' +
205+
FParams.ValueFromIndex[J]);
206+
exit;
207+
end;
208+
end;
209+
end;
210+
end;
211+
176212
// check if everything was provided
177213
ParseConsoleParams := valid = 2;
178214
end;

0 commit comments

Comments
 (0)