dendibakh / perf-ninja

This is an online course where you can learn and master the skill of low-level performance analysis and tuning.
2.45k stars 208 forks source link

Questions about deps chain 2 lab #89

Closed jsjtxietian closed 2 months ago

jsjtxietian commented 2 months ago

Hi thank you for your awesome work.

In deps chain lab, IMOP the dependency chain comes from the random number generator's global state , I couldn't figure out how to eliminate this. Then I happen to glance the answer here: https://github.com/dendibakh/perf-ninja/commit/36eeee9d81551ae099046fc1399a9042b558e64f, it uses two independent random number generators to break the chain.

My question comes from that the solution uses two independent rng which would make the simulation result different from the origin solution, the validation passes because rngForValidation uses a static field: val as a global state, but the one used for benchmark:XorShift32 does not. Is this by design or am I missing something?

dendibakh commented 2 months ago

Yes, you're right. Technically, this solution is not functionally equivalent to the original program. But users would not be able to tell the difference since the motion of particles is random anyway. But of course, this method is not widely applicable.

jsjtxietian commented 2 months ago

But users would not be able to tell the difference since the motion of particles is random anyway.

I see, it makes sense.

I suppose you can clarify it in the related README ?

dendibakh commented 2 months ago

Done. https://github.com/dendibakh/perf-ninja/commit/21cf74f4cda9d151d27cdc3fe36413de868bea9a