amrex icon indicating copy to clipboard operation
amrex copied to clipboard

Add second constructor to RandomEngine for CPU

Open AlexanderSinn opened this issue 6 months ago • 3 comments

Summary

#4443 deleted the default constructor of RandomEngine for GPU. However for CPU still the default constructor must be used, forcing #ifdef to be used in code that uses the constructor. This PR adds a second constructor to the CPU version of RandomEngine to match the GPU one. Note the only use for RandomEngine on CPU is to make GPU code work on CPU.

Additional background

Checklist

The proposed changes:

  • [ ] fix a bug or incorrect behavior in AMReX
  • [ ] add new capabilities to AMReX
  • [ ] changes answers in the test suite to more than roundoff level
  • [ ] are likely to significantly affect the results of downstream AMReX users
  • [ ] include documentation in the code and/or rst files, if appropriate

AlexanderSinn avatar Jun 27 '25 00:06 AlexanderSinn

The original intention was to make it really hard for people to write this type of code.

WeiqunZhang avatar Jun 27 '25 00:06 WeiqunZhang

If one wants to avoid ifdef, one should use ParallelForRNG and then use the RandomEngine provided by the function. Of course, I understand this makes some existing Particle functions hard to use.

WeiqunZhang avatar Jun 27 '25 01:06 WeiqunZhang

One might argue that RandomEngine{nullptr} does not look right on GPU. But I also did not expect that people would have used RandomEnginre{} on GPU and expected it to work.

WeiqunZhang avatar Jun 27 '25 01:06 WeiqunZhang

I changed it so now it is getInvalidRandomEngine() to make it more clear.

AlexanderSinn avatar Jun 27 '25 15:06 AlexanderSinn