Skip to content
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

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

Closed
oskooi opened this issue Aug 17, 2023 · 0 comments · Fixed by #2612
Labels

Comments

@oskooi
Copy link
Collaborator

oskooi commented Aug 17, 2023

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:

meep/src/step.cpp

Lines 172 to 196 in dad3e52

void fields::process_incoming_chunk_data(field_type ft, const chunk_pair &comm_pair) {
am_now_working_on(Boundaries);
int this_chunk_idx = comm_pair.second;
const int pair_idx = chunk_pair_to_index(comm_pair);
const realnum *pair_comm_block = static_cast<realnum *>(comm_blocks[ft][pair_idx]);
{
const comms_key key = {ft, CONNECT_PHASE, comm_pair};
size_t num_transfers = get_comm_size(key) / 2; // Two realnums per complex
if (num_transfers) {
const std::complex<realnum> *pair_comm_block_complex =
reinterpret_cast<const std::complex<realnum> *>(pair_comm_block);
const std::vector<realnum *> &incoming_connection =
chunks[this_chunk_idx]->connections_in.at(key);
const std::vector<std::complex<realnum> > &connection_phase_for_ft =
chunks[this_chunk_idx]->connection_phases[key];
for (size_t n = 0; n < num_transfers; ++n) {
std::complex<realnum> temp = connection_phase_for_ft[n] * pair_comm_block_complex[n];
*(incoming_connection[2 * n]) = temp.real();
*(incoming_connection[2 * n + 1]) = temp.imag();
}
pair_comm_block += 2 * num_transfers;
}
}

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:

meep/src/step.cpp

Lines 182 to 183 in dad3e52

const std::complex<realnum> *pair_comm_block_complex =
reinterpret_cast<const std::complex<realnum> *>(pair_comm_block);

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
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant