NanoComp / meep

free finite-difference time-domain (FDTD) software for electromagnetic simulations
GNU General Public License v2.0
1.21k stars 618 forks source link

Occasional errors in `fields::process_incoming_chunk_data` from multiplying two `std::complex<realnum>` numbers #2611

Closed oskooi closed 1 year ago

oskooi commented 1 year ago

Occasionally, I detect errors in the unit test python/tests/test_refl_angular.py which is traced to line 190 of fields::process_incoming_chunk_data involving the multiplication of two complex numbers:

https://github.com/NanoComp/meep/blob/dad3e5273e92f45f66991397e05e65c821cee55a/src/step.cpp#L172-L196

The problem, I suspect, is actually in the call to reinterpret_cast which is supposed to convert const realnum to const std::complex<realnum> and then use the result in the multiplication on line 190:

https://github.com/NanoComp/meep/blob/dad3e5273e92f45f66991397e05e65c821cee55a/src/step.cpp#L182-L183

A snippet of the stack trace shows where the error is triggered:

...
on time step 103902 (time=129.877), 0.00696845 s/step
on time step 104413 (time=130.516), 0.00783793 s/step
on time step 105022 (time=131.278), 0.00657031 s/step
*** SIGTERM received by PID 1500 (TID 1500) on cpu 68 from PID 1; stack trace: ***
PC: @     0x556870995664  (unknown)  std::__u::operator*<>()
    @     0x55688065707a       1152  FailureSignalHandler()
    @     0x7f9de4deb1c0  (unknown)  (unknown)
    @     0x556870995664          8  std::__u::operator*<>()
    @     0x556870a15111        128  meep::fields::process_incoming_chunk_data()
    @     0x556870a14edd        208  meep::fields::step_boundaries()
    @     0x556870a141f1        112  meep::fields::step()
    @     0x7f9dde21fbaf         80  _wrap_fields_step()
    @     0x55688052b589         32  cfunction_call
    @     0x5568804e860d         96  _PyObject_MakeTpCall
    @     0x5568805ecbe1        112  call_function
    @     0x5568805e8866        400  _PyEval_EvalFrameDefault
    @     0x5568805e3aa4         48  _PyEval_Vector
...