int i;
int j;
for (i = 0; i<NCOL; i++) {
for (j = 0; j<NCOL; j++) {
mat[i][j].neigh.push_back(mat[(i-1+NCOL)%NCOL][(j-1+NCOL)%NCOL]);
//mat[i][j].neigh.push_back(mat[i][(j-1+NCOL)%NCOL]);
mat[i][j].neigh.push_back(mat[(i+1)%NCOL][(j-1+NCOL)%NCOL]);
mat[i][j].neigh.push_back(mat[(i-1+NCOL)%NCOL][j]);
mat[i][j].neigh.push_back(mat[(i+1)%NCOL][j]);
mat[i][j].neigh.push_back(mat[(i-1+NCOL)%NCOL][(j+1)%NCOL]);
mat[i][j].neigh.push_back(mat[i][(j+1)%NCOL]);
mat[i][j].neigh.push_back(mat[(i+1)%NCOL][(j+1)%NCOL]);
}
}