Q:

Parallellizable Algorithms to traverse a 2D matrix being aware of both col/row-wise neighborhood

I have a fairly large N*N integer matrix Matrix2D (assume sufficient memory), 
1, within each row/column, I need to record the col/row index of an element if it's value is different than it's right/lower neighbour.
2, I want to find an optimal algorithms that is parallellizable, ideally by OMP.
So, finally I will have some data structures like,
std::vector<std::vector<int>>   RowWiseDiscontinuity(N);// N= #of rows
std::vector<std::vector<int>>   ColWiseDiscontinuity(N);// N= #of cols

where inner std::vector<int> records the row/col indices. 
I put my serial version here but find it difficult to be OMP parallelized... Someone could provide some idea how to implement the traversing over this 2D matrix with omp?
code snippet,
std::vector<std::vector<int>>   RowWiseDiscontinuity(N);// N= #of rows
std::vector<std::vector<int>>   ColWiseDiscontinuity(N);// N= #of cols
std::vector<int> TempX1;
std::vector<int> TempX2;
for (int y=0; y<N; ++y)
{
    TempX1.clear();
    for (int x =0; x<N; ++x)
    {
        int value = Matrix2D(x,y);
        TempX1.push_back(value);
    }

    auto iter1 = TempX1.begin();
    auto iter2 = TempX2.begin();

    if (y>0)
    for (int x =0; x<N; ++x)
    {
         if (*iter1 !=*(iter1+1))
         {
             RowWiseDiscontinuity[y].push_back(x); //Critical for OMP
         }
         ++iter1;
         ++iter2;
         if (*iter1 != *iter2)
         {
             ColWiseDiscontinuity[x].push_back(y); //Critical for OMP
         }
     }

     TempX2.swap(TempX1); // proceed to next row, remember previous

}

A:

I would create another array that holds the nearest neighbor both column and row-wise. This would have to be done as a first pass, obviously. I recommend creating a 2d array of pairs (pair) that holds the indices you want. Instead of two vectors, I would do a vector of pairs. Pairs are parallellizable and easily sorted. 
vector<vector<pair<int, int>>> elements(N);

