@@ -45,133 +45,43 @@ static memheap_context_t* _memheap_create(void);
4545 */
4646int mca_memheap_base_select ()
4747{
48- int priority = 0 ;
49- int max_priority = 0 ;
50- mca_base_component_list_item_t * cli , * next ;
51- mca_memheap_base_component_t * component = NULL ;
52- mca_memheap_base_component_t * max_priority_component = NULL ;
53- mca_memheap_base_module_t * module = NULL ;
54- memheap_context_t * context = NULL ;
55-
56- char * * include = opal_argv_split (mca_memheap_base_include , ',' );
57- char * * exclude = opal_argv_split (mca_memheap_base_exclude , ',' );
58-
59- context = _memheap_create ();
60- if (!context ) {
61- opal_argv_free (include );
62- opal_argv_free (exclude );
48+ int best_priority ;
49+ memheap_context_t * context ;
50+ mca_memheap_base_component_t * best_component = NULL ;
51+ mca_memheap_base_module_t * best_module = NULL ;
52+
53+ if ( OPAL_SUCCESS != mca_base_select ("memheap" , oshmem_memheap_base_framework .framework_output ,
54+ & oshmem_memheap_base_framework .framework_components ,
55+ (mca_base_module_t * * ) & best_module ,
56+ (mca_base_component_t * * ) & best_component ,
57+ & best_priority ) ) {
6358 return OSHMEM_ERROR ;
6459 }
6560
66- OPAL_LIST_FOREACH_SAFE (cli , next , & oshmem_memheap_base_framework .framework_components , mca_base_component_list_item_t ) {
67- component = (mca_memheap_base_component_t * ) cli -> cli_component ;
68-
69- /* Verify if the component is in the include or the exclude list. */
70- /* If there is an include list - item must be in the list to be included */
71- if (NULL != include ) {
72- char * * argv = include ;
73- bool found = false;
74- while (argv && * argv ) {
75- if (strcmp (component -> memheap_version .mca_component_name , * argv )
76- == 0 ) {
77- found = true;
78- break ;
79- }
80- argv ++ ;
81- }
82- /* If not in the list do not choose this component */
83- if (found == false) {
84- continue ;
85- }
86-
87- /* Otherwise - check the exclude list to see if this item has been specifically excluded */
88- } else if (NULL != exclude ) {
89- char * * argv = exclude ;
90- bool found = false;
91- while (argv && * argv ) {
92- if (strcmp (component -> memheap_version .mca_component_name , * argv )
93- == 0 ) {
94- found = true;
95- break ;
96- }
97- argv ++ ;
98- }
99- if (found == true) {
100- continue ;
101- }
102- }
103-
104- /* Verify that the component has an init function */
105- if (NULL == component -> memheap_init ) {
106- MEMHEAP_VERBOSE (10 ,
107- "select: no init function; for component %s. No component selected" ,
108- component -> memheap_version .mca_component_name );
109- } else {
110-
111- MEMHEAP_VERBOSE (5 ,
112- "select: component %s size : user %d private: %d" ,
113- component -> memheap_version .mca_component_name , (int )context -> user_size , (int )context -> private_size );
114-
115- /* Init the component in order to get its priority */
116- module = component -> memheap_init (context , & priority );
117-
118- /* If the component didn't initialize, remove it from the opened list, remove it from the component repository and return an error */
119- if (NULL == module ) {
120- MEMHEAP_VERBOSE (10 ,
121- "select: init of component %s returned failure" ,
122- component -> memheap_version .mca_component_name );
123-
124- opal_list_remove_item (& oshmem_memheap_base_framework .framework_components , & cli -> super );
125- mca_base_component_close ((mca_base_component_t * ) component ,
126- oshmem_memheap_base_framework .framework_output );
127- } else {
128- /* Calculate memheap size in case it was not set during component initialization */
129- module -> memheap_size = context -> user_size ;
130- }
131- }
132-
133- /* Init max priority component */
134- if (NULL == max_priority_component ) {
135- max_priority_component = component ;
136- mca_memheap_base_module_initialized = module ;
137- max_priority = priority ;
138- }
139-
140- /* Update max priority component if current component has greater priority */
141- if (priority > max_priority ) {
142- max_priority = priority ;
143- max_priority_component = component ;
144- mca_memheap_base_module_initialized = module ;
145- }
146- }
147-
148- opal_argv_free (include );
149- opal_argv_free (exclude );
150-
151- /* Verify that a component was selected */
152- if (NULL == max_priority_component ) {
153- MEMHEAP_VERBOSE (10 , "select: no component selected" );
61+ context = _memheap_create ();
62+ if (NULL == context ) {
15463 return OSHMEM_ERROR ;
15564 }
15665
157- /* Verify that some module was initialized */
158- if (NULL == mca_memheap_base_module_initialized ) {
66+ if (OSHMEM_SUCCESS != best_component -> memheap_init (context )) {
15967 opal_show_help ("help-oshmem-memheap.txt" ,
16068 "find-available:none-found" ,
16169 true,
16270 "memheap" );
163- orte_errmgr . abort ( 1 , NULL ) ;
71+ return OSHMEM_ERROR ;
16472 }
16573
166- MEMHEAP_VERBOSE (10 ,
167- "SELECTED %s component %s" ,
168- max_priority_component -> memheap_version .mca_type_name , max_priority_component -> memheap_version .mca_component_name );
169-
74+ /* Calculate memheap size in case it was not set during component initialization */
75+ best_module -> memheap_size = context -> user_size ;
17076 setenv (SHMEM_HEAP_TYPE ,
171- max_priority_component -> memheap_version .mca_component_name ,
172- 1 );
77+ best_component -> memheap_version .mca_component_name , 1 );
17378
174- mca_memheap = * mca_memheap_base_module_initialized ;
79+ mca_memheap = * best_module ;
80+
81+ MEMHEAP_VERBOSE (10 ,
82+ "SELECTED %s component %s" ,
83+ best_component -> memheap_version .mca_type_name ,
84+ best_component -> memheap_version .mca_component_name );
17585
17686 return OSHMEM_SUCCESS ;
17787}
0 commit comments