3030
3131#include "opal/class/opal_pointer_array.h"
3232#include "opal/util/argv.h"
33+ #include "opal/util/opal_environ.h"
34+ #include "opal/util/os_path.h"
3335#include "opal/util/output.h"
36+ #include "opal/util/printf.h"
3437#include "opal/util/proc.h"
3538#include "opal_stdint.h"
3639
40+ #include "opal/mca/base/mca_base_vari.h"
3741#include "opal/mca/pmix/base/base.h"
3842
43+ #include "src/include/pmix_frameworks.h"
44+
3945int opal_pmix_base_exchange (pmix_info_t * indat , pmix_pdata_t * outdat , int timeout )
4046{
4147 pmix_status_t rc ;
@@ -73,6 +79,150 @@ int opal_pmix_base_exchange(pmix_info_t *indat, pmix_pdata_t *outdat, int timeou
7379 return opal_pmix_convert_status (rc );
7480}
7581
82+ static bool check_pmix_param (char * param )
83+ {
84+ char * p ;
85+ size_t n ;
86+ int len ;
87+
88+ p = strchr (param , '_' );
89+ len = (int )(p - param );
90+
91+ if (0 == strncmp (param , "pmix" , len )) {
92+ return true;
93+ }
94+ for (n = 0 ; NULL != pmix_framework_names [n ]; n ++ ) {
95+ if (0 == strncmp (param , pmix_framework_names [n ], len )) {
96+ return true;
97+ }
98+ }
99+ return false;
100+ }
101+
102+ static bool check_pmix_overlap (char * var , char * value )
103+ {
104+ char * tmp ;
105+
106+ if (0 == strncmp (var , "dl_" , 3 )) {
107+ opal_asprintf (& tmp , "PMIX_MCA_pdl_%s" , & var [3 ]);
108+ // set it, but don't overwrite if they already
109+ // have a value in our environment
110+ setenv (tmp , value , false);
111+ free (tmp );
112+ return true;
113+ } else if (0 == strncmp (var , "oob_" , 4 )) {
114+ opal_asprintf (& tmp , "PMIX_MCA_ptl_%s" , & var [4 ]);
115+ // set it, but don't overwrite if they already
116+ // have a value in our environment
117+ setenv (tmp , value , false);
118+ free (tmp );
119+ return true;
120+ } else if (0 == strncmp (var , "hwloc_" , 6 )) {
121+ opal_asprintf (& tmp , "PMIX_MCA_%s" , var );
122+ // set it, but don't overwrite if they already
123+ // have a value in our environment
124+ setenv (tmp , value , false);
125+ free (tmp );
126+ return true;
127+ } else if (0 == strncmp (var , "if_" , 3 )) {
128+ // need to convert if to pif
129+ opal_asprintf (& tmp , "PMIX_MCA_pif_%s" , & var [3 ]);
130+ // set it, but don't overwrite if they already
131+ // have a value in our environment
132+ setenv (tmp , value , false);
133+ free (tmp );
134+ return true;
135+ }
136+ return false;
137+ }
138+
139+ // NOTE: This code is fundamentally the same (module PMIX <-> OPAL)
140+ // as the translate_params() routine in the PRRTE repo's
141+ // src/mca/schizo/ompi/schizo_ompi.c file. If there are
142+ // changes here, there are likely to be changes there.
143+ static void translate_params (void )
144+ {
145+ char * evar , * tmp , * e2 ;
146+ char * file ;
147+ const char * home ;
148+ opal_list_t params ;
149+ mca_base_var_file_value_t * fv ;
150+ bool pmix_overlap ;
151+ int n , len ;
152+
153+ /* Since we are direct launched, we need to check the OMPI default
154+ * MCA params to see if there is something relating to PRRTE
155+ * in them - this would be "old" references to things from
156+ * ORTE, as well as a few OPAL references that also impact us
157+ *
158+ * NOTE: we do this in the following precedence order. Note
159+ * that we do not overwrite at any step - this is so that we
160+ * don't overwrite something previously set by the user. So
161+ * the order to execution is the opposite of the intended
162+ * precedence order.
163+ *
164+ * 1. check the environmental paramaters for OMPI_MCA values
165+ * that need to be translated
166+ *
167+ * 2. the user's home directory file as it should
168+ * overwrite the system default file, but not the
169+ * envars
170+ *
171+ * 3. the system default parameter file
172+ */
173+ len = strlen ("OMPI_MCA_" );
174+ for (n = 0 ; NULL != environ [n ]; n ++ ) {
175+ if (0 == strncmp (environ [n ], "OMPI_MCA_" , len )) {
176+ e2 = strdup (environ [n ]);
177+ evar = strrchr (e2 , '=' );
178+ * evar = '\0' ;
179+ ++ evar ;
180+ pmix_overlap = check_pmix_overlap (& e2 [len ], evar );
181+ if (!pmix_overlap && check_pmix_param (& e2 [len ])) {
182+ opal_asprintf (& tmp , "PMIX_MCA_%s" , & e2 [len ]);
183+ // set it, but don't overwrite if they already
184+ // have a value in our environment
185+ setenv (tmp , evar , false);
186+ free (tmp );
187+ }
188+ free (e2 );
189+ }
190+ }
191+
192+ /* try to get user's home directory */
193+ home = opal_home_directory ();
194+ if (NULL != home ) {
195+ file = opal_os_path (false, home , ".openmpi" , "mca-params.conf" , NULL );
196+ OBJ_CONSTRUCT (& params , opal_list_t );
197+ mca_base_parse_paramfile (file , & params );
198+ free (file );
199+ OPAL_LIST_FOREACH (fv , & params , mca_base_var_file_value_t ) {
200+ pmix_overlap = check_pmix_overlap (& e2 [len ], evar );
201+ if (!pmix_overlap && check_pmix_param (fv -> mbvfv_var )) {
202+ opal_asprintf (& tmp , "PMIX_MCA_%s" , fv -> mbvfv_var );
203+ // set it, but don't overwrite if they already
204+ // have a value in our environment
205+ setenv (tmp , fv -> mbvfv_value , false);
206+ free (tmp );
207+ }
208+ }
209+ OPAL_LIST_DESTRUCT (& params );
210+ }
211+
212+ /* check if the user has set OMPIHOME in their environment */
213+ if (NULL != (evar = getenv ("OMPIHOME" ))) {
214+ /* look for the default MCA param file */
215+ file = opal_os_path (false, evar , "etc" , "openmpi-mca-params.conf" , NULL );
216+ OBJ_CONSTRUCT (& params , opal_list_t );
217+ mca_base_parse_paramfile (file , & params );
218+ free (file );
219+ OPAL_LIST_FOREACH (fv , & params , mca_base_var_file_value_t ) {
220+ check_pmix_overlap (fv -> mbvfv_var , fv -> mbvfv_value );
221+ }
222+ OPAL_LIST_DESTRUCT (& params );
223+ }
224+ }
225+
76226typedef struct {
77227 opal_list_item_t super ;
78228 pmix_nspace_t nspace ;
@@ -85,8 +235,13 @@ static opal_list_t localnspaces;
85235void opal_pmix_setup_nspace_tracker (void )
86236{
87237 /* check if we were launched by PRRTE */
88- if (NULL != getenv ("PRRTE_LAUNCHED " )) {
238+ if (NULL != getenv ("PRTE_LAUNCHED " )) {
89239 opal_process_info .nativelaunch = true;
240+ } else {
241+ // When direct launched, translate MCA parameters from older releases
242+ // into newer versions here, since PRRTE isn't involved. (When
243+ // natively launched, PRRTE will already have translated the params)
244+ translate_params ();
90245 }
91246
92247 OBJ_CONSTRUCT (& localnspaces , opal_list_t );
0 commit comments