Skip to content

Commit 158e54c

Browse files
devrealbosilca
authored andcommitted
Fix the info subscriber mechanism and hidden info keys
Signed-off-by: Joseph Schuchart <[email protected]>
1 parent ce3742c commit 158e54c

File tree

10 files changed

+72
-126
lines changed

10 files changed

+72
-126
lines changed

ompi/communicator/comm.c

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

710-
/* MPI-4 §7.4.4 requires us to remove all unknown keys from the info object */
711-
if (NULL != newcomp->super.s_info) {
712-
opal_info_remove_unreferenced(newcomp->super.s_info);
713-
}
714-
715710
exit:
716711
free ( results );
717712
free ( sorted );
@@ -1028,9 +1023,6 @@ static int ompi_comm_split_type_core(ompi_communicator_t *comm,
10281023
goto exit;
10291024
}
10301025

1031-
/* MPI-4 §7.4.4 requires us to remove all unknown keys from the info object */
1032-
opal_info_remove_unreferenced(newcomp->super.s_info);
1033-
10341026
/* TODO: there probably is better way to handle this case without throwing away the
10351027
* intermediate communicator. */
10361028
rc = ompi_comm_split (newcomp, local_split_type, key, newcomm, false);
@@ -1363,9 +1355,6 @@ int ompi_comm_dup_with_info ( ompi_communicator_t * comm, opal_info_t *info, omp
13631355
return rc;
13641356
}
13651357

1366-
/* MPI-4 §7.4.4 requires us to remove all unknown keys from the info object */
1367-
opal_info_remove_unreferenced(newcomp->super.s_info);
1368-
13691358
*newcomm = newcomp;
13701359
return MPI_SUCCESS;
13711360
}
@@ -1522,8 +1511,6 @@ static int ompi_comm_idup_with_info_finish (ompi_comm_request_t *request)
15221511
{
15231512
ompi_comm_idup_with_info_context_t *context =
15241513
(ompi_comm_idup_with_info_context_t *) request->context;
1525-
/* MPI-4 §7.4.4 requires us to remove all unknown keys from the info object */
1526-
opal_info_remove_unreferenced(context->newcomp->super.s_info);
15271514

15281515
/* done */
15291516
return MPI_SUCCESS;

ompi/file/file.c

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

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

146143
*fh = file;

ompi/info/info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ int ompi_mpiinfo_init_env(int argc, char *argv[], ompi_info_t *info)
243243
// related calls:
244244

245245
int ompi_info_dup (ompi_info_t *info, ompi_info_t **newinfo) {
246-
return opal_info_dup (&(info->super), (opal_info_t **)newinfo);
246+
return opal_info_dup_public (&(info->super), (opal_info_t **)newinfo);
247247
}
248248
int ompi_info_set (ompi_info_t *info, const char *key, const char *value) {
249249
return opal_info_set (&(info->super), key, value);

ompi/mpi/c/comm_get_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int MPI_Comm_get_info(MPI_Comm comm, MPI_Info *info_used)
6161

6262
opal_info_t *opal_info_used = &(*info_used)->super;
6363

64-
opal_info_dup(comm->super.s_info, &opal_info_used);
64+
opal_info_dup_public(comm->super.s_info, &opal_info_used);
6565

6666
return MPI_SUCCESS;
6767
}

ompi/mpi/c/file_get_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ int MPI_File_get_info(MPI_File fh, MPI_Info *info_used)
8686
}
8787
opal_info_t *opal_info_used = &(*info_used)->super;
8888

89-
opal_info_dup(fh->super.s_info, &opal_info_used);
89+
opal_info_dup_public(fh->super.s_info, &opal_info_used);
9090

9191
return OMPI_SUCCESS;
9292
}

ompi/mpi/c/win_get_info.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ int MPI_Win_get_info(MPI_Win win, MPI_Info *info_used)
6060
}
6161
opal_info_t *opal_info_used = &(*info_used)->super;
6262

63-
ret = opal_info_dup(win->super.s_info, &opal_info_used);
63+
ret = opal_info_dup_public(win->super.s_info, &opal_info_used);
6464

6565
OMPI_ERRHANDLER_RETURN(ret, win, ret, FUNC_NAME);
6666
}

ompi/win/win.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,6 @@ ompi_win_create(void *base, size_t size,
266266
return ret;
267267
}
268268

269-
/* MPI-4 §12.2.7 requires us to remove all unknown keys from the info object */
270-
opal_info_remove_unreferenced(win->super.s_info);
271-
272269
*newwin = win;
273270

274271
return OMPI_SUCCESS;
@@ -300,9 +297,6 @@ ompi_win_allocate(size_t size, int disp_unit, opal_info_t *info,
300297
return ret;
301298
}
302299

303-
/* MPI-4 §12.2.7 requires us to remove all unknown keys from the info object */
304-
opal_info_remove_unreferenced(win->super.s_info);
305-
306300
*((void**) baseptr) = base;
307301
*newwin = win;
308302

@@ -335,9 +329,6 @@ ompi_win_allocate_shared(size_t size, int disp_unit, opal_info_t *info,
335329
return ret;
336330
}
337331

338-
/* MPI-4 §12.2.7 requires us to remove all unknown keys from the info object */
339-
opal_info_remove_unreferenced(win->super.s_info);
340-
341332
*((void**) baseptr) = base;
342333
*newwin = win;
343334

@@ -368,9 +359,6 @@ ompi_win_create_dynamic(opal_info_t *info, ompi_communicator_t *comm, ompi_win_t
368359
return ret;
369360
}
370361

371-
/* MPI-4 §12.2.7 requires us to remove all unknown keys from the info object */
372-
opal_info_remove_unreferenced(win->super.s_info);
373-
374362
*newwin = win;
375363

376364
return OMPI_SUCCESS;

opal/util/info.c

Lines changed: 34 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,18 @@ OBJ_CLASS_INSTANCE(opal_info_entry_t, opal_list_item_t, info_entry_constructor,
6565
info_entry_destructor);
6666

6767
/*
68-
* Duplicate an info
68+
* Duplicate an info into newinfo. If public_info is true we only duplicate
69+
* key-value pairs that are not internal and that had been referenced,
70+
* either through opal_info_get or opal_info_set.
6971
*/
70-
int opal_info_dup(opal_info_t *info, opal_info_t **newinfo)
72+
static int opal_info_dup_impl(opal_info_t *info, opal_info_t **newinfo, bool public_only)
7173
{
7274
opal_info_entry_t *iterator;
7375

7476
OPAL_THREAD_LOCK(info->i_lock);
7577
OPAL_LIST_FOREACH (iterator, &info->super, opal_info_entry_t) {
78+
/* skip keys that are internal if we didn't ask for them */
79+
if (public_only && (iterator->ie_internal || iterator->ie_referenced == 0)) continue;
7680
/* create a new info entry and retain the string objects */
7781
opal_info_entry_t *newentry = OBJ_NEW(opal_info_entry_t);
7882
newentry->ie_key = iterator->ie_key;
@@ -85,6 +89,16 @@ int opal_info_dup(opal_info_t *info, opal_info_t **newinfo)
8589
return OPAL_SUCCESS;
8690
}
8791

92+
int opal_info_dup_public(opal_info_t *info, opal_info_t **newinfo)
93+
{
94+
return opal_info_dup_impl(info, newinfo, true);
95+
}
96+
97+
int opal_info_dup(opal_info_t *info, opal_info_t **newinfo)
98+
{
99+
return opal_info_dup_impl(info, newinfo, false);
100+
}
101+
88102
static void opal_info_get_nolock(opal_info_t *info, const char *key, opal_cstring_t **value,
89103
int *flag)
90104
{
@@ -136,7 +150,7 @@ static int opal_info_set_cstring_nolock(opal_info_t *info, const char *key, opal
136150
return OPAL_SUCCESS;
137151
}
138152

139-
static int opal_info_set_nolock(opal_info_t *info, const char *key, const char *value)
153+
static int opal_info_set_nolock(opal_info_t *info, const char *key, const char *value, bool internal)
140154
{
141155
opal_info_entry_t *old_info;
142156

@@ -147,6 +161,7 @@ static int opal_info_set_nolock(opal_info_t *info, const char *key, const char *
147161
*/
148162
size_t value_len = strlen(value);
149163
old_info->ie_referenced++;
164+
old_info->ie_internal = internal;
150165
if (old_info->ie_value->length == value_len
151166
&& 0 == strcmp(old_info->ie_value->string, value)) {
152167
return OPAL_SUCCESS;
@@ -171,6 +186,7 @@ static int opal_info_set_nolock(opal_info_t *info, const char *key, const char *
171186
return OPAL_ERR_OUT_OF_RESOURCE;
172187
}
173188
new_info->ie_referenced++;
189+
new_info->ie_internal = internal;
174190
opal_list_append(&(info->super), (opal_list_item_t *) new_info);
175191
}
176192
return OPAL_SUCCESS;
@@ -184,7 +200,20 @@ int opal_info_set(opal_info_t *info, const char *key, const char *value)
184200
int ret;
185201

186202
OPAL_THREAD_LOCK(info->i_lock);
187-
ret = opal_info_set_nolock(info, key, value);
203+
ret = opal_info_set_nolock(info, key, value, false);
204+
OPAL_THREAD_UNLOCK(info->i_lock);
205+
return ret;
206+
}
207+
208+
/*
209+
* Set a value on the info
210+
*/
211+
int opal_info_set_internal(opal_info_t *info, const char *key, const char *value)
212+
{
213+
int ret;
214+
215+
OPAL_THREAD_LOCK(info->i_lock);
216+
ret = opal_info_set_nolock(info, key, value, true);
188217
OPAL_THREAD_UNLOCK(info->i_lock);
189218
return ret;
190219
}
@@ -372,6 +401,7 @@ static void info_entry_constructor(opal_info_entry_t *entry)
372401
entry->ie_key = NULL;
373402
entry->ie_value = NULL;
374403
entry->ie_referenced = 0;
404+
entry->ie_internal = false;
375405
}
376406

377407
static void info_entry_destructor(opal_info_entry_t *entry)
@@ -410,52 +440,3 @@ static opal_info_entry_t *info_find_key(opal_info_t *info, const char *key)
410440
}
411441
return NULL;
412442
}
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-
}

opal/util/info.h

Lines changed: 30 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct opal_info_entry_t {
6767
opal_cstring_t *ie_key; /**< "key" part of the (key, value) pair */
6868
uint32_t ie_referenced; /**< number of times this entry was internally
6969
referenced */
70+
bool ie_internal; /**< internal keys are not handed back to the user */
7071
};
7172

7273
/**
@@ -90,7 +91,23 @@ OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_info_t);
9091
OPAL_DECLSPEC OBJ_CLASS_DECLARATION(opal_info_entry_t);
9192

9293
/**
93-
* opal_info_dup - Duplicate an 'MPI_Info' object
94+
* opal_info_dup - Duplicate public keys of an 'MPI_Info' object
95+
*
96+
* @param info source info object (handle)
97+
* @param newinfo pointer to the new info object (handle)
98+
*
99+
* @retval OPAL_SUCCESS upon success
100+
* @retval OPAL_ERR_OUT_OF_RESOURCE if out of memory
101+
*
102+
* Not only will the (key, value) pairs be duplicated, the order
103+
* of keys will be the same in 'newinfo' as it is in 'info'. When
104+
* an info object is no longer being used, it should be freed with
105+
* \c opal_info_free.
106+
*/
107+
int opal_info_dup_public(opal_info_t *info, opal_info_t **newinfo);
108+
109+
/**
110+
* opal_info_dup - Duplicate all entries of an 'MPI_Info' object
94111
*
95112
* @param info source info object (handle)
96113
* @param newinfo pointer to the new info object (handle)
@@ -117,6 +134,18 @@ int opal_info_dup(opal_info_t *info, opal_info_t **newinfo);
117134
*/
118135
OPAL_DECLSPEC int opal_info_set(opal_info_t *info, const char *key, const char *value);
119136

137+
/**
138+
* Set a new key,value pair on info and mark it as internal.
139+
*
140+
* @param info pointer to opal_info_t object
141+
* @param key pointer to the new key object
142+
* @param value pointer to the new value object
143+
*
144+
* @retval OPAL_SUCCESS upon success
145+
* @retval OPAL_ERR_OUT_OF_RESOURCE if out of memory
146+
*/
147+
OPAL_DECLSPEC int opal_info_set_internal(opal_info_t *info, const char *key, const char *value);
148+
120149
/**
121150
* Set a new key,value pair on info.
122151
*
@@ -287,43 +316,6 @@ static inline int opal_info_get_nkeys(opal_info_t *info, int *nkeys)
287316
return OPAL_SUCCESS;
288317
}
289318

290-
291-
/**
292-
* Mark the entry \c key as referenced.
293-
*
294-
* This function is useful for lazily initialized components
295-
* that do not read the key immediately but want to make sure
296-
* the key is kept by the object owning the info key.
297-
*
298-
* @param info Pointer to opal_info_t object.
299-
* @param key The key which to mark as referenced.
300-
*
301-
* @retval OPAL_SUCCESS
302-
*/
303-
int opal_info_mark_referenced(opal_info_t *info, const char *key);
304-
305-
/**
306-
* Remove a reference from the entry \c key.
307-
*
308-
* This function should be used by components reading the key
309-
* without wanting to retain it in the object owning the info.
310-
*
311-
* @param info Pointer to opal_info_t object.
312-
* @param key The key which to unmark as referenced.
313-
*
314-
* @retval OPAL_SUCCESS
315-
*/
316-
int opal_info_unmark_referenced(opal_info_t *info, const char *key);
317-
318-
/**
319-
* Remove any entries that are not marked as referenced
320-
*
321-
* @param info Pointer to opal_info_t object.
322-
*
323-
* @retval OPAL_SUCCESS
324-
*/
325-
int opal_info_remove_unreferenced(opal_info_t *info);
326-
327319
END_C_DECLS
328320

329321
#endif /* OPAL_INFO_H */

opal/util/info_subscriber.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,10 @@ int opal_infosubscribe_change_info(opal_infosubscriber_t *object, opal_info_t *n
269269
updated_value = opal_infosubscribe_inform_subscribers(object, iterator->ie_key->string,
270270
iterator->ie_value->string,
271271
&found_callback);
272-
if (NULL != updated_value
273-
&& 0 != strncmp(updated_value, value_str->string, value_str->length)) {
274-
err = opal_info_set(object->s_info, iterator->ie_key->string, updated_value);
272+
if (NULL != updated_value) {
273+
err = opal_info_set(object->s_info, key_str->string, updated_value);
274+
} else {
275+
err = opal_info_set_internal(object->s_info, key_str->string, value_str->string);
275276
}
276277
OBJ_RELEASE(value_str);
277278
OBJ_RELEASE(key_str);

0 commit comments

Comments
 (0)