Currently, openEMS doesn't have any special code to handle SIGINT (which
is raised by pressing Control-C). By default, the program is terminated
without saving data. This worked okay in the past, but now its
limitations are becoming obvious.
1. When openEMS is used as a Python module, Control-C stops working
because SIGINT is now managed by Python in order to generate
KeyboardInterrupt exceptions, normally this isn't a problem, but if
we are running an external C++ (Cython) function such as openEMS, the
Python interpreter mainloop has no control until we return. As a
result, SIGINT is received but never handled. In Cython, programs are
expected to call PyErr_CheckSignals() in its blocking loop periodically
to temporally transfer control back to Python to handle signals. But
this introduces a dependency of Cython in the FDTD mainloop.
2. During a simulation, it's not possible to abort it gracefully by
pressing Control-C, this is a limitation of openEMS itself, it's
always a force exit. Currently the only supported method for graceful
exit is creating a file called "ABORT" in the simulation directory.
If we already need to implement a signal handler, adding a graceful
exit at the same time would be a good idea.
This commit installs SIGINT handlers during SetupFDTD() and RunFDTD().
1. In RunFDTD(), if SIGINT is received once, a status flag is set, which
is then checked in CheckAbortCond(), allowing a graceful exit with the
same effect of an "ABORT" file. If SIGINT is received twice, openEMS
force exit without saving data (just like the old default behavior).
2. In SetupFDTD(), if SIGINT is received, openEMS immediately force
exit without saving data, identical to the old behavior. In a huge
simulation, initializing and compressing operators may have a long
time. so we want an early exit before RunFDTD().
3. Before RunFDTD() and SetupFDTD() return, the original signal handler
for SIGINT is restored. This is important since when we're acting as
a shared library. When a program (such as the Python interpreter) calls
us, changing the SIGINT handler unilaterally may overwrite the original
handler and affect the functionality of the original program. For
example, Python would never be able to raise KeyboardInterrupt again.
Thus, we save the original handler and restore it later.
Signed-off-by: Yifeng Li <tomli@tomli.me>
main.cpp:
1. Check return value of ParseFDTDSetup and exit if false
2. Use exit instead of return. These are almost identical. But
in my OpenMPI installation the process with teh highes rank
segfaults at the end when using return. This is not the case
with exit. Probably some C++ cleanup problem (destructors).
openems.cpp:
Give Parse_XML_FDTDSetup a deterministic return value.
openems_fdtd_mpi.cpp:
1. Remove the word "only" in an error message because there can
also be too many processes.
2. Fix the indexing variables for SetSplitPos in SetupMPI. Otherwise
more than one split results in an out-of-range exception and
unexpected behavior.
RunOpenEMS_MPI.m:
Apply Settings.MPI.GlobalArgs also to multi-host scenarios.
If constant cell material is activated, material probing is performed
only in the center of a primary cell.
This should improve and simplify SAR calculation if all materials
are assumed as constant within a primary YEE cell.
Usage from Matlab/Octave:
FDTD = InitFDTD('CellConstantMaterial',1);
Signed-off-by: Thorsten Liebig <Thorsten.Liebig@gmx.de>