MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / _MatrixSynchronize

Function _MatrixSynchronize

src/graph/graph.c:171–230  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

169// matches the number of nodes in the graph. Also, synchronize
170// matrix to execute any pending operations
171void _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
227cleanup:
228 // unlock matrix mutex

Callers

nothing calls this directly

Calls 8

RG_Matrix_nrowsFunction · 0.85
RG_Matrix_ncolsFunction · 0.85
RG_Matrix_isDirtyFunction · 0.85
Graph_RequiredMatrixDimFunction · 0.85
RG_Matrix_LockFunction · 0.85
RG_Matrix_resizeFunction · 0.85
RG_Matrix_waitFunction · 0.85
RG_Matrix_UnlockFunction · 0.85

Tested by

no test coverage detected