<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
Dear all,<br>
<br>
I have put together a couple of modules that allows PWscf (and very
likely all other codes depending from <tt>check_stop.f90</tt>) to stop
cleanly after a SIGUSR1 signal is sent to the process (I picked this
particular signal, because it is unlikely to be employed by the MPI
layer and because it is it's purpose to be re-defined by the
application, if needed. I guess that in a second moment this could be
however extended to SIGTERM too, I don't have time to check that right
now).<br>
<br>
The user kills the _main_process_ (the one on the first node with the
lowest pid usually) with a<br>
<br>
<tt>kill -SIGUSR1 <pid></tt><br>
<br>
and then PWscf will stop itself as if it had found an EXIT file
(checked both serially and with MPICH, shmem and p4).<br>
<br>
Additionally, if PW is running with mpich-shmem (or in a serial
fashion), it can be killed even more easily, with a simple:<br>
<br>
<tt>killall -SIGUSR1 pw.x</tt><br>
<br>
regardless of the number of processors.<br>
<br>
The module I have inserted, also provides 2 new functions that could be
used to customize other signals too (e.g. SIGUSR2...) and doesn't
change the behavior of the EXIT file.<br>
<br>
For what concerns the compatibility, the good new is that the feature,
when enabled, should compile with any Fortran compiler compatible with
the 2003 standard (I have tested it myself with Intel, PGI, G95 and
gfortran (>=4.3 required)), the bad new, is that it employs a C
module to implement the "sigaction" function, which is (of course) 
missing in the Fortran standard.<br>
<br>
The C file can be compiled with any GCC, no matter how old (I didn't
tested other compilers, sorry).<br>
 <br>
I understand that this approach (adding a C file into the QE
distribution) might be disliked, however I'd like to point out a couple
of reasons that might mitigate the skepticism around it:<br>
<br>
<ul>
  <li>the C file doesn't require particular libraries or maintainance
(it uses a POSIX2001 standard function, and a C compiler is
automatically found by the configure anyway). In fact the file was
compiled automatically once I added it into the proper Makefile and
make.depend (due to the the implicit make rules).</li>
</ul>
<ul>
  <li>The patch can be turned on and off by just defining a
preprocessor macro (-DTRAP_SIGUSR1, however the #define has been
inserted into the code for now) and, even when activated, it should
change the application only when a SIGUSR1 is thrown at it.</li>
</ul>
<ul>
  <li>If the aforementioned TRAP_SIGUSR1 define is not set, the
modification doesn't require a Fortran 2003 compiler anymore (the
module will just warn the user that the SIGUSR1 feature is disabled).</li>
</ul>
<ul>
  <li>This approach is far cleaner and mainainable than that of
including abandoned libraries (although i can understand the
opportunity of doing so, if no alternative is available) since the code
is smaller, compiles easily and doesn't add much overall complexity.</li>
</ul>
<ul>
  <li>Imho, this step of adding some C module to Quantum ESPRESSO will
have to be taken at some point anyway.</li>
</ul>
<br>
The files are in attachment. Instead of providing a patch (witch I can
do, if you prefeer) I send a set of modified files from the yesterday
CVS snapshot (although I assume check_stop doesn't change much from one
revision to the other):<br>
<br>
for the <tt>Modules</tt> directory:<br>
<br>
<tt>customize_signals.c</tt>, <tt>customize_signals.h</tt>: C files to
change the signal trapping mask (NOTE: the object will compile in any
case)<br>
<br>
<tt>check_stop.f90</tt>: modified module to include the signal trapping
mechanism<br>
<br>
<tt>set_signal.f90</tt>: module that interfaces with the C object and
provides the signal trapping handler (NOTE: the preproc. var.
TRAP_SIGUSR1 has been enabled by default _in_the_code_)<br>
<br>
<tt>Makefile</tt>, <tt>make.depend</tt>: modified make related files
to allow for correct dependencies checking<br>
<br>
for the <tt>PW</tt> directory:<br>
<br>
<tt>Makefile.pw</tt>: Same as above (needs to be renamed to Makefile)<br>
                     <br>
I tried to provide a patched <tt>configure.ac</tt> file too, but I'm
not experienced enough with autoconf at the moment, to insert a new
option without the risk of  breaking the compilation for one or more of
the (many) compilers supported (my intention was to add an <tt>--enable-signaltrapping</tt>
option, disabled by default).<br>
<br>
Btw, I have seen that the <tt>configure.ac</tt> script and products
are nicely separated from the main QE directory (where just the
configure script lies): since this is a feature I'd really like to
employ in my software, could you please tell me what commands have been
used to create the <tt>configure</tt> script from the <tt>configure.ac</tt>
keeping the other byproducts in "<tt>install</tt>"?<br>
<br>
Cheers,<br>
Riccardo<br>
</body>
</html>