Dear Siesta Developers,

I am developing this mpi genetic algorithm app to search for the optimal
configuration
of clusters of atoms. So far, serial siesta (evoked by "call system") has
been used quite
successfully as an external app to evaluate the cluster energy. I am now
testing parallel
siesta with the same purpose.

The proper way to call an mpi app from another mpi app would be through
"mpi_comm_spawn".
According to a few tests I made, this does work for parallel siesta but not
entirely. It seems
parallel siesta is not, for lack of a better term, "spawn ready" meaning
that parallel siesta should
be aware it is being called from mpi_comm_spawn and, in that case, be able
to match a call
like "call mpi_comm_disconnect(intercomm,error)" from the spawning process.
This call is
necessary to hold the spawning process until the spawnee processes are
finished and further
action can be made by the spawning process. In my case, it would be reading
the output files
from siesta.

As far as I know, all that is necessary for parallel siesta to become
"spawn ready" would be to
add something like this in the m_siesta_end module (siesta_end.F file) as
shown below:

#ifdef MPI
      use mpi_siesta, only: MPI_Finalize , mpi_comm_null
#endif

#ifdef MPI
      integer MPIerror
      integer mpi_comm_parent
#endif

! Finalize MPI
#ifdef MPI

      call mpi_comm_get_parent(mpi_comm_parent,MPIerror)

      if (mpi_comm_parent.ne.mpi_comm_null) then
          call mpi_comm_disconnect(mpi_comm_parent,MPIerror)
      endif

      call MPI_Finalize( MPIerror )

#endif

Please, note that testing the value of mpi_comm_parent as above make the
call to
mpi_comm_disconnect safe in case parallel siesta is called from "mpirun".

Well, I have applied the modifications above to the m_siesta_end module
file and the
execution of parallel siesta called from mpi_comm_spwan goes as expected.

Besides that, there is a problem with the i/o redirection shell feature
that siesta
uses to do input/output of data if it is called from mpi_comm_spawn.

I have discussed i/o redirection for spawn processes with the opempi
developers and,
at the moment (and for the foreseeable future), there seems to be no way to
specify i/o
redirection for spawnee processes, i.e., adding args like " < infile >
outfile " to
mpi_comm_spawn does not work. If I understood well, i/o redirection is
handled by the
shell of the fork processes and not by the args passed to the app mpirun
will execute
on the spawnee side...

I have tested the below modification to the m_siesta_init module
(siesta_init.F file)
and it works in case parallel siesta is called from mpi_comm_spawn:

#ifdef MPI
      use mpi_siesta, only: mpi_comm_world , mpi_comm_null
#endif

#ifdef MPI
      integer :: MPIerror  ! Return error code in MPI routines
      integer :: mpi_comm_parent
#endif

#ifdef MPI
      call MPI_Init( MPIerror )
      call MPI_Comm_Rank( MPI_Comm_World, Node, MPIerror )
      call MPI_Comm_Size( MPI_Comm_World, Nodes, MPIerror )

      call mpi_comm_get_parent(mpi_comm_parent,MPIerror)

      if (Node.eq.0.and.mpi_comm_parent.ne.mpi_comm_null) then
          open(5, file="siesta_in", action="read")
          open(6, file="siesta_out", action="write")
      endif

#endif

With the above changes, parallel siesta would read "siesta_in" file and
write "siesta_out" file
in the same way it would do if called in the traditional way like "mpirun
-n 5 siesta < siesta_in > siesta_out".

As a matter of fact, I think siesta could implement command line options
like "-i infile" and "-o outfile"
that: 1) would not interfere with i/o redirection; and 2) would make siesta
able to be called from
mpi_comm_spawn as arguments like "-i infile" and "-o outfile" can be easily
passed to mpi_comm_spawn.

May I suggest adding the above changes (or something of the sort) to
parallel siesta?
It would certainly interest other siesta users as they might use
mpi_comm_spawn as well.

Best regards and Happy New Year,

Alex A. Schmidt

Responder a