void unpack_remote_elem_side(stk::CommSparse& commSparse, int procId, stk::mesh::GraphEdge& recvGraphEdge)
{
    stk::mesh::EntityId globalId;
    commSparse.recv_buffer(procId).unpack<stk::mesh::EntityId>(globalId);
    recvGraphEdge.elem2 = -globalId;
    commSparse.recv_buffer(procId).unpack<int>(recvGraphEdge.side2);
}
void unpack_local_elem_side(stk::CommSparse& commSparse,
                            int procId,
                            const IdMapper& idMapper,
                            stk::mesh::GraphEdge& recvGraphEdge)
{
    stk::mesh::EntityId globalId;
    commSparse.recv_buffer(procId).unpack<stk::mesh::EntityId>(globalId);
    recvGraphEdge.elem1 = idMapper.globalToLocal(globalId);
    commSparse.recv_buffer(procId).unpack<int>(recvGraphEdge.side1);
}
stk::mesh::GraphEdge unpack_edge(stk::CommSparse& comm, const stk::mesh::BulkData& bulkData, const ElemElemGraph& graph, int proc_id)
{
    stk::mesh::EntityId id1 = 0, id2 = 0;
    unsigned side1 = 0, side2 = 0;
    comm.recv_buffer(proc_id).unpack<stk::mesh::EntityId>(id1);
    comm.recv_buffer(proc_id).unpack<unsigned>(side1);
    comm.recv_buffer(proc_id).unpack<stk::mesh::EntityId>(id2);
    comm.recv_buffer(proc_id).unpack<unsigned>(side2);

    stk::mesh::Entity element = bulkData.get_entity(stk::topology::ELEM_RANK, id2);
    ThrowRequireWithSierraHelpMsg(bulkData.is_valid(element));

    stk::mesh::impl::LocalId localId2 = graph.get_local_element_id(element);
    stk::mesh::GraphEdge edge(localId2, side2, -id1, side1);
    return edge;
}
void unpack_and_update_part_ordinals(stk::CommSparse &comm, const stk::mesh::BulkData& bulkData, const ElemElemGraph& graph, ParallelPartInfo &parallelPartInfo)
{
    for(int i=0;i<bulkData.parallel_size();++i)
    {
        while(comm.recv_buffer(i).remaining())
        {
            stk::mesh::GraphEdge edge = unpack_edge(comm, bulkData, graph, i);

            size_t num_ordinals = 0;
            comm.recv_buffer(i).unpack<size_t>(num_ordinals);
            std::vector<stk::mesh::PartOrdinal> partOrdinals(num_ordinals);
            for(stk::mesh::PartOrdinal &partOrdinal : partOrdinals)
                comm.recv_buffer(i).unpack<stk::mesh::PartOrdinal>(partOrdinal);

            parallelPartInfo[edge.elem2()] = partOrdinals;
        }
    }
}
void NoGhostGameofLife::recieve_num_active_neighbors_of_local_elements(stk::CommSparse& buffer)
{
    for (int procNum = 0; procNum < m_numProcs; procNum++)
    {
        stk::CommBuffer& buf = buffer.recv_buffer(procNum);
        while(buf.remaining())
            update_local_element_with_remote_neighbor_data(buf);
    }
}
void NoGhostGameofLife::unpack_remote_elem_key_info_from_buffer(stk::CommSparse& buffer)
{
    for (int proc = 0; proc < m_numProcs; proc++)
    {
        stk::CommBuffer& buf = buffer.recv_buffer(proc);
        while (buf.remaining())
            unpack_remote_info_from_this_processor(proc, buf);
    }
}
void NoGhostGameofLife::recieve_local_element_keys_to_check(stk::CommSparse& buffer)
{
    for (int procNum = 0; procNum < m_numProcs; procNum++)
    {
        stk::CommBuffer& buf = buffer.recv_buffer(procNum);
        while (buf.remaining())
            m_localElementsToVisit.insert(m_bulkData->
            get_entity(stk::unpack<stk::mesh::EntityKey>(buf)));
    }
}
void NoGhostGameofLife::unpack_local_and_remote_key_info_from_each_processor(stk::CommSparse&
                                                                             buffer)
{
    for (int procRank = 0; procRank < m_numProcs; procRank++)
    {
        stk::CommBuffer& buf = buffer.recv_buffer(procRank);
        while (buf.remaining())
            unpack_local_and_remote_keys_from_buffer(buf);
    }
}
void unpack_data(stk::CommSparse& comm, int my_proc_id, int num_procs, std::vector<SideSharingData>& sideSharingDataThisProc)
{
    for(int i=0;i<num_procs;++i)
    {
        while(comm.recv_buffer(i).remaining())
        {
            stk::mesh::impl::IdViaSidePair receivedIdSide;
            stk::mesh::EntityId chosenId;
            comm.recv_buffer(i).unpack<stk::mesh::EntityId>(receivedIdSide.id);
            comm.recv_buffer(i).unpack<int>(receivedIdSide.side);
            comm.recv_buffer(i).unpack<stk::mesh::EntityId>(chosenId);
            SideSharingData localTemp;
            localTemp.elementAndSide = receivedIdSide;
            localTemp.owningProc = std::min(my_proc_id, i);;
            localTemp.sharingProc = i;
            localTemp.chosenSideId = chosenId;
            unpack_vector(comm.recv_buffer(i), localTemp.sideNodes);
            unpack_vector(comm.recv_buffer(i), localTemp.partOrdinals);

            sideSharingDataThisProc.push_back(localTemp);
        }
    }
}
void unpack_selector_value(stk::CommSparse& comm, int rank, RemoteSelectedValue &remoteSelectedValue)
{
    int64_t id;
    comm.recv_buffer(rank).unpack<int64_t>(id);
    remoteSelectedValue.set_id_as_selected(id);
}
stk::mesh::EntityId unpack_chosen_side_id(stk::CommSparse &commSparse, int procId)
{
    stk::mesh::EntityId chosenSideId;
    commSparse.recv_buffer(procId).unpack<stk::mesh::EntityId>(chosenSideId);
    return chosenSideId;
}