Discussion:
Detect mpiexec in c++
(too old to reply)
e***@gmail.com
2008-12-01 17:11:21 UTC
Permalink
Greetings,

Is there any way to detect the presence of mpiexec/mpirun from my
program?

I have a code which needs to run both in parallel under MPI and under
a single process, not spawned from MPI. I'd like to be able to swap
out MPI-specific routines as needed. I'd like to avoid maintaining two
copies of the code or having to toggle inputs in a file if possible.

The only thing I see right now is that the command line arguments are
slightly different (at least under MPICH2) but I presume that is not
universal under every implementation.

Thanks,

Philip
Heiko Bauke
2008-12-01 18:18:15 UTC
Permalink
Hi,

On Mon, 1 Dec 2008 09:11:21 -0800 (PST)
Post by e***@gmail.com
Is there any way to detect the presence of mpiexec/mpirun from my
program?
I have a code which needs to run both in parallel under MPI and under
a single process, not spawned from MPI. I'd like to be able to swap
out MPI-specific routines as needed. I'd like to avoid maintaining two
copies of the code or having to toggle inputs in a file if possible.
there is no portable way to do this. Furthermore, in my opinion there is
no point to try to run an MPI program without mpirun. You will need the
MPI environment anyway, because you will have to link your program to
the MPI library. However, you may start your MPI program with only one
process in MPI_COMM_WORLD.


Heiko
--
-- Gegen Angriffe kann man sich wehren, gegen Lob ist man machtlos.
-- (Sigmund Freud, österr. Psychologe u. Psychater, 1856-1939)
-- Cluster Computing @ http://www.clustercomputing.de
-- Heiko Bauke @ http://www.mpi-hd.mpg.de/personalhomes/bauke
e***@gmail.com
2008-12-01 18:41:00 UTC
Permalink
Post by Heiko Bauke
Post by e***@gmail.com
I have a code which needs to run both in parallel under MPI and under
a single process, not spawned from MPI. I'd like to be able to swap
out MPI-specific routines as needed. I'd like to avoid maintaining two
copies of the code or having to toggle inputs in a file if possible.
there is no portable way to do this. Furthermore, in my opinion there is
no point to try to run an MPI program without mpirun. You will need the
MPI environment anyway, because you will have to link your program to
the MPI library. However, you may start your MPI program with only one
process in MPI_COMM_WORLD.
Heiko
Heiko,

I would have separate classes that operate in the MPI environment and
which don't operate in the MPI environment. I have this set up
already. For now, I'm using a flag in an input file to flip between
them but this can be problematic when flags don't match reality.

Consider for example a math program that can easily solve problems on
a single core of a desktop machine but scales well to solve very large
problems where a cluster is required. Furthermore consider the problem
is of a finite element nature where the equations are completely
independant and the full solution only "joins" at the solver in the
end. We can simply write an if-else-statement

if(MPI)
{
MPI_GMRES();
}
else if (...)
{
// other parallelization technique for another platform
}
else
{
Unparallelized_GMRES();
}

Or make classes/templates for a more elegant solution.

This is the problem I'm at right now. 99.9% of my code does not care
if the problem is broken up or not, just one or two pieces where the
solutions must join. So right now I flip out the parallelized and
unparallelized versions depending on the situation and the problem
size.

Yes, I could run with one MPI thread. However this does add some
overhead versus the unparallelized solver. This can be overcome with
time. Maybe this is the long-term solution but as this code is
destined for several archetectures, some where MPI is not the
parallelization solution of choice, I was trying to find a way to
simply switch between multiple parallelization options

Thanks,

Philip
Heiko Bauke
2008-12-01 19:16:45 UTC
Permalink
Hi,

On Mon, 1 Dec 2008 10:41:00 -0800 (PST)
Post by e***@gmail.com
We can simply write an if-else-statement
if(MPI)
{
MPI_GMRES();
}
else if (...)
{
// other parallelization technique for another platform
}
else
{
Unparallelized_GMRES();
}
I would suggest to switch to compile time switches:

#if MPI
MPI_GMRES();
#else
Unparallelized_GMRES();
#endif


Heiko
--
-- Jeder Mann tauscht eine Frau, die Kopfschmerzen hat, sehr gern gegen
-- eine andere, die welche verursacht. (Jerry Lewis, am. Komiker)
-- Cluster Computing @ http://www.clustercomputing.de
-- Heiko Bauke @ http://www.mpi-hd.mpg.de/personalhomes/bauke
Ilya Albrekht
2009-01-13 05:08:32 UTC
Permalink
Hi,

You may try to use Intel MPI and if you'll link your applications
static, thank you will be able to execute it as serial binary without
mpirun/mpiexec. All MPI routines will work correctly.

If your application is open source or for academic purpose, than I MPI
if free.

To separate parallel and sequential code just check number of
processes. If 1 run sequential code, if more than run parallel part.
Post by e***@gmail.com
Greetings,
Is there any way to detect the presence of mpiexec/mpirun from my
program?
I have a code which needs to run both in parallel under MPI and under
a single process, not spawned from MPI. I'd like to be able to swap
out MPI-specific routines as needed. I'd like to avoid maintaining two
copies of the code or having to toggle inputs in a file if possible.
The only thing I see right now is that the command line arguments are
slightly different (at least under MPICH2) but I presume that is not
universal under every implementation.
Thanks,
Philip
Loading...