HPCE / hpce-2017-cw5

1 stars 6 forks source link

How to actually run the puzzles #7

Closed m0zjo-code closed 6 years ago

m0zjo-code commented 6 years ago

Errr slightly embarrassing question...

It's not immediately clear to me on how to actually run the compiled puzzles after going through the readme - I keep getting seg-faults on the provided implementation which I guess means I'm just using them wrong...

Could someone provide some example use cases of the puzzles please??

Thanks! :)

m8pple commented 6 years ago

Ah yes, in the interest of a short readme I left things a bit implicit.

So assuming you've done make all, you could use bin/run_puzzle:

$ bin/run_puzzle
run_puzzle name scale logLevel
Puzzles:
edit_distance
gaussian_blur
hold_time
mining
random_projection

This is saying that the program takes three arguments:

So if we choose name=mining, scale=20, logLevel=2:

$ bin/run_puzzle mining 20 2
LogLevel = 2 -> 2
[run_puzzle], 1510481496.81, 2, Created log.
[run_puzzle], 1510481496.81, 2, Creating random input
[run_puzzle], 1510481496.81, 2, Executing puzzle
[run_puzzle], 1510481496.81, 2, Executing reference
[run_puzzle], 1510481496.81, 2, Checking output
[run_puzzle], 1510481496.81, 2, Output is correct

Increasing the log-level results in more output:

$ bin/run_puzzle mining 20 3
LogLevel = 3 -> 3
[run_puzzle], 1510481531.46, 2, Created log.
[run_puzzle], 1510481531.46, 2, Creating random input
[run_puzzle], 1510481531.46, 2, Executing puzzle
[run_puzzle], 1510481531.46, 3, Found new best of 13001368952934052812, ratio=0.00354708
[run_puzzle], 1510481531.46, 3, Found new best of 3475098330808870328, ratio=0.0132707
[run_puzzle], 1510481531.46, 3, Found new best of 2993103420261690249, ratio=0.0154077
[run_puzzle], 1510481531.46, 3, Found new best of 1174583366943439854, ratio=0.0392623
[run_puzzle], 1510481531.46, 3, Found new best of 234398509893197458, ratio=0.196746
[run_puzzle], 1510481531.46, 3, Found new best of 170740885297889898, ratio=0.270099
[run_puzzle], 1510481531.46, 3, Found new best of 151155954521271800, ratio=0.305095
[run_puzzle], 1510481531.46, 3, Found new best of 80107323736766319, ratio=0.575688
[run_puzzle], 1510481531.46, 3, Found new best of 63841427804842625, ratio=0.722366
[run_puzzle], 1510481531.46, 2, Executing reference
[run_puzzle], 1510481531.46, 3, Found new best of 13001368952934052812, ratio=0.00354708
[run_puzzle], 1510481531.46, 3, Found new best of 3475098330808870328, ratio=0.0132707
[run_puzzle], 1510481531.46, 3, Found new best of 2993103420261690249, ratio=0.0154077
[run_puzzle], 1510481531.46, 3, Found new best of 1174583366943439854, ratio=0.0392623
[run_puzzle], 1510481531.46, 3, Found new best of 234398509893197458, ratio=0.196746
[run_puzzle], 1510481531.46, 3, Found new best of 170740885297889898, ratio=0.270099
[run_puzzle], 1510481531.46, 3, Found new best of 151155954521271800, ratio=0.305095
[run_puzzle], 1510481531.46, 3, Found new best of 80107323736766319, ratio=0.575688
[run_puzzle], 1510481531.46, 3, Found new best of 63841427804842625, ratio=0.722366
[run_puzzle], 1510481531.46, 2, Checking output
[run_puzzle], 1510481531.46, 2, Output is correct
m8pple commented 6 years ago

And for independent files, we can create and save an input to a file (with the same parameters as before):

$ bin/create_puzzle_input mining 20 2 > w/input.bin
LogLevel = 2 -> 2
[run_puzzle], 1510481643.80, 2, Created log.
[run_puzzle], 1510481643.80, 2, Creating random input
[run_puzzle], 1510481643.80, 2, Writing data to stdout

We can then execute the puzzle:

$ bin/execute_puzzle
execute_puzzle isReference logLevel

So isReference controls whether it is the original version (1), or your optimised version (0).

Running the reference version:

$ cat w/input.bin | bin/execute_puzzle 1 2 > w/output.ref
[execute_puzzle], 1510481734.90, 2, Created log.
[execute_puzzle], 1510481734.90, 2, Loaded input, puzzle=mining
[execute_puzzle], 1510481734.90, 2, Begin reference
[execute_puzzle], 1510481734.90, 2, Finished reference

then the customised version (note the 1 has changed to a 0):

$ cat w/input.bin | bin/execute_puzzle 0 2 > w/output.got
[execute_puzzle], 1510481882.28, 2, Created log.
[execute_puzzle], 1510481882.28, 2, Loaded input, puzzle=mining
[execute_puzzle], 1510481882.28, 2, Begin execution
[execute_puzzle], 1510481882.28, 2, Finished execution

We now have:

The solution can then be compared:

$ bin/compare_puzzle_output w/input.bin w/output.ref w/output.got 2
LogLevel = 2 -> 2
[execute_puzzle], 1510481972.43, 2, Created log.
[execute_puzzle], 1510481972.43, 2, Loading input w/input.bin
[execute_puzzle], 1510481972.43, 2, Creating puzzle mining to match input
[execute_puzzle], 1510481972.43, 2, Loading reference w/output.ref
[execute_puzzle], 1510481972.43, 2, Loading got w/output.got
[execute_puzzle], 1510481972.43, 2, Outputs are equal.

There is also an example testing build target in the makefile called serenity_now - try doing make serenity_now.

m0zjo-code commented 6 years ago

Wonderful thanks! 👍