2004-01-18 02:07:40 +03:00
/*
2005-11-05 22:57:48 +03:00
* Copyright ( c ) 2004 - 2005 The Trustees of Indiana University and Indiana
* University Research and Technology
* Corporation . All rights reserved .
* Copyright ( c ) 2004 - 2005 The University of Tennessee and The University
* of Tennessee Research Foundation . All rights
* reserved .
2004-11-28 23:09:25 +03:00
* Copyright ( c ) 2004 - 2005 High Performance Computing Center Stuttgart ,
* University of Stuttgart . All rights reserved .
2005-03-24 15:43:37 +03:00
* Copyright ( c ) 2004 - 2005 The Regents of the University of California .
* All rights reserved .
2004-11-22 04:38:40 +03:00
* $ COPYRIGHT $
*
* Additional copyrights may follow
*
2004-01-18 02:07:40 +03:00
* $ HEADER $
*/
2006-02-12 04:33:29 +03:00
# include "opal_config.h"
2004-01-18 02:07:40 +03:00
# include <stdio.h>
# include <string.h>
2005-07-04 04:13:44 +04:00
# include "opal/util/cmd_line.h"
# include "opal/util/argv.h"
2005-07-04 05:36:20 +04:00
# include "opal/util/opal_environ.h"
2005-08-13 00:46:25 +04:00
# include "opal/mca/base/base.h"
2006-02-12 04:33:29 +03:00
# include "opal/constants.h"
2004-01-18 02:07:40 +03:00
/*
* Private variables
*/
2005-08-08 20:42:28 +04:00
/*
* Private functions
*/
static int process_arg ( const char * param , const char * value ,
char * * * params , char * * * values ) ;
static void add_to_env ( char * * params , char * * values , char * * * env ) ;
2004-01-18 02:07:40 +03:00
/*
* Add - mca to the possible command line options list
*/
2005-07-04 04:13:44 +04:00
int mca_base_cmd_line_setup ( opal_cmd_line_t * cmd )
2004-01-18 02:07:40 +03:00
{
2007-03-01 16:39:20 +03:00
int ret = OPAL_SUCCESS ;
2005-08-08 20:42:28 +04:00
ret = opal_cmd_line_make_opt3 ( cmd , ' \0 ' , " mca " , " mca " , 2 ,
" Pass context-specific MCA parameters; they are considered global if --gmca is not used and only one context is specified (arg0 is the parameter name; arg1 is the parameter value) " ) ;
2006-02-12 04:33:29 +03:00
if ( OPAL_SUCCESS ! = ret ) {
2005-08-08 20:42:28 +04:00
return ret ;
}
ret = opal_cmd_line_make_opt3 ( cmd , ' \0 ' , " gmca " , " gmca " , 2 ,
" Pass global MCA parameters that are applicable to all contexts (arg0 is the parameter name; arg1 is the parameter value) " ) ;
2007-03-01 16:39:20 +03:00
if ( OPAL_SUCCESS ! = ret ) {
return ret ;
}
{
opal_cmd_line_init_t entry =
2012-10-30 23:45:18 +04:00
{ " mca_base_param_file_prefix " , ' \0 ' , " am " , NULL , 1 ,
2007-03-01 16:39:20 +03:00
NULL , OPAL_CMD_LINE_TYPE_STRING ,
" Aggregate MCA parameter set file list "
} ;
ret = opal_cmd_line_make_opt_mca ( cmd , entry ) ;
if ( OPAL_SUCCESS ! = ret ) {
return ret ;
}
}
2005-08-08 20:42:28 +04:00
return ret ;
2004-01-18 02:07:40 +03:00
}
/*
* Look for and handle any - mca options on the command line
*/
2005-07-04 04:13:44 +04:00
int mca_base_cmd_line_process_args ( opal_cmd_line_t * cmd ,
2005-08-08 20:42:28 +04:00
char * * * context_env , char * * * global_env )
2004-01-18 02:07:40 +03:00
{
int i , num_insts ;
2005-08-08 20:42:28 +04:00
char * * params ;
char * * values ;
While waiting for fortran compiles...
Fixes for orterun in handling different MCA params for different
processes (reviewed by Brian):
- By design, if you run the following:
mpirun --mca foo aaa --mca foo bbb a.out
a.out will get a single MCA param for foo with value "aaa,bbb".
- However, if you specify multiple apps with different values for the
same MCA param, you should expect to get the different values for
each app. For example:
mpirun --mca foo aaa a.out : --mca foo bbb b.out
Should yield a.out with a "foo" param with value "aaa" and b.out
with a "foo" param with a value "bbb".
- This did not work -- both a.out and b.out would get a "foo" with
"aaa,bbb".
- This commit fixes this behavior -- now a.out will get aaa and b.out
will get bbb.
- Additionally, if you mix --mca and and app file, you can have
"global" params and per-line-in-the-appfile params. For example:
mpirun --mca foo zzzz --app appfile
where "appfile" contains:
-np 1 --mca bar aaa a.out
-np 1 --mca bar bbb b.out
In this case, a.out will get foo=zzzz and bar=aaa, and b.out will
get foo=zzzz and bar=bbb.
Spiffy.
Ok, fortran build is done... back to Fortran... sigh...
This commit was SVN r5710.
2005-05-13 18:36:36 +04:00
2005-08-08 20:42:28 +04:00
/* If no relevant parameters were given, just return */
2004-01-18 02:07:40 +03:00
2005-08-08 20:42:28 +04:00
if ( ! opal_cmd_line_is_taken ( cmd , " mca " ) & &
! opal_cmd_line_is_taken ( cmd , " gmca " ) ) {
2006-02-12 04:33:29 +03:00
return OPAL_SUCCESS ;
2005-03-18 06:43:59 +03:00
}
2004-01-18 02:07:40 +03:00
2005-08-08 20:42:28 +04:00
/* Handle app context-specific parameters */
2004-01-18 02:07:40 +03:00
2005-07-04 04:13:44 +04:00
num_insts = opal_cmd_line_get_ninsts ( cmd , " mca " ) ;
2005-08-08 20:42:28 +04:00
params = values = NULL ;
2005-03-18 06:43:59 +03:00
for ( i = 0 ; i < num_insts ; + + i ) {
2005-08-08 20:42:28 +04:00
process_arg ( opal_cmd_line_get_param ( cmd , " mca " , i , 0 ) ,
opal_cmd_line_get_param ( cmd , " mca " , i , 1 ) ,
& params , & values ) ;
2005-03-18 06:43:59 +03:00
}
2005-08-08 20:42:28 +04:00
if ( NULL ! = params ) {
add_to_env ( params , values , context_env ) ;
opal_argv_free ( params ) ;
opal_argv_free ( values ) ;
2005-03-18 06:43:59 +03:00
}
2004-01-18 02:07:40 +03:00
2005-08-08 20:42:28 +04:00
/* Handle global parameters */
2004-01-18 02:07:40 +03:00
2005-08-08 20:42:28 +04:00
num_insts = opal_cmd_line_get_ninsts ( cmd , " gmca " ) ;
params = values = NULL ;
for ( i = 0 ; i < num_insts ; + + i ) {
process_arg ( opal_cmd_line_get_param ( cmd , " gmca " , i , 0 ) ,
opal_cmd_line_get_param ( cmd , " gmca " , i , 1 ) ,
& params , & values ) ;
}
if ( NULL ! = params ) {
add_to_env ( params , values , global_env ) ;
opal_argv_free ( params ) ;
opal_argv_free ( values ) ;
2004-01-18 02:07:40 +03:00
}
2005-08-08 20:42:28 +04:00
/* All done */
2006-02-12 04:33:29 +03:00
return OPAL_SUCCESS ;
2004-01-18 02:07:40 +03:00
}
/*
2005-08-08 20:42:28 +04:00
* Process a single MCA argument .
2004-01-18 02:07:40 +03:00
*/
2007-02-16 21:17:50 +03:00
static int process_arg ( const char * param , const char * value ,
2005-08-08 20:42:28 +04:00
char * * * params , char * * * values )
2004-01-18 02:07:40 +03:00
{
2005-08-08 20:42:28 +04:00
int i ;
char * new_str ;
/* Look to see if we've already got an -mca argument for the same
param . Check against the list of MCA param ' s that we ' ve
already saved arguments for . */
for ( i = 0 ; NULL ! = * params & & NULL ! = ( * params ) [ i ] ; + + i ) {
if ( 0 = = strcmp ( param , ( * params ) [ i ] ) ) {
asprintf ( & new_str , " %s,%s " , ( * values ) [ i ] , value ) ;
free ( ( * values ) [ i ] ) ;
( * values ) [ i ] = new_str ;
2006-02-12 04:33:29 +03:00
return OPAL_SUCCESS ;
2005-08-08 20:42:28 +04:00
}
}
2004-01-18 02:07:40 +03:00
2005-08-08 20:42:28 +04:00
/* If we didn't already have an value for the same param, save
this one away */
opal_argv_append_nosize ( params , param ) ;
opal_argv_append_nosize ( values , value ) ;
2004-01-18 02:07:40 +03:00
2006-02-12 04:33:29 +03:00
return OPAL_SUCCESS ;
2005-08-08 20:42:28 +04:00
}
2004-01-18 02:07:40 +03:00
2005-08-08 20:42:28 +04:00
static void add_to_env ( char * * params , char * * values , char * * * env )
{
int i ;
char * name ;
2004-01-18 02:07:40 +03:00
2005-08-08 20:42:28 +04:00
/* Loop through all the args that we've gotten and make env
vars of the form OMPI_MCA_ * = value . */
for ( i = 0 ; NULL ! = params & & NULL ! = params [ i ] ; + + i ) {
2013-03-28 01:09:41 +04:00
( void ) mca_base_var_env_name ( params [ i ] , & name ) ;
2005-08-08 20:42:28 +04:00
opal_setenv ( name , values [ i ] , true , env ) ;
free ( name ) ;
}
2004-01-18 02:07:40 +03:00
}