CFL reachability problem using Kronecker product#10
CFL reachability problem using Kronecker product#10Mamontyonok wants to merge 8 commits intoSparseLinearAlgebra:stablefrom
Conversation
gsvgit
left a comment
There was a problem hiding this comment.
Add more explanatory comments. For example look at this request
| GrB_Index nvals_old = 0, nvals_new = 0; | ||
| GrB_Matrix_nvals(&nvals_old, A); | ||
| while (true) { | ||
| GrB_mxm(A, NULL, GrB_LOR, GrB_LOR_LAND_SEMIRING_BOOL, A, A, NULL); |
| char *msg | ||
| ) | ||
| { | ||
| GrB_Matrix M3 = NULL; |
| GrB_Index r_dim = rsm->state_count; | ||
| GrB_Index kronecker_dim = r_dim * g_dim; | ||
|
|
||
| for (int64_t nt = 0; nt < rsm->nonterminal_count; ++nt) { |
There was a problem hiding this comment.
It is hard to realize this loop. We iterate through all non-terminals. Each non-terminal must has related box and this box must has at least one final state. So, it is unclear what exactly we do in this loop.
There was a problem hiding this comment.
Am I right, that you just handle boxes where the same state is both final and start?
| GrB_Matrix_clear(M3); | ||
|
|
||
| for (int64_t t = 0; t < terms_count; ++t) { | ||
| GrB_kronecker(M3, NULL, GrB_LOR, GrB_LAND, |
| GrB_Matrix_extractTuples_BOOL(i, j, V, &m3_nvals, M3); | ||
|
|
||
| for (GrB_Index k = 0; k < m3_nvals; ++k) { | ||
| GrB_Index s = i[k] / g_dim; |
| GrB_Index x = i[k] % g_dim; | ||
| GrB_Index y = j[k] % g_dim; | ||
|
|
||
| for (GrB_Index nt = 0; nt < rsm->nonterminal_count; ++nt) { |
There was a problem hiding this comment.
Can it be done using matrix operations like select or reduce?
| GrB_Matrix_new(&BaseGraph, GrB_BOOL, kronecker_dim, kronecker_dim); | ||
| GrB_Matrix_new(&DeltaM, GrB_BOOL, kronecker_dim, kronecker_dim); | ||
|
|
||
| for (int64_t t = 0; t < terms_count; ++t) { |
There was a problem hiding this comment.
Забыли почистить код? Что-то тут странное, начинач со строки 91
There was a problem hiding this comment.
Да, видимо когда менял код, продублировал этот цикл
|
|
||
| GrB_Matrix_dup(&CombinedGraph, M_graph); | ||
|
|
||
| transitive_closure_inplace(CombinedGraph); |
There was a problem hiding this comment.
Если я правильн понимаю, что здесь происходит, то можно иначе пересчитывать транзитивыное замыкание. Пусть TC -- результат замыкания с предыдущей итерации, D -- дельта на этой итерации. Тогда можно посчиать transitive_closure_inplace(TC + D). Должно чуть меньше итераций требовать. Но надо проверять, что будет быстрее.
| for (int64_t nt = 0; nt < rsm->nonterminal_count; ++nt) { | ||
| GrB_Matrix_new(&outputs[nt], GrB_BOOL, g_dim, g_dim); | ||
| GrB_Matrix_new(&delta_outputs[nt], GrB_BOOL, g_dim, g_dim); | ||
|
|
||
| GrB_Index s = rsm->start_states[nt]; | ||
| bool is_final = false; | ||
| GrB_Vector_extractElement_BOOL(&is_final, rsm->final_states[nt], s); | ||
|
|
||
| if (is_final) { | ||
| for (GrB_Index v = 0; v < g_dim; ++v) { | ||
| GrB_Matrix_setElement_BOOL(outputs[nt], true, v, v); | ||
| GrB_Matrix_setElement_BOOL(delta_outputs[nt], true, v, v); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Hi, I wanted to add your algo to CFG_Bench, and that piece of code took a lot of time: around 3 seconds to process 1k iterations after 55k/256k iterations had been processed. The processing time increases linearly with the current iteration count.
I think it just adds the identity matrix to the outputs[nt] and delta_outputs[nt] matrices, so this code resolves the task and works in under 1 second on the c_alias init.g graph:
GrB_Vector v_diag;
GrB_Vector_new(&v_diag, GrB_BOOL, g_dim);
GrB_Vector_assign_BOOL(v_diag, GrB_NULL, GrB_NULL, true, GrB_ALL, g_dim, NULL);
for (int64_t nt = 0; nt < rsm->nonterminal_count; ++nt) {
GrB_Matrix_new(&outputs[nt], GrB_BOOL, g_dim, g_dim);
GrB_Matrix_new(&delta_outputs[nt], GrB_BOOL, g_dim, g_dim);
GrB_Index s = rsm->start_states[nt];
bool is_final = false;
GrB_Vector_extractElement_BOOL(&is_final, rsm->final_states[nt], s);
if (is_final) {
GrB_Matrix_diag(&outputs[nt], v_diag, 0);
GrB_Matrix_diag(&delta_outputs[nt], v_diag, 0);
}
}
GrB_free(&v_diag);
The basic version of the CFLR algorithm is based on the Kronecker product