pmix-standard icon indicating copy to clipboard operation
pmix-standard copied to clipboard

Provide a code example for the info list

Open abouteiller opened this issue 1 year ago • 0 comments

While working on #492, we thought that adding an example on how to use lists could be valuable.

@rhc54 proposed the following example

           I believe you asked me to provide a code example for the info list - here is a typical usage:
void *head;
pmix_status_t rc;
pmix_data_array_t darray;
pmix_info_t *info;
size_t ninfo;

// initialize the list
head = PMIx_Info_list_start();

// add something to the end of the list
rc = PMIx_Info_list_add(head, PMIX_CONNECT_TO_SYSTEM, NULL, PMIX_BOOL);
if (PMIX_SUCCESS != rc) {
    PMIx_Info_list_release(head);
    return rc;
}

// prepend something to the list
rc = PMIx_Info_list_prepend(head, PMIX_TCP_REPORT_URI, "filename", PMIX_STRING);
if (PMIX_SUCCESS != rc) {
    PMIx_Info_list_release(head);
    return rc;
}

// convert the list to an array of info
rc = PMIx_Info_list_convert(head, &darray);
if (PMIX_SUCCESS != rc) {
    PMIx_Info_list_release(head);
    return rc;
}

// cleanup the list
PMIx_Info_list_release(head);

// define pointer to the array of info for use
info = (pmix_info_t*)darray.array;
ninfo = darray.size;

Doesn't cover all the APIs - but is this sufficient? I could expand to cover more APIs, but this really is the most common usage.

Originally posted by @rhc54 in https://github.com/pmix/pmix-standard/issues/492#issuecomment-1769285586

abouteiller avatar Jan 25 '24 05:01 abouteiller