2017-10-27 13:50:40 +01:00
|
|
|
/**
|
|
|
|
* @file yapor.yap
|
|
|
|
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP-2.lan>
|
|
|
|
* @date Thu Oct 19 12:23:00 2017
|
|
|
|
*
|
|
|
|
* @brief Or-Parallelism
|
|
|
|
*
|
|
|
|
* @defgroup YapOR Or-Parallelism
|
|
|
|
@ @ingroup extensions
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
2014-06-19 15:04:48 +01:00
|
|
|
:- system_module( '$_utils', [callable/1,
|
|
|
|
current_op/3,
|
|
|
|
nb_current/2,
|
|
|
|
nth_instance/3,
|
|
|
|
nth_instance/4,
|
|
|
|
op/3,
|
|
|
|
prolog/0,
|
|
|
|
recordaifnot/3,
|
|
|
|
recordzifnot/3,
|
|
|
|
simple/1,
|
|
|
|
subsumes_term/2], ['$getval_exception'/3]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_boot', ['$live'/0]).
|
|
|
|
|
|
|
|
:- use_system_module( '$_errors', ['$do_error'/2]).
|
2014-04-09 12:39:29 +01:00
|
|
|
|
2014-06-19 15:04:48 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% %%
|
|
|
|
%% The YapTab/YapOr/OPTYap systems %%
|
|
|
|
%% %%
|
|
|
|
%% YapTab extends the Yap Prolog engine to support sequential tabling %%
|
|
|
|
%% YapOr extends the Yap Prolog engine to support or-parallelism %%
|
|
|
|
%% OPTYap extends the Yap Prolog engine to support or-parallel tabling %%
|
|
|
|
%% %%
|
|
|
|
%% %%
|
|
|
|
%% Yap Prolog was developed at University of Porto, Portugal %%
|
|
|
|
%% %%
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2010-04-20 03:59:48 +01:00
|
|
|
|
2014-06-19 15:04:48 +01:00
|
|
|
:- meta_predicate
|
|
|
|
parallel(0),
|
|
|
|
parallel_findall(?,0,?),
|
|
|
|
parallel_findfirst(?,0,?),
|
|
|
|
parallel_once(0).
|
2010-04-20 03:59:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-19 15:04:48 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% or_statistics/0 %%
|
|
|
|
%% opt_statistics/0 %%
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2011-05-25 18:38:46 +01:00
|
|
|
|
2014-06-19 15:04:48 +01:00
|
|
|
or_statistics :-
|
2011-05-25 18:38:46 +01:00
|
|
|
current_output(Stream),
|
|
|
|
or_statistics(Stream).
|
|
|
|
|
2014-06-19 15:04:48 +01:00
|
|
|
opt_statistics :-
|
2011-05-25 18:38:46 +01:00
|
|
|
current_output(Stream),
|
|
|
|
opt_statistics(Stream).
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-04-20 03:59:48 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% or_statistics/2 %%
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2010-04-23 04:22:10 +01:00
|
|
|
%% should match with code in OPTYap/opt.preds.c
|
2010-04-20 03:59:48 +01:00
|
|
|
or_statistics(total_memory,[BytesInUse,BytesAllocated]) :-
|
|
|
|
'$c_get_optyap_statistics'(0,BytesInUse,BytesAllocated).
|
|
|
|
or_statistics(or_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(4,BytesInUse,StructsInUse).
|
|
|
|
or_statistics(query_goal_solution_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(12,BytesInUse,StructsInUse).
|
|
|
|
or_statistics(query_goal_answer_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(13,BytesInUse,StructsInUse).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% opt_statistics/2 %%
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2010-04-23 04:22:10 +01:00
|
|
|
%% should match with code in OPTYap/opt.preds.c
|
2010-04-20 03:59:48 +01:00
|
|
|
opt_statistics(total_memory,[BytesInUse,BytesAllocated]) :-
|
|
|
|
'$c_get_optyap_statistics'(0,BytesInUse,BytesAllocated).
|
|
|
|
opt_statistics(table_entries,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(1,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(subgoal_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(2,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(dependency_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(3,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(or_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(4,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(suspension_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(5,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(subgoal_trie_nodes,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(6,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(answer_trie_nodes,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(7,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(subgoal_trie_hashes,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(8,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(answer_trie_hashes,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(9,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(global_trie_nodes,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(10,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(global_trie_hashes,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(11,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(query_goal_solution_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(12,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(query_goal_answer_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(13,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(table_subgoal_solution_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(14,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(table_subgoal_answer_frames,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(15,BytesInUse,StructsInUse).
|
2011-12-07 13:53:20 +00:00
|
|
|
opt_statistics(subgoal_entries,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(16,BytesInUse,StructsInUse).
|
|
|
|
opt_statistics(answer_ref_nodes,[BytesInUse,StructsInUse]) :-
|
|
|
|
'$c_get_optyap_statistics'(17,BytesInUse,StructsInUse).
|
2010-04-20 03:59:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2011-06-21 15:19:07 +01:00
|
|
|
%% parallel/1 %%
|
2010-04-20 03:59:48 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-06-21 15:19:07 +01:00
|
|
|
parallel(Goal) :-
|
|
|
|
parallel_mode(Mode), Mode = on, !,
|
|
|
|
(
|
|
|
|
'$parallel_query'(Goal)
|
|
|
|
;
|
|
|
|
true
|
|
|
|
).
|
|
|
|
parallel(Goal) :-
|
|
|
|
(
|
|
|
|
'$execute'(Goal),
|
|
|
|
fail
|
|
|
|
;
|
|
|
|
true
|
|
|
|
).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2011-06-21 15:19:07 +01:00
|
|
|
'$parallel_query'(Goal) :-
|
|
|
|
'$c_yapor_start',
|
|
|
|
'$execute'(Goal),
|
|
|
|
fail.
|
|
|
|
'$parallel_query'(_).
|
2010-04-20 03:59:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2011-06-21 15:19:07 +01:00
|
|
|
%% parallel_findall/3 %%
|
2010-04-20 03:59:48 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2011-06-21 15:19:07 +01:00
|
|
|
parallel_findall(Template,Goal,Answers) :-
|
|
|
|
parallel_mode(Mode), Mode = on, !,
|
2010-04-20 03:59:48 +01:00
|
|
|
(
|
2011-06-21 15:19:07 +01:00
|
|
|
'$parallel_findall_query'(Template,Goal)
|
2010-04-20 03:59:48 +01:00
|
|
|
;
|
2012-01-05 16:04:32 +00:00
|
|
|
'$c_parallel_get_answers'(Refs),
|
|
|
|
'$parallel_findall_recorded'(Refs,Answers),
|
|
|
|
eraseall(parallel_findall)
|
2010-04-20 03:59:48 +01:00
|
|
|
).
|
2011-06-21 15:19:07 +01:00
|
|
|
parallel_findall(Template,Goal,Answers) :-
|
|
|
|
findall(Template,Goal,Answers).
|
|
|
|
|
|
|
|
'$parallel_findall_query'(Template,Goal) :-
|
|
|
|
'$c_yapor_start',
|
|
|
|
'$execute'(Goal),
|
2012-01-05 16:04:32 +00:00
|
|
|
recordz(parallel_findall,Template,Ref),
|
|
|
|
'$c_parallel_new_answer'(Ref),
|
2011-06-21 15:19:07 +01:00
|
|
|
fail.
|
|
|
|
'$parallel_findall_query'(_,_).
|
|
|
|
|
2012-01-05 16:04:32 +00:00
|
|
|
'$parallel_findall_recorded'([],[]) :- !.
|
|
|
|
'$parallel_findall_recorded'([Ref|Refs],[Template|Answers]):-
|
2011-06-21 15:19:07 +01:00
|
|
|
recorded(parallel_findall,Template,Ref),
|
2012-01-05 16:04:32 +00:00
|
|
|
'$parallel_findall_recorded'(Refs,Answers).
|
2010-04-20 03:59:48 +01:00
|
|
|
|
|
|
|
|
2012-02-27 18:31:57 +00:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
%% parallel_findfirst/3 %%
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
|
|
|
parallel_findfirst(Template,Goal,Answer) :-
|
|
|
|
parallel_findall(Template,(Goal,!),Answer).
|
|
|
|
|
2010-04-20 03:59:48 +01:00
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
2011-06-21 15:19:07 +01:00
|
|
|
%% parallel_once/1 %%
|
2010-04-20 03:59:48 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2011-06-21 15:19:07 +01:00
|
|
|
parallel_once(Goal) :-
|
|
|
|
parallel_mode(Mode), Mode = on, !,
|
2010-04-20 03:59:48 +01:00
|
|
|
(
|
2011-06-21 15:19:07 +01:00
|
|
|
'$parallel_once_query'(Goal)
|
2010-04-20 03:59:48 +01:00
|
|
|
;
|
2011-06-21 15:19:07 +01:00
|
|
|
recorded(parallel_once,Goal,Ref),
|
|
|
|
erase(Ref)
|
2010-04-20 03:59:48 +01:00
|
|
|
).
|
2011-06-21 15:19:07 +01:00
|
|
|
parallel_once(Goal) :-
|
|
|
|
once(Goal).
|
|
|
|
|
|
|
|
'$parallel_once_query'(Goal) :-
|
|
|
|
'$c_yapor_start',
|
2011-06-22 19:20:56 +01:00
|
|
|
'$execute'(once(Goal)),
|
2011-06-21 15:19:07 +01:00
|
|
|
recordz(parallel_once,Goal,_),
|
|
|
|
fail.
|
|
|
|
'$parallel_once_query'(_).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
2010-04-23 04:22:10 +01:00
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|