Skip to content

Commit 118a0fd

Browse files
authored
Merge pull request #82 from OttoCoddo/main
Add ProcessorCount, help and improved handling parameters
2 parents 0c8e72a + cdc03de commit 118a0fd

2 files changed

Lines changed: 49 additions & 24 deletions

File tree

entries/ocoddo/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ Hope you find this interesting.
1313
- Make sure you set build mode to `Release`
1414
- Build
1515
- Run as `./ocoddo ./input.txt`
16-
- You can try different parameters for your hardware: `./ocoddo ./input.txt --jumper-count=192 --part-size=192`. Try values from `128`, `192`, `256`, and up
16+
- You can try different parameters for your hardware: `./ocoddo ./input.txt --jumper-count=192 --part-size=192 --processor-count=32`. Try values from `128`, `192`, `256`, and up
1717

1818

1919

2020
Made by O
21+

entries/ocoddo/src/Project1.lpr

Lines changed: 47 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
var
3232
JumperCount: UPS;
3333
PartSize: UPS;
34+
ProcessorCount: U8;
3435

3536
type
3637
THash = U32;
@@ -240,11 +241,6 @@ TStationSummary = record
240241

241242
procedure Process(out AStations: TStationResultArray); overload;
242243

243-
function ProcessorCount: U8;
244-
begin
245-
Result := LogicalProcessorCount;
246-
end;
247-
248244
procedure Initialize(out AContext: TContext);
249245
var
250246
I: Ind;
@@ -368,27 +364,55 @@ TStationSummary = record
368364
WriteLn(ToStr(RST));
369365
end;
370366

371-
var
372-
I: Ind;
373-
N: Str;
374-
V: I64;
375-
begin
376-
if Length(Parameters) = 0 then
377-
Exit;
367+
function HandleParameters(out AFilePath: TFilePath): Bool;
368+
var
369+
I: Ind;
370+
N: Str;
371+
V: I64;
372+
begin
373+
Result := False;
374+
if Length(Parameters) = 0 then
375+
begin
376+
WriteLn;
377+
WriteLn('1BRC');
378+
WriteLn('----');
379+
WriteLn('Made by O');
380+
WriteLn;
381+
WriteLn('Usage:');
382+
WriteLn('./ocoddo ./input.txt [Options]');
383+
WriteLn;
384+
WriteLn('Options:');
385+
WriteLn('--jumper-count=[Value]. Use 128, 192, 256, etc');
386+
WriteLn('--part-size=[Value]. Use 128, 192, 256, etc');
387+
WriteLn('--processor-count=[Value]. Use 1 or more');
388+
WriteLn;
389+
Exit;
390+
end;
378391

379-
JumperCount := 256 * 1024;
380-
PartSize := 192 * 1024 - ReadMargin;
392+
ProcessorCount := LogicalProcessorCount;
393+
JumperCount := 256 * 1024;
394+
PartSize := 192 * 1024 - ReadMargin;
381395

382-
for I := 1 to High(Parameters) do
383-
begin
384-
N := Name(Parameters[I]);
385-
ToI64(Value(Parameters[I]), V);
396+
for I := 1 to High(Parameters) do
397+
begin
398+
N := Name(Parameters[I]);
399+
ToI64(Value(Parameters[I]), V);
400+
401+
if N = 'jumper-count' then
402+
JumperCount := V * 1024
403+
else if N = 'part-size' then
404+
PartSize := (V * 1024) - ReadMargin
405+
else if N = 'processor-count' then
406+
ProcessorCount := V;
407+
end;
386408

387-
if N = 'jumper-count' then
388-
JumperCount := V * 1024
389-
else if N = 'part-size' then
390-
PartSize := (V * 1024) - ReadMargin;
409+
AFilePath := Fix(Value(Parameters[0]));
410+
Result := True;
391411
end;
392412

393-
Run(&File(Fix(Value(Parameters[0]))));
413+
var
414+
FN: TFilePath;
415+
begin
416+
if HandleParameters(FN) then
417+
Run(&File(FN));
394418
end.

0 commit comments

Comments
 (0)