[英]How can I localize the reasons for excessive goal expansion?
The execution profiler of SICStus Prolog 4.5.1 gave me the following output: SICStus Prolog 4.5.1的执行分析器给了我以下输出:
| ?- print_profile. insns try/retry called name ---------------------------------------------------------------- 4965857/4965857 prolog:wellformed_body_expand/11 201383839 4965857 4965857 prolog:call_goal_expansion/6 *4860319/4860363 prolog:choice/0 4860319/9720726 prolog:in_hook_flag/2 4860319/9006266 prolog:prolog_catch/3 ---------------------------------------------------------------- 4965868/4965868 prolog:wellformed_body_iso/11 178771039 19863439 4965868 prolog:wellformed_body_expand/11 4965857/4965857 prolog:call_goal_expansion/6 4965857/4965857 prolog:goal_exp/8 4965857/4965857 prolog:wf_source_module/2 ---------------------------------------------------------------- 165399306 5469803 ... ---------------------------------------------------------------- 3044459/3044459 prolog:dcg_translate_dcg_safe/8 163441583 23688395 3044459 prolog:dcg_translate_dcg_atom/6 ---------------------------------------------------------------- ...
Quite puzzling! 相当令人费解! It seems that 3/4 of all work (column #1 in the table) is due to goal expansion.
似乎3/4的工作(表中的第1列)是由于目标扩展。
But why? 但为什么? How can I localize the code causing all these goal expansions?
如何本地化导致所有这些目标扩展的代码? Please help!
请帮忙!
@PerMildner's answer and comments pointed the way to resolving the issue. @ PerMildner的回答和评论指出了解决问题的方法。 New execution profiling results of
magic_square__no_sym(4)
(magic squares of size 4x4 with additional constraints between corner points to eliminate symmetric solutions) using library(clpz)
look a lot more reasonable: 新的执行剖析的结果
magic_square__no_sym(4)
使用(4×4的大小与角点之间的额外的限制的幻方,以消除对称解决方案) library(clpz)
看多了很多合理的:
| ?- print_profile. insns try/retry called name ---------------------------------------------------------------- 1197973/2041757 clpz:fd_put/3 843784/2041757 clpz:fd_put/5 153514528 5339777 2041757 clpz:put_terminating_q/4 34012/8145271 clpz:domain_infimum/2 34012/8263457 clpz:domain_supremum/2 16/1224480 clpz:new_queue/1 51821/51821 clpz:queue_goal_q/2 620022/620022 clpz:trigger_props_q/5 ---------------------------------------------------------------- 1197973/1224480 clpz:fd_put/3 16/1224480 clpz:put_terminating_q/4 26357/1224480 clpz:trigger_once/1 134/1224480 clpz:variables_same_queue/1 113876576 0 1224480 clpz:new_queue/1 ---------------------------------------------------------------- ...
The performance impact of the changes in goal expansion for this case are very impressive: 2X ! 这个案例的目标扩展变化对性能的影响令人印象深刻: 2倍 !
SICStus tries to be clever when there is no goal expansion that can be applicable. 当没有可适用的目标扩展时,SICStus会尝试变得聪明。 In that case the call to
call_goal_expansion
can often be avoided. 在这种情况下,通常可以避免调用
call_goal_expansion
。 However, if there is a goal expansion visible (eg by loading clpz
) and that goal expansion has poor indexing, then the full goal expansion processing is attempted. 但是,如果目标扩展可见(例如,通过加载
clpz
)并且目标扩展具有较差的索引,则尝试完全目标扩展处理。 The latter may be what happens because of the "defaulty" last clause of clpz:goal_expansion/5
. 后者可能是因为
clpz:goal_expansion/5
的“defaulty” 最后一个子句而发生的事情。
Note that "poor indexing" cannot be worked around by adding cuts in this case. 请注意,在这种情况下,通过添加剪切无法解决“差索引”问题。 Internally, SICStus looks into the indexing data structure for the
goal_expansion/5
predicate to determine whether any of its clauses could be applicable. 在内部,SICStus查看
goal_expansion/5
谓词的索引数据结构,以确定其任何子句是否适用。 A catch-all clause, like the linked one, makes this test fail and the full, slower, call_goal_expansion
will be called. 像链接的子句一样,catch-all子句使得此测试失败,
call_goal_expansion
将调用完整,较慢的call_goal_expansion
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.