Skip to content

Commit 8d1fdc4

Browse files
authored
Merge pull request #9770 from devreal/filter_unknown_info_v5.0.x
Drop unknown/ignored info keys on communicators, files, and windows [v5.0.x]
2 parents 1c41a07 + 500cef6 commit 8d1fdc4

File tree

8 files changed

+158
-26
lines changed

8 files changed

+158
-26
lines changed

ompi/communicator/comm.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,11 @@ int ompi_comm_split_with_info( ompi_communicator_t* comm, int color, int key,
619619
/* Activate the communicator and init coll-component */
620620
rc = ompi_comm_activate (&newcomp, comm, NULL, NULL, NULL, false, mode);
621621

622+
/* MPI-4 §7.4.4 requires us to remove all unknown keys from the info object */
623+
if (NULL != newcomp->super.s_info) {
624+
opal_info_remove_unreferenced(newcomp->super.s_info);
625+
}
626+
622627
exit:
623628
free ( results );
624629
free ( sorted );
@@ -950,6 +955,10 @@ int ompi_comm_split_type (ompi_communicator_t *comm, int split_type, int key,
950955
}
951956

952957
if (!need_split) {
958+
959+
/* MPI-4 §7.4.4 requires us to remove all unknown keys from the info object */
960+
opal_info_remove_unreferenced(newcomp->super.s_info);
961+
953962
/* common case. no reordering and no MPI_UNDEFINED */
954963
*newcomm = newcomp;
955964

@@ -1040,6 +1049,9 @@ int ompi_comm_dup_with_info ( ompi_communicator_t * comm, opal_info_t *info, omp
10401049
return rc;
10411050
}
10421051

1052+
/* MPI-4 §7.4.4 requires us to remove all unknown keys from the info object */
1053+
opal_info_remove_unreferenced(newcomp->super.s_info);
1054+
10431055
*newcomm = newcomp;
10441056
return MPI_SUCCESS;
10451057
}
@@ -1194,6 +1206,11 @@ static int ompi_comm_idup_with_info_activate (ompi_comm_request_t *request)
11941206

11951207
static int ompi_comm_idup_with_info_finish (ompi_comm_request_t *request)
11961208
{
1209+
ompi_comm_idup_with_info_context_t *context =
1210+
(ompi_comm_idup_with_info_context_t *) request->context;
1211+
/* MPI-4 §7.4.4 requires us to remove all unknown keys from the info object */
1212+
opal_info_remove_unreferenced(context->newcomp->super.s_info);
1213+
11971214
/* done */
11981215
return MPI_SUCCESS;
11991216
}

ompi/file/file.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ int ompi_file_open(struct ompi_communicator_t *comm, const char *filename,
137137
return ret;
138138
}
139139

140+
/* MPI-4 §14.2.8 requires us to remove all unknown keys from the info object */
141+
opal_info_remove_unreferenced(file->super.s_info);
142+
140143
/* All done */
141144

142145
*fh = file;

ompi/mca/common/ompio/common_ompio_file_view.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,15 +222,17 @@ int mca_common_ompio_set_view (ompio_file_t *fh,
222222

223223
opal_cstring_t *stripe_str;
224224
/* Check the info object set during File_open */
225-
opal_info_get (fh->f_info, "cb_nodes", &stripe_str, &flag);
225+
opal_info_get (info, "cb_nodes", &stripe_str, &flag);
226226
if ( flag ) {
227227
sscanf ( stripe_str->string, "%d", &num_cb_nodes );
228228
OMPIO_MCA_PRINT_INFO(fh, "cb_nodes", stripe_str->string, "");
229+
/* add the key/value to the file's info object */
230+
opal_info_set_cstring(fh->f_info, "cb_nodes", stripe_str);
229231
OBJ_RELEASE(stripe_str);
230232
}
231233
else {
232234
/* Check the info object set during file_set_view */
233-
opal_info_get (info, "cb_nodes", &stripe_str, &flag);
235+
opal_info_get (fh->f_info, "cb_nodes", &stripe_str, &flag);
234236
if ( flag ) {
235237
sscanf ( stripe_str->string, "%d", &num_cb_nodes );
236238
OMPIO_MCA_PRINT_INFO(fh, "cb_nodes", stripe_str->string, "");
@@ -325,17 +327,19 @@ int mca_common_ompio_set_view (ompio_file_t *fh,
325327
}
326328

327329
bool info_is_set=false;
328-
opal_info_get (fh->f_info, "collective_buffering", &stripe_str, &flag);
330+
opal_info_get (info, "collective_buffering", &stripe_str, &flag);
329331
if ( flag ) {
330332
if ( strncmp ( stripe_str->string, "false", sizeof("true") )){
331333
info_is_set = true;
332334
OMPIO_MCA_PRINT_INFO(fh, "collective_buffering", stripe_str->string, "enforcing using individual fcoll component");
333335
} else {
334336
OMPIO_MCA_PRINT_INFO(fh, "collective_buffering", stripe_str->string, "");
335337
}
338+
/* add the key/value to the file's info object */
339+
opal_info_set_cstring(fh->f_info, "collective_buffering", stripe_str);
336340
OBJ_RELEASE(stripe_str);
337341
} else {
338-
opal_info_get (info, "collective_buffering", &stripe_str, &flag);
342+
opal_info_get (fh->f_info, "collective_buffering", &stripe_str, &flag);
339343
if ( flag ) {
340344
if ( strncmp ( stripe_str->string, "false", sizeof("true") )){
341345
info_is_set = true;

ompi/mca/osc/base/base.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ int ompi_osc_base_select(ompi_win_t *win,
4545
size_t size,
4646
int disp_unit,
4747
ompi_communicator_t *comm,
48-
opal_info_t *info,
4948
int flavor,
5049
int *model);
5150

ompi/mca/osc/base/osc_base_init.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ ompi_osc_base_select(ompi_win_t *win,
3636
size_t size,
3737
int disp_unit,
3838
ompi_communicator_t *comm,
39-
opal_info_t *info,
4039
int flavor,
4140
int *model)
4241
{
@@ -55,7 +54,8 @@ ompi_osc_base_select(ompi_win_t *win,
5554
ompi_osc_base_component_t *component = (ompi_osc_base_component_t*)
5655
((mca_base_component_list_item_t*) item)->cli_component;
5756

58-
priority = component->osc_query(win, base, size, disp_unit, comm, info, flavor);
57+
priority = component->osc_query(win, base, size, disp_unit, comm,
58+
win->super.s_info, flavor);
5959
if (priority < 0) {
6060
if (MPI_WIN_FLAVOR_SHARED == flavor && OMPI_ERR_RMA_SHARED == priority) {
6161
/* NTH: quick fix to return OMPI_ERR_RMA_SHARED */
@@ -86,5 +86,6 @@ ompi_osc_base_select(ompi_win_t *win,
8686
"select: component %s selected",
8787
best_component->osc_version.mca_component_name );
8888

89-
return best_component->osc_select(win, base, size, disp_unit, comm, info, flavor, model);
89+
return best_component->osc_select(win, base, size, disp_unit, comm,
90+
win->super.s_info, flavor, model);
9091
}

ompi/win/win.c

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ ompi_predefined_win_t *ompi_mpi_win_null_addr = &ompi_mpi_win_null;
5252
mca_base_var_enum_t *ompi_win_accumulate_ops = NULL;
5353
mca_base_var_enum_flag_t *ompi_win_accumulate_order = NULL;
5454

55-
static mca_base_var_enum_value_t accumulate_ops_values[] = {
55+
static const mca_base_var_enum_value_t accumulate_ops_values[] = {
5656
{.value = OMPI_WIN_ACCUMULATE_OPS_SAME_OP_NO_OP, .string = "same_op_no_op",},
5757
{.value = OMPI_WIN_ACCUMULATE_OPS_SAME_OP, .string = "same_op",},
5858
{.value = -1, .string = NULL},
5959
};
6060

61-
static mca_base_var_enum_value_flag_t accumulate_order_flags[] = {
61+
static const mca_base_var_enum_value_flag_t accumulate_order_flags[] = {
6262
{.flag = OMPI_WIN_ACC_ORDER_NONE, .string = "none", .conflicting_flag = OMPI_WIN_ACC_ORDER_RAR |
6363
OMPI_WIN_ACC_ORDER_WAR | OMPI_WIN_ACC_ORDER_RAW | OMPI_WIN_ACC_ORDER_WAW},
6464
{.flag = OMPI_WIN_ACC_ORDER_RAR, .string = "rar", .conflicting_flag = OMPI_WIN_ACC_ORDER_NONE},
@@ -152,7 +152,14 @@ static int alloc_window(struct ompi_communicator_t *comm, opal_info_t *info, int
152152
return OMPI_ERR_OUT_OF_RESOURCE;
153153
}
154154

155-
ret = opal_info_get_value_enum (info, "accumulate_ops", &acc_ops,
155+
/* Copy the info for the info layer */
156+
win->super.s_info = OBJ_NEW(opal_info_t);
157+
if (info) {
158+
opal_info_dup(info, &(win->super.s_info));
159+
}
160+
161+
162+
ret = opal_info_get_value_enum (win->super.s_info, "accumulate_ops", &acc_ops,
156163
OMPI_WIN_ACCUMULATE_OPS_SAME_OP_NO_OP,
157164
ompi_win_accumulate_ops, &flag);
158165
if (OMPI_SUCCESS != ret) {
@@ -162,7 +169,7 @@ static int alloc_window(struct ompi_communicator_t *comm, opal_info_t *info, int
162169

163170
win->w_acc_ops = (ompi_win_accumulate_ops_t)acc_ops;
164171

165-
ret = opal_info_get_value_enum (info, "accumulate_order", &acc_order,
172+
ret = opal_info_get_value_enum (win->super.s_info, "accumulate_order", &acc_order,
166173
OMPI_WIN_ACC_ORDER_RAR | OMPI_WIN_ACC_ORDER_WAR |
167174
OMPI_WIN_ACC_ORDER_RAW | OMPI_WIN_ACC_ORDER_WAW,
168175
&(ompi_win_accumulate_order->super), &flag);
@@ -180,12 +187,6 @@ static int alloc_window(struct ompi_communicator_t *comm, opal_info_t *info, int
180187
OBJ_RETAIN(group);
181188
win->w_group = group;
182189

183-
/* Copy the info for the info layer */
184-
win->super.s_info = OBJ_NEW(opal_info_t);
185-
if (info) {
186-
opal_info_dup(info, &(win->super.s_info));
187-
}
188-
189190
*win_out = win;
190191

191192
return OMPI_SUCCESS;
@@ -243,7 +244,7 @@ ompi_win_create(void *base, size_t size,
243244
return ret;
244245
}
245246

246-
ret = ompi_osc_base_select(win, &base, size, disp_unit, comm, info, MPI_WIN_FLAVOR_CREATE, &model);
247+
ret = ompi_osc_base_select(win, &base, size, disp_unit, comm, MPI_WIN_FLAVOR_CREATE, &model);
247248
if (OMPI_SUCCESS != ret) {
248249
OBJ_RELEASE(win);
249250
return ret;
@@ -255,6 +256,9 @@ ompi_win_create(void *base, size_t size,
255256
return ret;
256257
}
257258

259+
/* MPI-4 §12.2.7 requires us to remove all unknown keys from the info object */
260+
opal_info_remove_unreferenced(win->super.s_info);
261+
258262
*newwin = win;
259263

260264
return OMPI_SUCCESS;
@@ -275,7 +279,7 @@ ompi_win_allocate(size_t size, int disp_unit, opal_info_t *info,
275279
return ret;
276280
}
277281

278-
ret = ompi_osc_base_select(win, &base, size, disp_unit, comm, info, MPI_WIN_FLAVOR_ALLOCATE, &model);
282+
ret = ompi_osc_base_select(win, &base, size, disp_unit, comm, MPI_WIN_FLAVOR_ALLOCATE, &model);
279283
if (OMPI_SUCCESS != ret) {
280284
OBJ_RELEASE(win);
281285
return ret;
@@ -287,6 +291,9 @@ ompi_win_allocate(size_t size, int disp_unit, opal_info_t *info,
287291
return ret;
288292
}
289293

294+
/* MPI-4 §12.2.7 requires us to remove all unknown keys from the info object */
295+
opal_info_remove_unreferenced(win->super.s_info);
296+
290297
*((void**) baseptr) = base;
291298
*newwin = win;
292299

@@ -308,7 +315,7 @@ ompi_win_allocate_shared(size_t size, int disp_unit, opal_info_t *info,
308315
return ret;
309316
}
310317

311-
ret = ompi_osc_base_select(win, &base, size, disp_unit, comm, info, MPI_WIN_FLAVOR_SHARED, &model);
318+
ret = ompi_osc_base_select(win, &base, size, disp_unit, comm, MPI_WIN_FLAVOR_SHARED, &model);
312319
if (OMPI_SUCCESS != ret) {
313320
OBJ_RELEASE(win);
314321
return ret;
@@ -320,6 +327,9 @@ ompi_win_allocate_shared(size_t size, int disp_unit, opal_info_t *info,
320327
return ret;
321328
}
322329

330+
/* MPI-4 §12.2.7 requires us to remove all unknown keys from the info object */
331+
opal_info_remove_unreferenced(win->super.s_info);
332+
323333
*((void**) baseptr) = base;
324334
*newwin = win;
325335

@@ -339,7 +349,7 @@ ompi_win_create_dynamic(opal_info_t *info, ompi_communicator_t *comm, ompi_win_t
339349
return ret;
340350
}
341351

342-
ret = ompi_osc_base_select(win, MPI_BOTTOM, 0, 1, comm, info, MPI_WIN_FLAVOR_DYNAMIC, &model);
352+
ret = ompi_osc_base_select(win, MPI_BOTTOM, 0, 1, comm, MPI_WIN_FLAVOR_DYNAMIC, &model);
343353
if (OMPI_SUCCESS != ret) {
344354
OBJ_RELEASE(win);
345355
return ret;
@@ -351,6 +361,9 @@ ompi_win_create_dynamic(opal_info_t *info, ompi_communicator_t *comm, ompi_win_t
351361
return ret;
352362
}
353363

364+
/* MPI-4 §12.2.7 requires us to remove all unknown keys from the info object */
365+
opal_info_remove_unreferenced(win->super.s_info);
366+
354367
*newwin = win;
355368

356369
return OMPI_SUCCESS;

opal/util/info.c

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static void opal_info_get_nolock(opal_info_t *info, const char *key, opal_cstrin
102102
if (NULL != value) {
103103
OBJ_RETAIN(search->ie_value);
104104
*value = search->ie_value;
105+
search->ie_referenced++;
105106
}
106107
}
107108
}
@@ -118,6 +119,7 @@ static int opal_info_set_cstring_nolock(opal_info_t *info, const char *key, opal
118119
OBJ_RELEASE(old_info->ie_value);
119120
OBJ_RETAIN(value);
120121
old_info->ie_value = value;
122+
old_info->ie_referenced++;
121123
} else {
122124
opal_info_entry_t *new_info;
123125
new_info = OBJ_NEW(opal_info_entry_t);
@@ -128,6 +130,7 @@ static int opal_info_set_cstring_nolock(opal_info_t *info, const char *key, opal
128130
new_info->ie_key = key_str;
129131
OBJ_RETAIN(value);
130132
new_info->ie_value = value;
133+
new_info->ie_referenced++;
131134
opal_list_append(&(info->super), (opal_list_item_t *) new_info);
132135
}
133136
return OPAL_SUCCESS;
@@ -143,6 +146,7 @@ static int opal_info_set_nolock(opal_info_t *info, const char *key, const char *
143146
* key already exists, check whether it is the same
144147
*/
145148
size_t value_len = strlen(value);
149+
old_info->ie_referenced++;
146150
if (old_info->ie_value->length == value_len
147151
&& 0 == strcmp(old_info->ie_value->string, value)) {
148152
return OPAL_SUCCESS;
@@ -166,6 +170,7 @@ static int opal_info_set_nolock(opal_info_t *info, const char *key, const char *
166170
OBJ_RELEASE(new_info);
167171
return OPAL_ERR_OUT_OF_RESOURCE;
168172
}
173+
new_info->ie_referenced++;
169174
opal_list_append(&(info->super), (opal_list_item_t *) new_info);
170175
}
171176
return OPAL_SUCCESS;
@@ -366,6 +371,7 @@ static void info_entry_constructor(opal_info_entry_t *entry)
366371
{
367372
entry->ie_key = NULL;
368373
entry->ie_value = NULL;
374+
entry->ie_referenced = 0;
369375
}
370376

371377
static void info_entry_destructor(opal_info_entry_t *entry)
@@ -404,3 +410,52 @@ static opal_info_entry_t *info_find_key(opal_info_t *info, const char *key)
404410
}
405411
return NULL;
406412
}
413+
414+
/**
415+
* Mark the entry \c key as referenced.
416+
*/
417+
int opal_info_mark_referenced(opal_info_t *info, const char *key)
418+
{
419+
opal_info_entry_t *entry;
420+
421+
OPAL_THREAD_LOCK(info->i_lock);
422+
entry = info_find_key(info, key);
423+
entry->ie_referenced++;
424+
OPAL_THREAD_UNLOCK(info->i_lock);
425+
426+
return OPAL_SUCCESS;
427+
}
428+
429+
/**
430+
* Remove a reference from the entry \c key.
431+
*/
432+
int opal_info_unmark_referenced(opal_info_t *info, const char *key)
433+
{
434+
opal_info_entry_t *entry;
435+
436+
OPAL_THREAD_LOCK(info->i_lock);
437+
entry = info_find_key(info, key);
438+
entry->ie_referenced--;
439+
OPAL_THREAD_UNLOCK(info->i_lock);
440+
441+
return OPAL_SUCCESS;
442+
}
443+
444+
/**
445+
* Remove any entries that are not marked as referenced
446+
*/
447+
int opal_info_remove_unreferenced(opal_info_t *info)
448+
{
449+
opal_info_entry_t *iterator, *next;
450+
/* iterate over all entries and remove the ones that are not referenced */
451+
OPAL_THREAD_LOCK(info->i_lock);
452+
OPAL_LIST_FOREACH_SAFE (iterator, next, &info->super, opal_info_entry_t) {
453+
if (!iterator->ie_referenced) {
454+
opal_list_remove_item(&info->super, &iterator->super);
455+
}
456+
}
457+
OPAL_THREAD_UNLOCK(info->i_lock);
458+
459+
460+
return OPAL_SUCCESS;
461+
}

0 commit comments

Comments
 (0)