resize given matrix, such that its number of row and columns matches the number of nodes in the graph. Also, synchronize matrix to execute any pending operations
| 169 | // matches the number of nodes in the graph. Also, synchronize |
| 170 | // matrix to execute any pending operations |
| 171 | void _MatrixSynchronize |
| 172 | ( |
| 173 | const Graph *g, |
| 174 | RG_Matrix m |
| 175 | ) { |
| 176 | GrB_Info info; |
| 177 | GrB_Index n_rows; |
| 178 | GrB_Index n_cols; |
| 179 | |
| 180 | RG_Matrix_nrows(&n_rows, m); |
| 181 | RG_Matrix_ncols(&n_cols, m); |
| 182 | |
| 183 | bool dirty = RG_Matrix_isDirty(m); |
| 184 | GrB_Index dims = Graph_RequiredMatrixDim(g); |
| 185 | |
| 186 | UNUSED(info); |
| 187 | |
| 188 | // matrix must be resized if its dimensions missmatch required dimensions |
| 189 | bool require_resize = (n_rows != dims || n_cols != dims); |
| 190 | |
| 191 | // matrix fully synced, nothing to do |
| 192 | if(!require_resize && !dirty) { |
| 193 | return; |
| 194 | } |
| 195 | |
| 196 | // lock matrix |
| 197 | RG_Matrix_Lock(m); |
| 198 | |
| 199 | // recheck |
| 200 | RG_Matrix_nrows(&n_rows, m); |
| 201 | RG_Matrix_ncols(&n_cols, m); |
| 202 | dirty = RG_Matrix_isDirty(m); |
| 203 | dims = Graph_RequiredMatrixDim(g); |
| 204 | require_resize = (n_rows != dims || n_cols != dims); |
| 205 | |
| 206 | // some other thread performed sync |
| 207 | if(!require_resize && !dirty) { |
| 208 | goto cleanup; |
| 209 | } |
| 210 | |
| 211 | // resize if required |
| 212 | if(require_resize) { |
| 213 | info = RG_Matrix_resize(m, dims, dims); |
| 214 | ASSERT(info == GrB_SUCCESS); |
| 215 | } |
| 216 | |
| 217 | // flush pending changes if dirty |
| 218 | // we need to call 'RG_Matrix_isDirty' again |
| 219 | // as 'RG_Matrix_resize' might require 'wait' for HyperSparse matrices |
| 220 | if(RG_Matrix_isDirty(m)) { |
| 221 | info = RG_Matrix_wait(m, false); |
| 222 | ASSERT(info == GrB_SUCCESS); |
| 223 | } |
| 224 | |
| 225 | ASSERT(RG_Matrix_isDirty(m) == false); |
| 226 | |
| 227 | cleanup: |
| 228 | // unlock matrix mutex |
nothing calls this directly
no test coverage detected