-
Notifications
You must be signed in to change notification settings - Fork 641
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
enable single precision floating points for fields arrays #1544
Conversation
I modified the DFT fields to be always stored using double precision floating point. This way, it's only the precision of the time-domain fields that can be modified using the preprocessor flag. |
In order to ensure that the unit tests for the adjoint solver in Also, the API for the HDF5 routines Note that all material (ε) related quantities of the All tests are still passing when the macro |
If only for the sake of utilizing SIMD as much as possible, we should try to make every quantity in the inner loops of (Everything else, e.g. material grids, DFTs, etcetera, we can leave as |
Eventually, it would be good to be able to switch precision at runtime, by making |
Would be good to plot error vs. resolution (for a convergence test similar to the subpixel averaging papers) and reflection vs. PML thickness (similar to the PML papers), in both double and single precision. They should match, until you get to very high resolutions / long lengths where the single-precision results will become limited by roundoff errors. It would be nice to see at what point that occurs. |
The quantities of the inner loops of Also, the |
The following is a plot of the error in a resonant mode of a ring resonator vs. resolution showing the two cases of single vs. double precision. (This is the same example from the subpixel smoothing tutorial.) The two sets of results are nearly identical up to the fifth decimal digit at the largest resolution of 700. The In terms of benchmarking the runtime performance, I used the 3d OLED example which includes PMLs, DFT flux monitors, and Lorentzian susceptibilities. The timestepping rate for the single precision using 20 MPI processes was ~50% that of double precision. For consistency, the remaining functions not addressed in this PR which should also be modified to return |
…pe float and double
97c8cbb
to
3d67879
Compare
) * remove cdouble type * replace double,complex<double> with realnum,complex<realnum> * always store DFT fields using double precision floating point * fixes * store all floating point parameters of MaterialGrid as doubles * specify HDF5 read/write type format using single_precision parameter * read_chunk/write_chunk in structure_dump.cpp use correct precision * switch dft_ldos arrays to type complex<double> from complex<realnum> * convert PML arrays sig,kap,siginv to realnum from double * use single precision by default for h5file member functions write/read and related * create two versions of read_chunk/write_chunk with input arrays of type float and double * convert gyrotropic_susceptibility parameters to realnum * minor formatting fixes * update comment for single precision usage in meep.hpp
Currently, all fields arrays (time domain and DFT) are double precision floating point. However, in the past Meep used to support single precision floating point for the fields arrays for reducing memory storage and improving runtime performance (due to the reduced memory bandwidth consumption). Unfortunately, this feature had bit rotted although its artifact still exists in
src/meep.hpp
:meep/src/meep.hpp
Lines 31 to 43 in 0b460cd
This PR restores this feature by replacing numerous instances of
double
,complex<double>
withrealnum
,complex<realnum>
. Both the time-domain and the DFT fields arrays are set to therealnum
type.The PR compiles and all tests pass with
MEEP_SINGLE
set to0
insrc/meep.hpp
(the default). This just means that this PR does not break anything.When this feature is enabled, all but two of the nineteen C++ tests are passing (which is expected since some tests are comparing results against hard-coded values obtained using double precision):
This PR also causes several of the Python tests to fail:
I haven't yet performed any benchmarking to verify that this PR actually speeds up the time stepping.
Importantly, we'll need to investigate what effect reducing the floating point precision has on the adjoint solver since its unit test is failing.