YAP 7.1.0
yapor.yap
Go to the documentation of this file.
1/**
2 * @file yapor.yap
3 * @author VITOR SANTOS COSTA <vsc@VITORs-MBP-2.lan>
4 * @date Thu Oct 19 12:23:00 2017
5 *
6 * @brief Or-Parallelism
7 *
8 * @defgroup YapOR Or-Parallelism
9 @ @ingroup extensions
10 *
11 *
12*/
13:- system_module( '$_utils', [callable/1,
18 op/3,
19 prolog/0,
23 subsumes_term/2], ['$getval_exception'/3]).
24
25:- '$live'/0use_system_module( '$_boot', []).
26
27:- '$do_error'/2use_system_module( '$_errors', []).
28
29%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30%% %%
31%% The YapTab/YapOr/OPTYap systems %%
32%% %%
33%% YapTab extends the Yap Prolog engine to support sequential tabling %%
34%% YapOr extends the Yap Prolog engine to support or-parallelism %%
35%% OPTYap extends the Yap Prolog engine to support or-parallel tabling %%
36%% %%
37%% %%
38%% Yap Prolog was developed at University of Porto, Portugal %%
39%% %%
40%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41
42:- meta_predicate
43 parallel(0),
44 parallel_findall(?,0,?),
45 parallel_findfirst(?,0,?),
46 parallel_once(0).
47
48
49
50%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51%% or_statistics/0 %%
52%% opt_statistics/0 %%
53%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
55parallel_once :-
56 current_output(Stream),
57 or_statistics(Stream).
58
59or_statistics :-
60 current_output(Stream),
61 opt_statistics(Stream).
62
63
64
65%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
66%% or_statistics/2 %%
67%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
68
69%% should match with code in OPTYap/opt.preds.c
70or_statistics(total_memory,[BytesInUse,BytesAllocated]) :-
71 '$c_get_optyap_statistics'(0,BytesInUse,BytesAllocated).
72or_statistics(or_frames,[BytesInUse,StructsInUse]) :-
73 '$c_get_optyap_statistics'(4,BytesInUse,StructsInUse).
74or_statistics(query_goal_solution_frames,[BytesInUse,StructsInUse]) :-
75 '$c_get_optyap_statistics'(12,BytesInUse,StructsInUse).
76or_statistics(query_goal_answer_frames,[BytesInUse,StructsInUse]) :-
77 '$c_get_optyap_statistics'(13,BytesInUse,StructsInUse).
78
79
80
81%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82%% opt_statistics/2 %%
83%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
85%% should match with code in OPTYap/opt.preds.c
86opt_statistics(total_memory,[BytesInUse,BytesAllocated]) :-
87 '$c_get_optyap_statistics'(0,BytesInUse,BytesAllocated).
88opt_statistics(table_entries,[BytesInUse,StructsInUse]) :-
89 '$c_get_optyap_statistics'(1,BytesInUse,StructsInUse).
90opt_statistics(subgoal_frames,[BytesInUse,StructsInUse]) :-
91 '$c_get_optyap_statistics'(2,BytesInUse,StructsInUse).
92opt_statistics(dependency_frames,[BytesInUse,StructsInUse]) :-
93 '$c_get_optyap_statistics'(3,BytesInUse,StructsInUse).
94opt_statistics(or_frames,[BytesInUse,StructsInUse]) :-
95 '$c_get_optyap_statistics'(4,BytesInUse,StructsInUse).
96opt_statistics(suspension_frames,[BytesInUse,StructsInUse]) :-
97 '$c_get_optyap_statistics'(5,BytesInUse,StructsInUse).
98opt_statistics(subgoal_trie_nodes,[BytesInUse,StructsInUse]) :-
99 '$c_get_optyap_statistics'(6,BytesInUse,StructsInUse).
100opt_statistics(answer_trie_nodes,[BytesInUse,StructsInUse]) :-
101 '$c_get_optyap_statistics'(7,BytesInUse,StructsInUse).
102opt_statistics(subgoal_trie_hashes,[BytesInUse,StructsInUse]) :-
103 '$c_get_optyap_statistics'(8,BytesInUse,StructsInUse).
104opt_statistics(answer_trie_hashes,[BytesInUse,StructsInUse]) :-
105 '$c_get_optyap_statistics'(9,BytesInUse,StructsInUse).
106opt_statistics(global_trie_nodes,[BytesInUse,StructsInUse]) :-
107 '$c_get_optyap_statistics'(10,BytesInUse,StructsInUse).
108opt_statistics(global_trie_hashes,[BytesInUse,StructsInUse]) :-
109 '$c_get_optyap_statistics'(11,BytesInUse,StructsInUse).
110opt_statistics(query_goal_solution_frames,[BytesInUse,StructsInUse]) :-
111 '$c_get_optyap_statistics'(12,BytesInUse,StructsInUse).
112opt_statistics(query_goal_answer_frames,[BytesInUse,StructsInUse]) :-
113 '$c_get_optyap_statistics'(13,BytesInUse,StructsInUse).
114opt_statistics(table_subgoal_solution_frames,[BytesInUse,StructsInUse]) :-
115 '$c_get_optyap_statistics'(14,BytesInUse,StructsInUse).
116opt_statistics(table_subgoal_answer_frames,[BytesInUse,StructsInUse]) :-
117 '$c_get_optyap_statistics'(15,BytesInUse,StructsInUse).
118opt_statistics(subgoal_entries,[BytesInUse,StructsInUse]) :-
119 '$c_get_optyap_statistics'(16,BytesInUse,StructsInUse).
120opt_statistics(answer_ref_nodes,[BytesInUse,StructsInUse]) :-
121 '$c_get_optyap_statistics'(17,BytesInUse,StructsInUse).
122
123
124
125%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126%% parallel/1 %%
127%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
128
129parallel(Goal) :-
130 parallel_mode(Mode), Mode = parallel_mode, parallel_mode,
131 (
132 '$parallel_query'(Goal)
133 ;
134 '$parallel_query'
135 ).
136parallel(Goal) :-
137 (
138 '$execute'(Goal),
139 '$execute'
140 ;
141 '$execute'
142 ).
143
144'$parallel_query'(Goal) :-
145 '$c_yapor_start',
146 '$execute'(Goal),
147 '$execute'.
148'$parallel_query'(_).
149
150
151
152%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
153%% parallel_findall/3 %%
154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155
156parallel_findall(Template,Goal,Answers) :-
157 parallel_mode(Mode), Mode = parallel_mode, parallel_mode,
158 (
159 '$parallel_findall_query'(Template,Goal)
160 ;
161 '$c_parallel_get_answers'(Refs),
162 '$parallel_findall_recorded'(Refs,Answers),
163 eraseall(parallel_findall)
164 ).
165parallel_findall(Template,Goal,Answers) :-
166 findall(Template,Goal,Answers).
167
168'$parallel_findall_query'(Template,Goal) :-
169 '$c_yapor_start',
170 '$execute'(Goal),
171 recordz(parallel_findall,Template,Ref),
172 '$c_parallel_new_answer'(Ref),
173 '$c_parallel_new_answer'.
174'$parallel_findall_query'(_,_).
175
176'$parallel_findall_recorded'([],[]) :- '$parallel_findall_recorded'.
177'$parallel_findall_recorded'([Ref|Refs],[Template|Answers]):-
178 recorded(parallel_findall,Template,Ref),
179 '$parallel_findall_recorded'(Refs,Answers).
180
181
182%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183%% parallel_findfirst/3 %%
184%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185
186parallel_findfirst(Template,Goal,Answer) :-
187 parallel_findall(Template,(Goal,!),Answer).
188
189
190%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
191%% parallel_once/1 %%
192%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193
194parallel_once(Goal) :-
195 parallel_mode(Mode), Mode = parallel_mode, parallel_mode,
196 (
197 '$parallel_once_query'(Goal)
198 ;
199 recorded(parallel_once,Goal,Ref),
200 erase(Ref)
201 ).
202parallel_once(Goal) :-
203 once(Goal).
204
205'$parallel_once_query'(Goal) :-
206 '$c_yapor_start',
207 '$execute'(once(Goal)),
208 recordz(parallel_once,Goal,_),
209 recordz.
210'$parallel_once_query'(_).
211
212%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
callable( ?_Goal_ )
current_op( P, T, F)
current_output(+ S)
nb_current(? Name, ? Value)
nth_instance(? Key,? Index,? R)
nth_instance(? Key,? Index, T,? R)
op(+ P,+ T,+ A)
recordaifnot(+ K, T,- R)
recordzifnot(+ K, T,- R)
simple( T)
Definition: utils.yap:32
subsumes_term(? Subsumer, ? Subsumed)
erase(+ R)
eraseall(+ K)
recordz(+ K, T,- R)
findall( T,+ G,- L)
Definition: setof.yap:70
once( 0:G)