From 0ca51355ce3a74f15ac294baea41721da21462af Mon Sep 17 00:00:00 2001 From: rzf Date: Sun, 8 Jun 2008 08:38:36 +0000 Subject: [PATCH] added memory profiling calls removed limit to 1000 variables imposed by createVars beause of the use of tha array of names of variables git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@2266 b08c6af1-5177-4d33-ba66-4b1c6b8b522a --- cplint/cplint.h | 2 +- cplint/cplint_yap.c | 39 ++++++++++++++++++++++++++------------- cplint/lpadclpbn.pl | 27 ++++++++++++++++++++++++--- cplint/lpadsld.pl | 36 ++++++++++++++++++++++++++++++++---- cplint/lpadvel.pl | 24 ++++++++++++++++++++++-- 5 files changed, 105 insertions(+), 23 deletions(-) diff --git a/cplint/cplint.h b/cplint/cplint.h index 8c78f5fb5..56e5491e8 100644 --- a/cplint/cplint.h +++ b/cplint/cplint.h @@ -29,7 +29,7 @@ typedef struct } variable; -void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar, char inames[1000][20]); +void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar,int create_dot, char inames[1000][20]); void createExpression(array_t * expression, YAP_Term t); void init_my_predicates(void); int compare(char *a, char *b); diff --git a/cplint/cplint_yap.c b/cplint/cplint_yap.c index 40f5d579b..a4a8fba6e 100644 --- a/cplint/cplint_yap.c +++ b/cplint/cplint_yap.c @@ -24,7 +24,7 @@ FILE *open_file (char *filename, const char *mode); void reverse(char s[]); static int compute_prob(void); -void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar, char inames[1000][20]) +void createVars(array_t * vars, YAP_Term t,DdManager * mgr, array_t * bVar2mVar,int create_dot, char inames[1000][20]) /* adds the boolean variables to the BDD and returns an array_t containing them (array_t is defined in the util library of glu) returns also the names of the variables to be used to save the ADD in dot format @@ -52,12 +52,15 @@ returns also the names of the variables to be used to save the ADD in dot format v.booleanVars=array_alloc(DdNode *,0); for (i=0;i format("Variables: ~p~n",[Var]), @@ -81,6 +85,7 @@ solve(GoalsList,Prob,CPUTime1,CPUTime2,WallTime1,WallTime2):- statistics(walltime,[_,WT2]), WallTime2 is WT2/1000 ; + print_mem, Prob=0.0, statistics(cputime,[_,CT1]), CPUTime1 is CT1/1000, @@ -89,9 +94,19 @@ solve(GoalsList,Prob,CPUTime1,CPUTime2,WallTime1,WallTime2):- CPUTime2 =0.0, statistics(walltime,[_,WT2]), WallTime2 =0.0 - ),!. - + ),!, + format(user_error,"~nMemory after inference~n",[]), + print_mem. +print_mem:- + statistics(global_stack,[GS,GSF]), + statistics(local_stack,[LS,LSF]), + statistics(heap,[HP,HPF]), + statistics(trail,[TU,TF]), + format(user_error,"~nGloabal stack used ~d execution stack free: ~d~n",[GS,GSF]), + format(user_error,"Local stack used ~d execution stack free: ~d~n",[LS,LSF]), + format(user_error,"Heap used ~d heap free: ~d~n",[HP,HPF]), + format(user_error,"Trail used ~d Trail free: ~d~n",[TU,TF]). find_deriv(GoalsList,Deriv):- solve(GoalsList,[],DerivDup), @@ -111,6 +126,7 @@ solve_cond(Goals,Evidence,Prob):- (setof(DerivE,find_deriv(Evidence,DerivE),LDupE)-> rem_dup_lists(LDupE,[],LE), (setof(DerivGE,find_deriv_GE(LE,Goals,DerivGE),LDupGE)-> + print_mem, rem_dup_lists(LDupGE,[],LGE), build_formula(LE,FormulaE,[],VarE), var2numbers(VarE,0,NewVarE), @@ -120,11 +136,15 @@ solve_cond(Goals,Evidence,Prob):- call_compute_prob(NewVarGE,FormulaGE,ProbGE), Prob is ProbGE/ProbE ; + print_mem, Prob=0.0 ) ; + print_mem, Prob=undefined - ). + ), + format(user_error,"~nMemory after inference~n",[]), + print_mem. /* sc(Goals,Evidence,Prob,Time1,Time2) compute the conditional probability of the list of goals Goals given the list of goals Evidence @@ -502,6 +522,14 @@ Termi is of the form [Factor1,...,Factorm] Factorj is of the form (Var,Value) where Var is the index of the multivalued variable Var and Value is the index of the value */ +build_formula([],[],Var,Var,C,C). + +build_formula([D|TD],[F|TF],VarIn,VarOut,C0,C1):- + length(D,NC), + C2 is C0+NC, + build_term(D,F,VarIn,Var1), + build_formula(TD,TF,Var1,VarOut,C2,C1). + build_formula([],[],Var,Var). build_formula([D|TD],[F|TF],VarIn,VarOut):- diff --git a/cplint/lpadvel.pl b/cplint/lpadvel.pl index bcdb79827..acde32d54 100644 --- a/cplint/lpadvel.pl +++ b/cplint/lpadvel.pl @@ -107,20 +107,36 @@ s(GL,P,CPUTime1,CPUTime2,WallTime1,WallTime2):- CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), WallTime1 is WT1/1000, + print_mem, convert_to_bn(CL,GL,[],P), statistics(cputime,[_,CT2]), CPUTime2 is CT2/1000, statistics(walltime,[_,WT2]), WallTime2 is WT2/1000 + ; statistics(cputime,[_,CT1]), CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), WallTime1 is WT1/1000, + print_mem, CPUTime2=0.0, WallTime2=0.0, P=0.0 - ). + ), + format(user_error,"~nMemory after inference~n",[]), + print_mem. + +print_mem:- + statistics(global_stack,[GS,GSF]), + statistics(local_stack,[LS,LSF]), + statistics(heap,[HP,HPF]), + statistics(trail,[TU,TF]), + format(user_error,"~nGloabal stack used ~d execution stack free: ~d~n",[GS,GSF]), + format(user_error,"Local stack used ~d execution stack free: ~d~n",[LS,LSF]), + format(user_error,"Heap used ~d heap free: ~d~n",[HP,HPF]), + format(user_error,"Trail used ~d Trail free: ~d~n",[TU,TF]). + /* sc(GoalsList,EvidenceList,Prob) compute the probability of a list of goals GoalsList given EvidenceList. Both lists can have variables, sc returns in @@ -136,6 +152,7 @@ sc(GL,GLC,P,CPUTime1,CPUTime2,WallTime1,WallTime2):- CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), WallTime1 is WT1/1000, + print_mem, (Undef=yes-> P=undef, CPUTime2=0.0, @@ -148,6 +165,7 @@ sc(GL,GLC,P,CPUTime1,CPUTime2,WallTime1,WallTime2):- WallTime2 is WT2/1000 ) ; + print_mem, statistics(cputime,[_,CT1]), CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), @@ -155,7 +173,9 @@ sc(GL,GLC,P,CPUTime1,CPUTime2,WallTime1,WallTime2):- CPUTime2=0.0, WallTime2=0.0, P=0.0 - ). + ), + format(user_error,"~nMemory after inference~n",[]), + print_mem. remove_head([],[]).