void copy_into_shared_ids(const fei::CommMap<int>::Type& procs_to_ids_and_sharing_procs,
                          const snl_fei::RecordCollection& records,
                          fei::SharedIDs<int>& sharedIDs)
{
    //Given a CommMap object which maps procs to packed vectors of ids and sharing
    //procs, and a RecordCollection of records that appear in the local subdomain:
    //Loop through the CommMap and for each id that exists in 'records', copy that
    //id along with the associated sharing procs into the sharedIDs object.

    fei::CommMap<int>::Type::const_iterator
    ip_iter = procs_to_ids_and_sharing_procs.begin(),
    ip_end = procs_to_ids_and_sharing_procs.end();

    for(; ip_iter != ip_end; ++ip_iter) {
        const std::vector<int>& ids_and_procs = ip_iter->second;
        size_t vsize = ids_and_procs.size();
        size_t offset = 0;
        while(offset < vsize) {
            int id = ids_and_procs[offset++];
            int num_procs = ids_and_procs[offset++];
            if (records.getRecordWithID(id) != NULL) {
                sharedIDs.addSharedID(id, num_procs, &ids_and_procs[offset]);
            }
            offset += num_procs;
        }
    }
}