xcompact3d / x3d2

https://xcompact3d.github.io/x3d2
BSD 3-Clause "New" or "Revised" License
3 stars 4 forks source link

Single precision support for MPI messages #70

Open semi-h opened 6 months ago

semi-h commented 6 months ago

There is the compile time seleciton mechanism for the precision in the code base, however the MPI modules are currently hardcoded for MPI_DOUBLE_PRECISION. We need to figure out a way to fix this so that we can run single precision simulations.

A very incomplete attemt is here (albeit the wrong place, it should be in base backend) https://github.com/xcompact3d/x3d2/blob/85246f3b27fecee0095559029dbc4faadb7b5731/src/cuda/backend.f90#L26 Then based on the dp parameter MPI_FP_PREC can be set and used everywhere afterwards. This probably will require converting mpi_sendrecv modules into classes, so that they can be instantiated at the backends with the MPI_FP_PREC

Thanks @JamieJQuinn for pointing out this in #67.

pbartholomew08 commented 6 months ago

This is not the correct way to do it - dp = kind(0.0d0) (or something similar) will be compiler-specific, and not necessarily aligned with the MPI library. Something equivalent to

#ifdef DOUBLE_PREC
integer, parameter :: MPI_FP_PREC = MPI_DOUBLE_PRECISION
#else
integer, parameter :: MPI_FP_PREC = MPI_REAL
#endif

is what should be used (could also do with functions, but then can't make it constant)

pbartholomew08 commented 6 months ago

it might also be worth looking into MPI_F08 - this is a better module than the default MPI one, however it isn't very well supported and tends to break tools so I haven't really used it... But it is a bit better on the type safety side of things.

semi-h commented 6 months ago

Parameter is actually very simple way of implementing this, and probably most robust. I think we can go ahead with it.