It depends on what you are trying to do. If you intend to use this solely with OMPI 1.2.x, then you could use some of those. However, they are risky as they are in general internal to OMPI's infrastructure - and thus, subject to change from one release to another.

We do have some environmental variables that we guarantee to be "stable" across releases. You could look for OMPI_COMM_WORLD_SIZE, or OMPI_UNIVERSE_SIZE (there are a couple of others as well, but any of these would do).

However, these will only tell you that the job was launched via OMPI's mpirun - it won't tell you that it was a parallel job. It could be a serial job that just happened to be launched by mpirun. For example, we set the same environmental params when we execute "mpirun hostname" - mpirun has no way of knowing the parallel vs serial nature of the app it is launching, so it sets all the variables required by a parallel job just-in-case.

Likewise, these variables will only tell you it is a parallel job launched by OMPI. If you use another MPI (e.g., MVAPICH), none of these would be set - yet it would still be a parallel job.

So it boils down to your particular mode of operation. If you only run with OMPI, and you would only launch via OMPI's mpirun if you wanted to execute in a parallel mode, then you could look for either of those two environmental params. Otherwise, you may have to do as Doug suggests and create your own "flag".

Ralph

On Oct 20, 2008, at 4:45 PM, Doug Reeder wrote:

Brian,

In your code branch for the parallel run you could set an environment or internal variable when you call mpi_init. Can you parse the command line (arg 0) and figure out if you are running parallel or serial.

Doug Reeder
On Oct 20, 2008, at 3:40 PM, Adams, Brian M wrote:

I work on an application (DAKOTA) that has opted for single binaries with source code to detect serial vs. MPI execution at run-time.  While I realize there are many other ways to handle this (wrapper scripts, command-line switches, different binaries for serial vs. MPI, etc.), I'm looking for a reliable way to detect (in source) whether a binary has been launched in serial or with orterun.
 
We typically do this via detecting environment variables, so the easiest path for me would be to know an environment variable present when an application is invoked with orterun that is not typically present outside that MPI runtime environment.  Some candidates that came up in my particular environment include the following, but I don't know if any is a safe bet:
 
OMPI_MCA_gpr_replica_uri
OMPI_MCA_mpi_paffinity_processor
OMPI_MCA_mpi_yield_when_idle
OMPI_MCA_ns_nds
OMPI_MCA_ns_nds_cellid
OMPI_MCA_ns_nds_jobid
OMPI_MCA_ns_nds_num_procs
OMPI_MCA_ns_nds_vpid
OMPI_MCA_ns_nds_vpid_start
OMPI_MCA_ns_replica_uri
OMPI_MCA_orte_app_num
OMPI_MCA_orte_base_nodename
OMPI_MCA_orte_precondition_transports
OMPI_MCA_pls
OMPI_MCA_ras
OMPI_MCA_rds
OMPI_MCA_rmaps
OMPI_MCA_rmgr
OMPI_MCA_universe
 
I'd also welcome suggestions for other in-source tests that might reliably detect run via orterun.  Thanks!
 
Brian
----------
Brian M. Adams, PhD (briadam@sandia.gov)
Optimization and Uncertainty Estimation
Sandia National Laboratories, Albuquerque, NM
 
 
_______________________________________________
users mailing list

_______________________________________________
users mailing list
users@open-mpi.org
http://www.open-mpi.org/mailman/listinfo.cgi/users