fix parallel_findall/3
This commit is contained in:
parent
72f79b8c4f
commit
1fe86ba2b3
@ -26,7 +26,6 @@
|
|||||||
#define THREADS_INDIRECT_BUCKETS ((MAX_THREADS - THREADS_DIRECT_BUCKETS) / THREADS_DIRECT_BUCKETS) /* (1024 - 32) / 32 = 31 */
|
#define THREADS_INDIRECT_BUCKETS ((MAX_THREADS - THREADS_DIRECT_BUCKETS) / THREADS_DIRECT_BUCKETS) /* (1024 - 32) / 32 = 31 */
|
||||||
#define THREADS_NUM_BUCKETS (THREADS_DIRECT_BUCKETS + THREADS_INDIRECT_BUCKETS)
|
#define THREADS_NUM_BUCKETS (THREADS_DIRECT_BUCKETS + THREADS_INDIRECT_BUCKETS)
|
||||||
#define TG_ANSWER_SLOTS 20
|
#define TG_ANSWER_SLOTS 20
|
||||||
#define MAX_LENGTH_ANSWER 1000
|
|
||||||
#define MAX_BRANCH_DEPTH 1000
|
#define MAX_BRANCH_DEPTH 1000
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
|
@ -165,9 +165,9 @@ void Yap_init_global_optyap_data(int max_table_size, int n_workers, int sch_loop
|
|||||||
|
|
||||||
|
|
||||||
void Yap_init_local_optyap_data(int wid) {
|
void Yap_init_local_optyap_data(int wid) {
|
||||||
#ifdef THREADS_CONSUMER_SHARING
|
#if defined(YAPOR_THREADS) || defined(THREADS_CONSUMER_SHARING)
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
#endif /* THREADS_CONSUMER_SHARING */
|
#endif /* YAPOR_THREADS || THREADS_CONSUMER_SHARING */
|
||||||
|
|
||||||
#if defined(TABLING) && (defined(YAPOR) || defined(THREADS))
|
#if defined(TABLING) && (defined(YAPOR) || defined(THREADS))
|
||||||
/* local data related to memory management */
|
/* local data related to memory management */
|
||||||
|
@ -57,6 +57,7 @@ static Int p_yapor_start( USES_REGS1 );
|
|||||||
static Int p_yapor_workers( USES_REGS1 );
|
static Int p_yapor_workers( USES_REGS1 );
|
||||||
static Int p_worker( USES_REGS1 );
|
static Int p_worker( USES_REGS1 );
|
||||||
static Int p_parallel_new_answer( USES_REGS1 );
|
static Int p_parallel_new_answer( USES_REGS1 );
|
||||||
|
static Int p_parallel_get_answers( USES_REGS1 );
|
||||||
static Int p_show_statistics_or( USES_REGS1 );
|
static Int p_show_statistics_or( USES_REGS1 );
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
#if defined(YAPOR) && defined(TABLING)
|
#if defined(YAPOR) && defined(TABLING)
|
||||||
@ -66,9 +67,6 @@ static Int p_get_optyap_statistics( USES_REGS1 );
|
|||||||
|
|
||||||
#ifdef YAPOR
|
#ifdef YAPOR
|
||||||
static inline realtime current_time(void);
|
static inline realtime current_time(void);
|
||||||
static inline int parallel_new_answer_putchar(int sno, int ch);
|
|
||||||
static inline void show_answers(void);
|
|
||||||
static inline void answer_to_stdout(char *answer);
|
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
|
|
||||||
#ifdef TABLING
|
#ifdef TABLING
|
||||||
@ -107,12 +105,6 @@ static inline struct page_statistics show_statistics_table_subgoal_answer_frames
|
|||||||
** Macros & Declarations **
|
** Macros & Declarations **
|
||||||
************************************/
|
************************************/
|
||||||
|
|
||||||
#ifdef YAPOR
|
|
||||||
#define TIME_RESOLUTION 1000000
|
|
||||||
static int length_answer;
|
|
||||||
static qg_ans_fr_ptr actual_answer;
|
|
||||||
#endif /* YAPOR */
|
|
||||||
|
|
||||||
struct page_statistics {
|
struct page_statistics {
|
||||||
#ifdef USE_PAGES_MALLOC
|
#ifdef USE_PAGES_MALLOC
|
||||||
long pages_allocated; /* same as struct pages (opt.structs.h) */
|
long pages_allocated; /* same as struct pages (opt.structs.h) */
|
||||||
@ -230,6 +222,7 @@ void Yap_init_optyap_preds(void) {
|
|||||||
Yap_InitCPred("$c_yapor_workers", 1, p_yapor_workers, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
Yap_InitCPred("$c_yapor_workers", 1, p_yapor_workers, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||||
Yap_InitCPred("$c_worker", 0, p_worker, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
Yap_InitCPred("$c_worker", 0, p_worker, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||||
Yap_InitCPred("$c_parallel_new_answer", 1, p_parallel_new_answer, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
Yap_InitCPred("$c_parallel_new_answer", 1, p_parallel_new_answer, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||||
|
Yap_InitCPred("$c_parallel_get_answers", 1, p_parallel_get_answers, SafePredFlag|SyncPredFlag|HiddenPredFlag);
|
||||||
Yap_InitCPred("or_statistics", 1, p_show_statistics_or, SafePredFlag|SyncPredFlag);
|
Yap_InitCPred("or_statistics", 1, p_show_statistics_or, SafePredFlag|SyncPredFlag);
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
#if defined(YAPOR) && defined(TABLING)
|
#if defined(YAPOR) && defined(TABLING)
|
||||||
@ -243,7 +236,6 @@ void Yap_init_optyap_preds(void) {
|
|||||||
void finish_yapor(void) {
|
void finish_yapor(void) {
|
||||||
GLOBAL_execution_time = current_time() - GLOBAL_execution_time;
|
GLOBAL_execution_time = current_time() - GLOBAL_execution_time;
|
||||||
GLOBAL_parallel_mode = PARALLEL_MODE_ON;
|
GLOBAL_parallel_mode = PARALLEL_MODE_ON;
|
||||||
/* show_answers(); */
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
@ -727,12 +719,11 @@ static Int p_worker( USES_REGS1 ) {
|
|||||||
|
|
||||||
|
|
||||||
static Int p_parallel_new_answer( USES_REGS1 ) {
|
static Int p_parallel_new_answer( USES_REGS1 ) {
|
||||||
|
qg_ans_fr_ptr actual_answer;
|
||||||
or_fr_ptr leftmost_or_fr;
|
or_fr_ptr leftmost_or_fr;
|
||||||
|
|
||||||
length_answer = 0;
|
|
||||||
ALLOC_QG_ANSWER_FRAME(actual_answer);
|
ALLOC_QG_ANSWER_FRAME(actual_answer);
|
||||||
Yap_plwrite(ARG1, parallel_new_answer_putchar, 4, 1200);
|
AnsFr_answer(actual_answer) = Deref(ARG1);
|
||||||
AnsFr_answer(actual_answer)[length_answer] = 0;
|
|
||||||
AnsFr_next(actual_answer) = NULL;
|
AnsFr_next(actual_answer) = NULL;
|
||||||
leftmost_or_fr = CUT_leftmost_or_frame();
|
leftmost_or_fr = CUT_leftmost_or_frame();
|
||||||
LOCK_OR_FRAME(leftmost_or_fr);
|
LOCK_OR_FRAME(leftmost_or_fr);
|
||||||
@ -747,6 +738,26 @@ static Int p_parallel_new_answer( USES_REGS1 ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static Int p_parallel_get_answers( USES_REGS1 ){
|
||||||
|
Term t = TermNil;
|
||||||
|
|
||||||
|
if (OrFr_qg_solutions(LOCAL_top_or_fr)) {
|
||||||
|
qg_ans_fr_ptr aux_answer1, aux_answer2;
|
||||||
|
aux_answer1 = SolFr_first(OrFr_qg_solutions(LOCAL_top_or_fr));
|
||||||
|
while (aux_answer1) {
|
||||||
|
t = MkPairTerm(AnsFr_answer(aux_answer1), t);
|
||||||
|
aux_answer2 = aux_answer1;
|
||||||
|
aux_answer1 = AnsFr_next(aux_answer1);
|
||||||
|
FREE_QG_ANSWER_FRAME(aux_answer2);
|
||||||
|
}
|
||||||
|
FREE_QG_SOLUTION_FRAME(OrFr_qg_solutions(LOCAL_top_or_fr));
|
||||||
|
OrFr_qg_solutions(LOCAL_top_or_fr) = NULL;
|
||||||
|
}
|
||||||
|
Yap_unify(ARG1, t);
|
||||||
|
return (TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static Int p_show_statistics_or( USES_REGS1 ) {
|
static Int p_show_statistics_or( USES_REGS1 ) {
|
||||||
struct page_statistics stats;
|
struct page_statistics stats;
|
||||||
long bytes, total_bytes = 0;
|
long bytes, total_bytes = 0;
|
||||||
@ -1029,95 +1040,16 @@ static Int p_get_optyap_statistics( USES_REGS1 ) {
|
|||||||
|
|
||||||
#ifdef YAPOR
|
#ifdef YAPOR
|
||||||
static inline realtime current_time(void) {
|
static inline realtime current_time(void) {
|
||||||
|
#define TIME_RESOLUTION 1000000
|
||||||
|
struct timeval tempo;
|
||||||
|
gettimeofday(&tempo, NULL);
|
||||||
|
return ((realtime)tempo.tv_sec + (realtime)tempo.tv_usec / TIME_RESOLUTION);
|
||||||
/* to get time as Yap */
|
/* to get time as Yap */
|
||||||
/*
|
/*
|
||||||
double now, interval;
|
double now, interval;
|
||||||
Yap_cputime_interval(&now, &interval);
|
Yap_cputime_interval(&now, &interval);
|
||||||
return ((realtime)now);
|
return ((realtime)now);
|
||||||
*/
|
*/
|
||||||
struct timeval tempo;
|
|
||||||
gettimeofday(&tempo, NULL);
|
|
||||||
return ((realtime)tempo.tv_sec + (realtime)tempo.tv_usec / TIME_RESOLUTION);
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline int parallel_new_answer_putchar(int sno, int ch) {
|
|
||||||
AnsFr_answer(actual_answer)[length_answer++] = ch;
|
|
||||||
return ch;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline void show_answers(void) {
|
|
||||||
CACHE_REGS
|
|
||||||
int i, answers = 0;
|
|
||||||
if (OrFr_qg_solutions(LOCAL_top_or_fr)) {
|
|
||||||
qg_ans_fr_ptr aux_answer1, aux_answer2;
|
|
||||||
aux_answer1 = SolFr_first(OrFr_qg_solutions(LOCAL_top_or_fr));
|
|
||||||
while (aux_answer1) {
|
|
||||||
answer_to_stdout(AnsFr_answer(aux_answer1));
|
|
||||||
aux_answer2 = aux_answer1;
|
|
||||||
aux_answer1 = AnsFr_next(aux_answer1);
|
|
||||||
FREE_QG_ANSWER_FRAME(aux_answer2);
|
|
||||||
answers++;
|
|
||||||
}
|
|
||||||
FREE_QG_SOLUTION_FRAME(OrFr_qg_solutions(LOCAL_top_or_fr));
|
|
||||||
OrFr_qg_solutions(LOCAL_top_or_fr) = NULL;
|
|
||||||
}
|
|
||||||
switch(answers) {
|
|
||||||
case 0:
|
|
||||||
Sfprintf(Serror, "[ no answers found");
|
|
||||||
break;
|
|
||||||
case 1:
|
|
||||||
Sfprintf(Serror, "[ 1 answer found");
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
Sfprintf(Serror, "[ %d answers found", answers);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
Sfprintf(Serror, " (in %f seconds) ]\n\n", GLOBAL_execution_time);
|
|
||||||
Sflush(Serror);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static inline void answer_to_stdout(char *answer) {
|
|
||||||
int length_answer = 0, length_output = 0, caracter, list, par_rectos;
|
|
||||||
char output[MAX_LENGTH_ANSWER];
|
|
||||||
while (1) {
|
|
||||||
length_answer += 2;
|
|
||||||
while (answer[length_answer] != ']') {
|
|
||||||
length_answer++;
|
|
||||||
caracter = 0;
|
|
||||||
while (answer[length_answer] != ',' && answer[length_answer] != ']')
|
|
||||||
caracter = caracter * 10 + answer[length_answer++] - '0';
|
|
||||||
output[length_output++] = caracter;
|
|
||||||
}
|
|
||||||
length_answer++;
|
|
||||||
output[length_output++] = ' ';
|
|
||||||
output[length_output++] = '=';
|
|
||||||
output[length_output++] = ' ';
|
|
||||||
if (answer[length_answer++] == ',') {
|
|
||||||
list = 1;
|
|
||||||
output[length_output++] = '[';
|
|
||||||
} else list = 0;
|
|
||||||
par_rectos = 1;
|
|
||||||
while (1) {
|
|
||||||
if (answer[length_answer] == '[') par_rectos++;
|
|
||||||
else if (answer[length_answer] == ']' && --par_rectos == 0) break;
|
|
||||||
output[length_output++] = answer[length_answer++];
|
|
||||||
}
|
|
||||||
if (list) output[length_output++] = ']';
|
|
||||||
if (answer[++length_answer] != ']') {
|
|
||||||
output[length_output++] = ' ';
|
|
||||||
output[length_output++] = ';';
|
|
||||||
output[length_output++] = ' ';
|
|
||||||
}
|
|
||||||
else break;
|
|
||||||
}
|
|
||||||
output[length_output] = 0;
|
|
||||||
Sfprintf(Serror, " %s\n", output);
|
|
||||||
Sflush(Serror);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
#endif /* YAPOR */
|
#endif /* YAPOR */
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ typedef struct query_goal_solution_frame{
|
|||||||
** ---------------------------------------- */
|
** ---------------------------------------- */
|
||||||
|
|
||||||
typedef struct query_goal_answer_frame{
|
typedef struct query_goal_answer_frame{
|
||||||
char answer[MAX_LENGTH_ANSWER];
|
Term answer;
|
||||||
struct query_goal_answer_frame *next;
|
struct query_goal_answer_frame *next;
|
||||||
} *qg_ans_fr_ptr;
|
} *qg_ans_fr_ptr;
|
||||||
|
|
||||||
|
13
pl/yapor.yap
13
pl/yapor.yap
@ -129,7 +129,9 @@ parallel_findall(Template,Goal,Answers) :-
|
|||||||
(
|
(
|
||||||
'$parallel_findall_query'(Template,Goal)
|
'$parallel_findall_query'(Template,Goal)
|
||||||
;
|
;
|
||||||
findall(X,'$parallel_findall_recorded'(X), Answers)
|
'$c_parallel_get_answers'(Refs),
|
||||||
|
'$parallel_findall_recorded'(Refs,Answers),
|
||||||
|
eraseall(parallel_findall)
|
||||||
).
|
).
|
||||||
parallel_findall(Template,Goal,Answers) :-
|
parallel_findall(Template,Goal,Answers) :-
|
||||||
findall(Template,Goal,Answers).
|
findall(Template,Goal,Answers).
|
||||||
@ -137,14 +139,15 @@ parallel_findall(Template,Goal,Answers) :-
|
|||||||
'$parallel_findall_query'(Template,Goal) :-
|
'$parallel_findall_query'(Template,Goal) :-
|
||||||
'$c_yapor_start',
|
'$c_yapor_start',
|
||||||
'$execute'(Goal),
|
'$execute'(Goal),
|
||||||
recordz(parallel_findall,Template,_),
|
recordz(parallel_findall,Template,Ref),
|
||||||
%% '$c_parallel_new_answer'(Ref),
|
'$c_parallel_new_answer'(Ref),
|
||||||
fail.
|
fail.
|
||||||
'$parallel_findall_query'(_,_).
|
'$parallel_findall_query'(_,_).
|
||||||
|
|
||||||
'$parallel_findall_recorded'(Template) :-
|
'$parallel_findall_recorded'([],[]) :- !.
|
||||||
|
'$parallel_findall_recorded'([Ref|Refs],[Template|Answers]):-
|
||||||
recorded(parallel_findall,Template,Ref),
|
recorded(parallel_findall,Template,Ref),
|
||||||
erase(Ref).
|
'$parallel_findall_recorded'(Refs,Answers).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user