Another interesting thing in Hennessy.Mod is procedure Rand, one of the two pseudorandom number generators in it. The C version is: int Rand () { seed = (seed * 1309 + 13849) & 65535; return (seed); }; This can be translated to Oberon thus: PROCEDURE Rand (): INTEGER; BEGIN seed := (seed * 1309 + 13849) MOD 65536 (* use MOD 65636 to get the same output as C *) RETURN seed (* in V5 use MOD 65535 to prevent a crash in Tree *) END Rand; In Oberon '... MOD 65536' produces the same pseudorandom numbers as '... & 65535' in C. I can understand that: at the bit level '... MOD 65536' is equivalent to '... & 65535'. But could anyone explain why '... MOD 65636' gives a crash in Tree and '... MOD 65535' does not? That is: in System Oberon V5, using the 2016-08-02 version of the compiler; when using the 2019-01-21 version more things go wrong. The OBNC compiler is unproblematic when the correct code ... MOD 65636 is used. I also applied patches to the 2019-01-21 version, as suggested by Andreas Pirklbauer in his posts of 27-2-2020 and 01-03-2020, but then I get three 'reg stack' compiler errors pointing to the Time procedure. -- Hans Klaver
Sorry: 65636 in the text should be 65536.
seed := (seed * 1309 + 13849) MOD 65536 (* use MOD 65636 to get the same output as C *) RETURN seed (* in V5 use MOD 65535 to prevent a crash in Tree *) END Rand;
In Oberon '... MOD 65536' produces the same pseudorandom numbers as '... & 65535' in C. I can understand that: at the bit level '... MOD 65536' is equivalent to '... & 65535'.
But could anyone explain why '... MOD 65636' gives a crash in Tree and '... MOD 65535' does not?
Hans Just take the well-proven random generator. Below I inserted my version in Oberon-07 br Jörg . . . . . . MODULE RandomNumbers; IMPORT Kernel; (* Park-Miller 1993 *) CONST a = 48271; m = 7FFFFFFFH; q = m DIV a; r = m MOD a; VAR z*: INTEGER; PROCEDURE Uniform*(): REAL; (* returns a random nbr 0 < x < 1 *) (* z = a * z MOD m by Schrage's method *) BEGIN z := a*(z MOD q) - r*(z DIV q); IF z < 0 THEN INC(z, m) END RETURN FLT(z) / FLT(m) END Uniform; PROCEDURE RND*(max: INTEGER): INTEGER; (* returns an integer in the range 0..max-1 *) RETURN FLOOR(Uniform() * FLT(max)) END RND; PROCEDURE InitSeed*(seed: INTEGER); BEGIN IF seed = 0 THEN z := 1 ELSE z := seed END; END InitSeed; BEGIN InitSeed(Kernel.Time()) END RandomNumbers. Am 09.04.20, 10:22 schrieb "Oberon im Auftrag von Hans Klaver" <oberon-bounces@lists.inf.ethz.ch im Auftrag von hklaver@dds.nl>: Sorry: 65636 in the text should be 65536. > > seed := (seed * 1309 + 13849) MOD 65536 (* use MOD 65636 to get the same output as C *) > RETURN seed (* in V5 use MOD 65535 to prevent a crash in Tree *) > END Rand; > > In Oberon '... MOD 65536' produces the same pseudorandom numbers as '... & 65535' in C. > I can understand that: at the bit level '... MOD 65536' is equivalent to '... & 65535'. > > But could anyone explain why '... MOD 65636' gives a crash in Tree and '... MOD 65535' does not? -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Jörg, you wrote:
Just take the well-proven random generator. Below I inserted my version in Oberon-07
Thanks for the suggestion. The Lehmer-Schrage RN generator from the Reiser-Wirth book (with your prime number modification of the a constant!) has been in my Oberon-07 library for some time already (see https://github.com/hansklav/Oberon-07/blob/master/Random.Mod). But in the case of the Hennessy benchmarks I would regard it as a form of 'cheating' to use another function than the one that is part of the benchmark, because the most pure comparisons are only possible if the same list of random numbers is used in each implementation, even if the random function is not perfect. Now I suspect the crash of the Oberon System V5 described by me is caused by some external code used by Peter de Wachter's RISC emulator, because only now I noticed that the following error message is shown on the command line where I started the emulator: Assertion failed: (data && data_ptr < data_len), function clipboard_data_write, file src/sdl-clipboard.c, line 78. Abort trap: 6 Maybe it is even specific to the macOS version of SDL2 (I use the RISC emulator under macOS). I have never used the clipboard function of the RISC emulator. Again: the OBNC Oberon-07 compiler has no problem with the Rand function as it should be, and OBNC also uses the SDL2 library for certain functionality, but probably not this particular function. -- Hans Klaver
Hans Indeed, first I thought the culprit is the random number generator. The treesort algorithm in the Hennessy benchmark uses two things that can go wrong: First, it uses the recursive procedure Insert and Checktree. Second, it allocates a node on the heap for the tree structure. So, either the stack underflows (because of the recursion is too deep) or the heap overflows or both. Let’s look at the stack: the recursion depth of Insert varies depending on the values generated by Rand(). I played a little with different start values of seed and found the recursion depth varies between 20 and 27. Nothing to be worried about. Stack underflow is not going to happen. Let’s look at the heap: How many times CreateNode is called, depends on the values generated by Rand(). Generally a “node” uses 12 bytes, but the smallest allocation granularity on the heap is 32 bytes à every call to CreateNode needs 32 bytes on the heap. With DIV 65535 in the random number generator, CreateNode is - by luck - only called 767 times = 24.5 kB. As Time() repeats Trees() 10 times, we’ll need overall 245 kB of heap space. Trees() terminates happily. With DIV 65536, CreateNode is called 4999 times = 160 kB. After 2 iterations in Time(), the available heap is exhausted. One remark, even if you use DIV 65535 you can’t call Hennessy.Do several times, as the garbage collector can not do it’s job. Reason for this is that “tree” is not set to NIL. If you want to improve Trees a little, put “tree := NIL” at the end of Trees(). But this does not help in case of DIV 65536. br Jörg Von: Oberon <oberon-bounces@lists.inf.ethz.ch> im Auftrag von Hans Klaver <hklaver@dds.nl> Antworten an: ETH Oberon and related systems <oberon@lists.inf.ethz.ch> Datum: Freitag, 10. April 2020 um 01:18 An: ETH Oberon and related systems <oberon@lists.inf.ethz.ch> Betreff: Re: [Oberon] ... MOD 65536 Jörg, you wrote: Just take the well-proven random generator. Below I inserted my version in Oberon-07 Thanks for the suggestion. The Lehmer-Schrage RN generator from the Reiser-Wirth book (with your prime number modification of the a constant!) has been in my Oberon-07 library for some time already (see https://github.com/hansklav/Oberon-07/blob/master/Random.Mod). But in the case of the Hennessy benchmarks I would regard it as a form of 'cheating' to use another function than the one that is part of the benchmark, because the most pure comparisons are only possible if the same list of random numbers is used in each implementation, even if the random function is not perfect. Now I suspect the crash of the Oberon System V5 described by me is caused by some external code used by Peter de Wachter's RISC emulator, because only now I noticed that the following error message is shown on the command line where I started the emulator: Assertion failed: (data && data_ptr < data_len), function clipboard_data_write, file src/sdl-clipboard.c, line 78. Abort trap: 6 Maybe it is even specific to the macOS version of SDL2 (I use the RISC emulator under macOS). I have never used the clipboard function of the RISC emulator. Again: the OBNC Oberon-07 compiler has no problem with the Rand function as it should be, and OBNC also uses the SDL2 library for certain functionality, but probably not this particular function. -- Hans Klaver -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hans I did the following: PROCEDURE Trees* (); VAR i : LONGINT; BEGIN IF Kernel.heapLim - Kernel.heapOrg - Kernel.allocated > 160000 THEN tInitarr(); NEW(tree); (* here the rest of Trees *) END; tree := NIL; Oberon.Collect(0) (* tell the GC to start after Hennessy terminated *) END Trees; With these modifications you can take whatever random number generator you wanna use. DIV 65535 (wrong) or DIV 65536 (corresponds to the C original) or any other. br Joerg Von: Oberon <oberon-bounces@lists.inf.ethz.ch> im Auftrag von Jörg <joerg.straube@iaeth.ch> Antworten an: ETH Oberon and related systems <oberon@lists.inf.ethz.ch> Datum: Freitag, 10. April 2020 um 12:45 An: ETH Oberon and related systems <oberon@lists.inf.ethz.ch> Betreff: Re: [Oberon] ... MOD 65536 Hans Indeed, first I thought the culprit is the random number generator. The treesort algorithm in the Hennessy benchmark uses two things that can go wrong: First, it uses the recursive procedure Insert and Checktree. Second, it allocates a node on the heap for the tree structure. So, either the stack underflows (because of the recursion is too deep) or the heap overflows or both. Let’s look at the stack: the recursion depth of Insert varies depending on the values generated by Rand(). I played a little with different start values of seed and found the recursion depth varies between 20 and 27. Nothing to be worried about. Stack underflow is not going to happen. Let’s look at the heap: How many times CreateNode is called, depends on the values generated by Rand(). Generally a “node” uses 12 bytes, but the smallest allocation granularity on the heap is 32 bytes à every call to CreateNode needs 32 bytes on the heap. With DIV 65535 in the random number generator, CreateNode is - by luck - only called 767 times = 24.5 kB. As Time() repeats Trees() 10 times, we’ll need overall 245 kB of heap space. Trees() terminates happily. With DIV 65536, CreateNode is called 4999 times = 160 kB. After 2 iterations in Time(), the available heap is exhausted. One remark, even if you use DIV 65535 you can’t call Hennessy.Do several times, as the garbage collector can not do it’s job. Reason for this is that “tree” is not set to NIL. If you want to improve Trees a little, put “tree := NIL” at the end of Trees(). But this does not help in case of DIV 65536. br Jörg Von: Oberon <oberon-bounces@lists.inf.ethz.ch> im Auftrag von Hans Klaver <hklaver@dds.nl> Antworten an: ETH Oberon and related systems <oberon@lists.inf.ethz.ch> Datum: Freitag, 10. April 2020 um 01:18 An: ETH Oberon and related systems <oberon@lists.inf.ethz.ch> Betreff: Re: [Oberon] ... MOD 65536 Jörg, you wrote: Just take the well-proven random generator. Below I inserted my version in Oberon-07 Thanks for the suggestion. The Lehmer-Schrage RN generator from the Reiser-Wirth book (with your prime number modification of the a constant!) has been in my Oberon-07 library for some time already (see https://github.com/hansklav/Oberon-07/blob/master/Random.Mod). But in the case of the Hennessy benchmarks I would regard it as a form of 'cheating' to use another function than the one that is part of the benchmark, because the most pure comparisons are only possible if the same list of random numbers is used in each implementation, even if the random function is not perfect. Now I suspect the crash of the Oberon System V5 described by me is caused by some external code used by Peter de Wachter's RISC emulator, because only now I noticed that the following error message is shown on the command line where I started the emulator: Assertion failed: (data && data_ptr < data_len), function clipboard_data_write, file src/sdl-clipboard.c, line 78. Abort trap: 6 Maybe it is even specific to the macOS version of SDL2 (I use the RISC emulator under macOS). I have never used the clipboard function of the RISC emulator. Again: the OBNC Oberon-07 compiler has no problem with the Rand function as it should be, and OBNC also uses the SDL2 library for certain functionality, but probably not this particular function. -- Hans Klaver -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Hi Jörg, Just now I noticed that my reply to your modification of Hennessy.Trees (below) did not make it to the list (possibly because I included a few screenprints of run times). So now again: Thanks Jörg, this modification is great! Everything runs as it should now. Now also in Oberon System V5 Hennessy.Mod can be used with ...MOD 65536 (sic!) in procedure Rand. All reference output is as it should be. And as a nice side effect of your modification the treesort benchmark runs nearly three times as fast as before: Run times Hennessy Mm and Sort procedures in V5 (10 runs, ms): MOD Trees Intmm Mm Quick Bubble Tree 65535 original 983 998 900 2016 747 65536 original 984 1016 933 2017 -- 65535 modified 966 1014 876 1954 647 65536 modified 970 1016 908 1971 *259* These are all benchmarks that make use of procedure Rand. As can be seen in most of them there is no noticable difference whether 65535 of 65536 is used in the MOD expression, but sometimes there can be a huge difference. This is an illustration that in benchmarks it is important to consistently use the same pseudo-random generator and initial seed. -- Hans Klaver
Op 10 apr. 2020, om 13:20 heeft Jörg <joerg.straube@iaeth.ch> het volgende geschreven:
Hans
I did the following: PROCEDURE Trees* (); VAR i : LONGINT; BEGIN IF Kernel.heapLim - Kernel.heapOrg - Kernel.allocated > 160000 THEN tInitarr(); NEW(tree); (* here the rest of Trees *) END; tree := NIL; Oberon.Collect(0) (* tell the GC to start after Hennessy terminated *) END Trees;
With these modifications you can take whatever random number generator you wanna use. DIV 65535 (wrong) or DIV 65536 (corresponds to the C original) or any other.
br Joerg
Hans That „Trees“ seems to run faster is because I skip the execution if there is not enough memory. In other words, although Time() calls every algorithm 10 times, Trees will in a lot of cases only run 2 or 3 times (of those 10 calls) depending on the amount of heap space left... br Jörg
Am 13.04.2020 um 19:47 schrieb Hans Klaver <hklaver@dds.nl>:
Hi Jörg,
Just now I noticed that my reply to your modification of Hennessy.Trees (below) did not make it to the list (possibly because I included a few screenprints of run times).
So now again:
Thanks Jörg, this modification is great! Everything runs as it should now.
Now also in Oberon System V5 Hennessy.Mod can be used with ...MOD 65536 (sic!) in procedure Rand. All reference output is as it should be.
And as a nice side effect of your modification the treesort benchmark runs nearly three times as fast as before:
Run times Hennessy Mm and Sort procedures in V5 (10 runs, ms):
MOD Trees Intmm Mm Quick Bubble Tree 65535 original 983 998 900 2016 747 65536 original 984 1016 933 2017 --
65535 modified 966 1014 876 1954 647 65536 modified 970 1016 908 1971 *259*
These are all benchmarks that make use of procedure Rand. As can be seen in most of them there is no noticable difference whether 65535 of 65536 is used in the MOD expression, but sometimes there can be a huge difference.
This is an illustration that in benchmarks it is important to consistently use the same pseudo-random generator and initial seed.
-- Hans Klaver
Op 10 apr. 2020, om 13:20 heeft Jörg <joerg.straube@iaeth.ch> het volgende geschreven:
Hans
I did the following: PROCEDURE Trees* (); VAR i : LONGINT; BEGIN IF Kernel.heapLim - Kernel.heapOrg - Kernel.allocated > 160000 THEN tInitarr(); NEW(tree); (* here the rest of Trees *) END; tree := NIL; Oberon.Collect(0) (* tell the GC to start after Hennessy terminated *) END Trees;
With these modifications you can take whatever random number generator you wanna use. DIV 65535 (wrong) or DIV 65536 (corresponds to the C original) or any other.
br Joerg
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Ah, now I see. So my current implementation of the Tree benchmark in Hennessy.Mod is not correct, and is 'cheating'. Maybe I should isolate the Tree benchmark as a separate module. This is also done in the C versions of the LLVM test-suite (for all benchmarks of the suite). And I suspect that the original Pascal versions of the Hennessy benchmarks also were separate programs, but I have never seen them. -- Hans
Op 13 apr. 2020, om 20:15 heeft Joerg <joerg.straube@iaeth.ch> het volgende geschreven:
Hans
That „Trees“ seems to run faster is because I skip the execution if there is not enough memory.
In other words, although Time() calls every algorithm 10 times, Trees will in a lot of cases only run 2 or 3 times (of those 10 calls) depending on the amount of heap space left...
br Jörg
Am 13.04.2020 um 19:47 schrieb Hans Klaver <hklaver@dds.nl>:
Hi Jörg,
Just now I noticed that my reply to your modification of Hennessy.Trees (below) did not make it to the list (possibly because I included a few screenprints of run times).
So now again:
Thanks Jörg, this modification is great! Everything runs as it should now.
Now also in Oberon System V5 Hennessy.Mod can be used with ...MOD 65536 (sic!) in procedure Rand. All reference output is as it should be.
And as a nice side effect of your modification the treesort benchmark runs nearly three times as fast as before:
Run times Hennessy Mm and Sort procedures in V5 (10 runs, ms):
MOD Trees Intmm Mm Quick Bubble Tree 65535 original 983 998 900 2016 747 65536 original 984 1016 933 2017 --
65535 modified 966 1014 876 1954 647 65536 modified 970 1016 908 1971 *259*
These are all benchmarks that make use of procedure Rand. As can be seen in most of them there is no noticable difference whether 65535 of 65536 is used in the MOD expression, but sometimes there can be a huge difference.
This is an illustration that in benchmarks it is important to consistently use the same pseudo-random generator and initial seed.
-- Hans Klaver
Op 10 apr. 2020, om 13:20 heeft Jörg <joerg.straube@iaeth.ch <mailto:joerg.straube@iaeth.ch>> het volgende geschreven:
Hans
I did the following: PROCEDURE Trees* (); VAR i : LONGINT; BEGIN IF Kernel.heapLim - Kernel.heapOrg - Kernel.allocated > 160000 THEN tInitarr(); NEW(tree); (* here the rest of Trees *) END; tree := NIL; Oberon.Collect(0) (* tell the GC to start after Hennessy terminated *) END Trees;
With these modifications you can take whatever random number generator you wanna use. DIV 65535 (wrong) or DIV 65536 (corresponds to the C original) or any other.
br Joerg
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Separate module or not, is not the key question. It does not help much. As it is coded today (sort 5000 elements) Trees needs (worst case scenario) 160 kB heap space. The Oberon system having only a total amount of 1MB offers ~420 kB heap space. So, it is impossible to run the algorithm 10 times. The garbage collector freeing up unused heap space is programmed in module Oberon but it‘s not exported. So officially, you can’t run the GC while your program runs. The allocated and now unused memory is only collected AFTER the Hennessy terminates. With a little bit of trickery you could program your own garbage collector that frees up all data structure Trees allocated with NEW after every call of Trees. But this is a little far fetched... br Jörg
Am 13.04.2020 um 20:36 schrieb Hans Klaver <hklaver@dds.nl>:
Ah, now I see.
So my current implementation of the Tree benchmark in Hennessy.Mod is not correct, and is 'cheating'.
Maybe I should isolate the Tree benchmark as a separate module. This is also done in the C versions of the LLVM test-suite (for all benchmarks of the suite). And I suspect that the original Pascal versions of the Hennessy benchmarks also were separate programs, but I have never seen them.
-- Hans
Op 13 apr. 2020, om 20:15 heeft Joerg <joerg.straube@iaeth.ch> het volgende geschreven:
Hans
That „Trees“ seems to run faster is because I skip the execution if there is not enough memory.
In other words, although Time() calls every algorithm 10 times, Trees will in a lot of cases only run 2 or 3 times (of those 10 calls) depending on the amount of heap space left...
br Jörg
Am 13.04.2020 um 19:47 schrieb Hans Klaver <hklaver@dds.nl>:
Hi Jörg,
Just now I noticed that my reply to your modification of Hennessy.Trees (below) did not make it to the list (possibly because I included a few screenprints of run times).
So now again:
Thanks Jörg, this modification is great! Everything runs as it should now.
Now also in Oberon System V5 Hennessy.Mod can be used with ...MOD 65536 (sic!) in procedure Rand. All reference output is as it should be.
And as a nice side effect of your modification the treesort benchmark runs nearly three times as fast as before:
Run times Hennessy Mm and Sort procedures in V5 (10 runs, ms):
MOD Trees Intmm Mm Quick Bubble Tree 65535 original 983 998 900 2016 747 65536 original 984 1016 933 2017 --
65535 modified 966 1014 876 1954 647 65536 modified 970 1016 908 1971 *259*
These are all benchmarks that make use of procedure Rand. As can be seen in most of them there is no noticable difference whether 65535 of 65536 is used in the MOD expression, but sometimes there can be a huge difference.
This is an illustration that in benchmarks it is important to consistently use the same pseudo-random generator and initial seed.
-- Hans Klaver
Op 10 apr. 2020, om 13:20 heeft Jörg <joerg.straube@iaeth.ch> het volgende geschreven:
Hans
I did the following: PROCEDURE Trees* (); VAR i : LONGINT; BEGIN IF Kernel.heapLim - Kernel.heapOrg - Kernel.allocated > 160000 THEN tInitarr(); NEW(tree); (* here the rest of Trees *) END; tree := NIL; Oberon.Collect(0) (* tell the GC to start after Hennessy terminated *) END Trees;
With these modifications you can take whatever random number generator you wanna use. DIV 65535 (wrong) or DIV 65536 (corresponds to the C original) or any other.
br Joerg
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Am 13.04.2020 um 21:09 schrieb Joerg:
The garbage collector freeing up unused heap space is programmed in module Oberon but it‘s not exported. So officially, you can’t run the GC while your program runs.
And when you try, you may accidentally collect objects that are only referenced on the stack by stack frames of your callers.
With a little bit of trickery you could program your own garbage collector that frees up all data structure Trees allocated with NEW after every call of Trees. But this is a little far fetched...
Easier solution: Change the tree node to have an extra node pointer "chain" , and add two more global node pointers "allocated" and "garbage" both initially NIL. Replace every call to NEW(node) by code that * if "garbage" is non-nil, use its value and advance it to "garbage.chain". * if "garbage" is nil, allocate a new node. In both cases, store the old value of "allocated" in the "new" node's "chain" and store the new node in "allocated". At the end of the algorithm (when discarding the old "tree"), move "allocated" to "garbage". Effectively have two linked lists of "allocated" and "free" tree nodes, and use those before allocating new ones. That way, you can run the algorithm as often as you want, it will always use the same tree nodes. But you may also consider that cheating, as it is no longer benchmarking the memory allocator after the first run. Regards, Michael
I put a global counter in the conditional part of Trees, and indeed it reveals that this part is entered only 2 times of the 10 calls, as you predicted. It's interesting that the "reference output" of Trees is the first ten integers shown here: https://github.com/microsoft/test-suite/blob/master/SingleSource/Benchmarks/... <https://github.com/microsoft/test-suite/blob/master/SingleSource/Benchmarks/Stanford/Treesort.reference_output> giving at least me the illusion that the Tree benchmark was run correctly 10 times. Now that I look more carefully this is just an illusion, because this "reference output" is reusing the global array sortlist, which is the list of unsorted integers and which is left unchanged after each run of Trees. So this is not a well chosen reference output, asserting only a correct initialization of this array. A least the number of times the procedure CheckTree is called should be reported as well. For the time being (until I have crafted my private garbage collector ;-) within Oberon System V5 I will run the Tree benchmark only once or twice at a time. Once again, thanks for your educational help and advice! -- Hans
Op 13 apr. 2020, om 21:09 heeft Joerg <joerg.straube@iaeth.ch> het volgende geschreven:
Separate module or not, is not the key question. It does not help much. As it is coded today (sort 5000 elements) Trees needs (worst case scenario) 160 kB heap space. The Oberon system having only a total amount of 1MB offers ~420 kB heap space. So, it is impossible to run the algorithm 10 times.
The garbage collector freeing up unused heap space is programmed in module Oberon but it‘s not exported. So officially, you can’t run the GC while your program runs. The allocated and now unused memory is only collected AFTER the Hennessy terminates.
With a little bit of trickery you could program your own garbage collector that frees up all data structure Trees allocated with NEW after every call of Trees. But this is a little far fetched...
br Jörg
Am 13.04.2020 um 20:36 schrieb Hans Klaver <hklaver@dds.nl>:
Ah, now I see.
So my current implementation of the Tree benchmark in Hennessy.Mod is not correct, and is 'cheating'.
Maybe I should isolate the Tree benchmark as a separate module. This is also done in the C versions of the LLVM test-suite (for all benchmarks of the suite). And I suspect that the original Pascal versions of the Hennessy benchmarks also were separate programs, but I have never seen them.
-- Hans
Op 13 apr. 2020, om 20:15 heeft Joerg <joerg.straube@iaeth.ch <mailto:joerg.straube@iaeth.ch>> het volgende geschreven:
Hans
That „Trees“ seems to run faster is because I skip the execution if there is not enough memory.
In other words, although Time() calls every algorithm 10 times, Trees will in a lot of cases only run 2 or 3 times (of those 10 calls) depending on the amount of heap space left...
br Jörg
Am 13.04.2020 um 19:47 schrieb Hans Klaver <hklaver@dds.nl <mailto:hklaver@dds.nl>>:
Hi Jörg,
Just now I noticed that my reply to your modification of Hennessy.Trees (below) did not make it to the list (possibly because I included a few screenprints of run times).
So now again:
Thanks Jörg, this modification is great! Everything runs as it should now.
Now also in Oberon System V5 Hennessy.Mod can be used with ...MOD 65536 (sic!) in procedure Rand. All reference output is as it should be.
And as a nice side effect of your modification the treesort benchmark runs nearly three times as fast as before:
Run times Hennessy Mm and Sort procedures in V5 (10 runs, ms):
MOD Trees Intmm Mm Quick Bubble Tree 65535 original 983 998 900 2016 747 65536 original 984 1016 933 2017 --
65535 modified 966 1014 876 1954 647 65536 modified 970 1016 908 1971 *259*
These are all benchmarks that make use of procedure Rand. As can be seen in most of them there is no noticable difference whether 65535 of 65536 is used in the MOD expression, but sometimes there can be a huge difference.
This is an illustration that in benchmarks it is important to consistently use the same pseudo-random generator and initial seed.
-- Hans Klaver
Op 10 apr. 2020, om 13:20 heeft Jörg <joerg.straube@iaeth.ch <mailto:joerg.straube@iaeth.ch>> het volgende geschreven:
Hans
I did the following: PROCEDURE Trees* (); VAR i : LONGINT; BEGIN IF Kernel.heapLim - Kernel.heapOrg - Kernel.allocated > 160000 THEN tInitarr(); NEW(tree); (* here the rest of Trees *) END; tree := NIL; Oberon.Collect(0) (* tell the GC to start after Hennessy terminated *) END Trees;
With these modifications you can take whatever random number generator you wanna use. DIV 65535 (wrong) or DIV 65536 (corresponds to the C original) or any other.
br Joerg
participants (4)
-
Hans Klaver -
Joerg -
Jörg -
Michael Schierl