2004-01-17 23:07:40 +00:00
|
|
|
/*
|
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "lam_config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2004-03-17 18:45:16 +00:00
|
|
|
#include "constants.h"
|
|
|
|
#include "util/cmd_line.h"
|
|
|
|
#include "util/argv.h"
|
|
|
|
#include "mca/base/base.h"
|
2004-01-17 23:07:40 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private variables
|
|
|
|
*/
|
|
|
|
static int mca_param_argc = 0;
|
|
|
|
static char **mca_param_argv = NULL;
|
|
|
|
static int mca_value_argc = 0;
|
|
|
|
static char **mca_value_argv = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add -mca to the possible command line options list
|
|
|
|
*/
|
2004-01-20 23:58:51 +00:00
|
|
|
int mca_base_cmd_line_setup(lam_cmd_line_t *cmd)
|
2004-01-17 23:07:40 +00:00
|
|
|
{
|
2004-01-20 23:58:51 +00:00
|
|
|
return lam_cmd_line_make_opt(cmd, 'm', "mca", 2,
|
|
|
|
"General mechanism to pass MCA parameters");
|
2004-01-17 23:07:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Look for and handle any -mca options on the command line
|
|
|
|
*/
|
2004-01-20 23:58:51 +00:00
|
|
|
int mca_base_cmd_line_process_args(lam_cmd_line_t *cmd)
|
2004-01-17 23:07:40 +00:00
|
|
|
{
|
|
|
|
int i, num_insts;
|
|
|
|
char *buf = 0;
|
|
|
|
int buflen = 0;
|
|
|
|
|
|
|
|
/* If no "-mca" parameters were given, just return */
|
|
|
|
|
|
|
|
if (!lam_cmd_line_is_taken(cmd, "mca"))
|
|
|
|
return LAM_SUCCESS;
|
|
|
|
|
|
|
|
/* Otherwise, assemble them into an argc/argv */
|
|
|
|
|
|
|
|
num_insts = lam_cmd_line_get_ninsts(cmd, "mca");
|
|
|
|
for (i = 0; i < num_insts; ++i)
|
|
|
|
mca_base_cmd_line_process_arg(lam_cmd_line_get_param(cmd, "mca", i, 0),
|
|
|
|
lam_cmd_line_get_param(cmd, "mca", i, 1));
|
|
|
|
|
|
|
|
/* Now put that argc/argv in the environment */
|
|
|
|
|
|
|
|
if (NULL == mca_param_argv)
|
|
|
|
return LAM_SUCCESS;
|
|
|
|
|
|
|
|
/* Loop through all the -mca args that we've gotten and make env
|
|
|
|
vars of the form LAM_MPI_MCA_*=value. This is a memory leak, but
|
|
|
|
that's how putenv works. :-( */
|
|
|
|
|
|
|
|
for (i = 0; NULL != mca_param_argv[i]; ++i) {
|
|
|
|
buflen = strlen(mca_param_argv[i]) + strlen(mca_value_argv[i]) + 32;
|
2004-02-10 00:09:36 +00:00
|
|
|
buf = malloc(buflen);
|
2004-01-17 23:07:40 +00:00
|
|
|
if (NULL == buf)
|
|
|
|
return LAM_ERR_OUT_OF_RESOURCE;
|
|
|
|
|
|
|
|
snprintf(buf, buflen, "LAM_MPI_MCA_%s=%s", mca_param_argv[i],
|
|
|
|
mca_value_argv[i]);
|
|
|
|
putenv(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return LAM_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process a single MCA argument. Done as a separate function so that
|
|
|
|
* top-level applications can directly invoke this to effect MCA
|
|
|
|
* command line arguments.
|
|
|
|
*/
|
2004-01-20 23:58:51 +00:00
|
|
|
int mca_base_cmd_line_process_arg(const char *param, const char *value)
|
2004-01-17 23:07:40 +00:00
|
|
|
{
|
|
|
|
int i, len;
|
|
|
|
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 != mca_param_argv && NULL != mca_param_argv[i]; ++i) {
|
|
|
|
if (0 == strcmp(param, mca_param_argv[i])) {
|
|
|
|
len = strlen(value) + strlen(mca_param_argv[i]);
|
2004-02-10 00:09:36 +00:00
|
|
|
new_str = malloc(len);
|
2004-01-17 23:07:40 +00:00
|
|
|
snprintf(new_str, len, "%s,%s", mca_value_argv[i], value);
|
2004-02-10 00:09:36 +00:00
|
|
|
free(mca_value_argv[i]);
|
2004-01-17 23:07:40 +00:00
|
|
|
mca_value_argv[i] = new_str;
|
|
|
|
|
|
|
|
return LAM_SUCCESS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we didn't already have an value for the same param, save this
|
|
|
|
one away */
|
|
|
|
|
2004-01-20 23:58:51 +00:00
|
|
|
lam_argv_append(&mca_param_argc, &mca_param_argv, param);
|
|
|
|
lam_argv_append(&mca_value_argc, &mca_value_argv, value);
|
2004-01-17 23:07:40 +00:00
|
|
|
|
|
|
|
return LAM_SUCCESS;
|
|
|
|
}
|