2001-04-09 20:54:03 +01:00
|
|
|
/*************************************************************************
|
|
|
|
* *
|
|
|
|
* YAP Prolog *
|
|
|
|
* *
|
|
|
|
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
|
|
|
* *
|
|
|
|
* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 *
|
|
|
|
* *
|
|
|
|
**************************************************************************
|
|
|
|
* *
|
|
|
|
* File: yapor.yap *
|
|
|
|
* Last rev: 8/2/88 *
|
|
|
|
* mods: *
|
|
|
|
* comments: support or-parallelism *
|
|
|
|
* *
|
|
|
|
*************************************************************************/
|
|
|
|
|
2001-10-30 16:42:05 +00:00
|
|
|
'$parallel_query'(G,[]) :- !, '$start_yapor', '$execute'(G), !,
|
|
|
|
'$parallel_yes_answer'.
|
|
|
|
'$parallel_query'(G,V) :- '$start_yapor', '$execute'(G), '$parallel_new_answer'(V).
|
2001-04-09 20:54:03 +01:00
|
|
|
|
|
|
|
% ***************************
|
|
|
|
% * -------- YAPOR -------- *
|
|
|
|
% ***************************
|
|
|
|
|
2001-05-28 20:54:53 +01:00
|
|
|
default_sequential(X) :-
|
|
|
|
'$default_sequential'(X), !.
|
2001-04-09 20:54:03 +01:00
|
|
|
default_sequential(_).
|
|
|
|
|
|
|
|
'$sequential' :-
|
|
|
|
'$default_sequential'(X),
|
|
|
|
'$initialization'('$default_sequential'(X)),
|
|
|
|
'$default_sequential'(on).
|
|
|
|
|
|
|
|
'$parallel' :-
|
|
|
|
'$default_sequential'(X),
|
|
|
|
'$initialization'('$default_sequential'(X)),
|
|
|
|
'$default_sequential'(off).
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$sequential_directive'(X,_) :- var(X), !,
|
2001-04-09 20:54:03 +01:00
|
|
|
write(user_error, '[ Error: argument to sequential/1 should be a predicate ]'),
|
|
|
|
nl(user_error),
|
|
|
|
fail.
|
2001-11-15 00:01:43 +00:00
|
|
|
'$sequential_directive'((A,B),M) :- !,
|
|
|
|
'$sequential_directive'(A,M), '$sequential_directive'(B,M).
|
|
|
|
'$sequential_directive'(M:A,_) :- !,
|
|
|
|
'$sequential_directive'(A,M).
|
|
|
|
'$sequential_directive'(A/N,M) :- integer(N), atom(A), !,
|
|
|
|
functor(T,A,N),
|
|
|
|
'$flags'(T,M,F,F),
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2003-12-04 18:13:04 +00:00
|
|
|
X is F /\ 0x00000020, X =\= 0, !,
|
2001-04-09 20:54:03 +01:00
|
|
|
write(user_error, '[ Warning: '),
|
2001-11-15 00:01:43 +00:00
|
|
|
write(user_error, M:A/N),
|
2001-04-09 20:54:03 +01:00
|
|
|
write(user_error, ' is already declared as sequential ]'),
|
|
|
|
nl(user_error)
|
|
|
|
;
|
2003-12-04 18:13:04 +00:00
|
|
|
X is F /\ 0x1991F880, X =:= 0, !, '$sequential'(T,M)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
write(user_error, '[ Error: '),
|
2001-11-15 00:01:43 +00:00
|
|
|
write(user_error, M:A/N),
|
2001-04-09 20:54:03 +01:00
|
|
|
write(user_error, ' cannot be declared as sequential ]'),
|
|
|
|
nl(user_error),
|
|
|
|
fail
|
|
|
|
).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$sequential_directive'(X,_) :- write(user_error, '[ Error: '),
|
2001-04-09 20:54:03 +01:00
|
|
|
write(user_error, X),
|
|
|
|
write(user_error, ' is an invalid argument to sequential/1 ]'),
|
|
|
|
nl(user_error),
|
|
|
|
fail.
|
|
|
|
|
2001-11-15 00:01:43 +00:00
|
|
|
'$parallel_directive'(X,M) :- var(X), !,
|
2002-09-09 18:40:12 +01:00
|
|
|
'$do_error'(instantiation_error,parallel(M:X)).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$parallel_directive'((A,B),M) :- !,
|
|
|
|
'$parallel_directive'(A,M),
|
|
|
|
'parallel_directive'(B,M).
|
|
|
|
'$parallel_directive'(M:A,_) :- !,
|
|
|
|
'$parallel_directive'(A,M).
|
|
|
|
'$parallel_directive'(A/N,M) :- integer(N), atom(A), !,
|
|
|
|
functor(T,A,N), '$flags'(T,M,F,F),
|
2001-04-09 20:54:03 +01:00
|
|
|
(
|
2003-12-04 18:13:04 +00:00
|
|
|
NF is F /\ 0x00000020, '$flags'(T,F,NF) ;
|
2001-04-09 20:54:03 +01:00
|
|
|
write(user_error, '[ Warning: '),
|
2001-11-15 00:01:43 +00:00
|
|
|
write(user_error, M:A/N),
|
2001-04-09 20:54:03 +01:00
|
|
|
write(user_error, ' is already declared as sequential ]'),
|
|
|
|
nl(user_error)
|
|
|
|
;
|
2003-12-04 18:13:04 +00:00
|
|
|
X is F /\ 0x1991FC80, X =:= 0, !, '$sequential'(T)
|
2001-04-09 20:54:03 +01:00
|
|
|
;
|
|
|
|
write(user_error, '[ Error: '),
|
2001-11-15 00:01:43 +00:00
|
|
|
write(user_error, M:A/N),
|
2001-04-09 20:54:03 +01:00
|
|
|
write(user_error, ' cannot be declared as parallel ]'),
|
|
|
|
nl(user_error),
|
|
|
|
fail
|
|
|
|
).
|
2001-11-15 00:01:43 +00:00
|
|
|
'$parallel_directive'(X,_) :- write(user_error, '[ Error: '),
|
2001-04-09 20:54:03 +01:00
|
|
|
write(user_error, X),
|
|
|
|
write(user_error, ' is an invalid argument to parallel/1 ]'),
|
|
|
|
nl(user_error),
|
|
|
|
fail.
|
|
|
|
|
|
|
|
|
|
|
|
%
|
|
|
|
% do not try to run consult in the parallel system.
|
|
|
|
%
|
|
|
|
'$parallelizable'(_) :-
|
2007-11-26 23:43:10 +00:00
|
|
|
nb_getval('$consulting_file',S), S\=[], !, fail.
|
2001-04-09 20:54:03 +01:00
|
|
|
'$parallelizable'((G1,G2)) :- !,
|
|
|
|
'$parallelizable'(G1),
|
|
|
|
'$parallelizable'(G2).
|
|
|
|
'$parallelizable'((G1;G2)) :- !,
|
|
|
|
'$parallelizable'(G1),
|
|
|
|
'$parallelizable'(G2).
|
|
|
|
'$parallelizable'((G1|G2)) :- !,
|
|
|
|
'$parallelizable'(G1),
|
|
|
|
'$parallelizable'(G2).
|
|
|
|
'$parallelizable'((G1->G2)) :- !,
|
|
|
|
'$parallelizable'(G1),
|
|
|
|
'$parallelizable'(G2).
|
|
|
|
'$parallelizable'([]) :- !, fail.
|
|
|
|
'$parallelizable'([_|_]) :- !, fail.
|
|
|
|
'$parallelizable'(consult(_)) :- !, fail.
|
|
|
|
'$parallelizable'(reconsult(_)) :- !, fail.
|
|
|
|
'$parallelizable'(compile(_)) :- !, fail.
|
|
|
|
'$parallelizable'(use_module(_)) :- !, fail.
|
|
|
|
'$parallelizable'(_).
|
|
|
|
|
|
|
|
|
|
|
|
|