|
From: Fabrizio R. <rz...@us...> - 2008-06-08 08:38:40
|
Update of /cvsroot/yap/cplint In directory sc8-pr-cvs10.sourceforge.net:/tmp/cvs-serv17262 Modified Files: cplint.h cplint_yap.c lpadclpbn.pl lpadsld.pl lpadvel.pl Log Message: added memory profiling calls removed limit to 1000 variables imposed by createVars beause of the use of tha array of names of variables Index: cplint.h =================================================================== RCS file: /cvsroot/yap/cplint/cplint.h,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- cplint.h 5 Dec 2007 10:47:19 -0000 1.3 +++ cplint.h 8 Jun 2008 08:38:36 -0000 1.4 @@ -29,7 +29,7 @@ } 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); Index: cplint_yap.c =================================================================== RCS file: /cvsroot/yap/cplint/cplint_yap.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- cplint_yap.c 8 Nov 2007 11:32:14 -0000 1.2 +++ cplint_yap.c 8 Jun 2008 08:38:36 -0000 1.3 @@ -24,7 +24,7 @@ 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 @@ v.booleanVars=array_alloc(DdNode *,0); for (i=0;i<nVal;i++) { - strcpy(inames[b+i],"X"); - sprintf(numberVar,"%d",varIndex); - strcat(inames[b+i],numberVar); - strcat(inames[b+i],"_"); - sprintf(numberBit,"%d",i); - strcat(inames[b+i],numberBit); + if (create_dot) + { + strcpy(inames[b+i],"X"); + sprintf(numberVar,"%d",varIndex); + strcat(inames[b+i],numberVar); + strcat(inames[b+i],"_"); + sprintf(numberBit,"%d",i); + strcat(inames[b+i],numberBit); + } p=YAP_FloatOfTerm(YAP_HeadOfTerm(probTerm)); array_insert(double,v.probabilities,i,p); probTerm=YAP_TailOfTerm(probTerm); @@ -112,7 +115,7 @@ array_t * variables,* expression, * bVar2mVar; DdNode * function, * add; DdManager * mgr; - int nBVar,i,j,intBits; + int nBVar,i,j,intBits,create_dot; FILE * file; DdNode * array[1]; char * onames[1]; @@ -120,20 +123,29 @@ char * names[1000]; GHashTable * nodes; /* hash table that associates nodes with their probability if already computed, it is defined in glib */ - + Cudd_ReorderingType order; arg1=YAP_ARG1; arg2=YAP_ARG2; arg3=YAP_ARG3; arg4=YAP_ARG4; mgr=Cudd_Init(0,0,CUDD_UNIQUE_SLOTS,CUDD_CACHE_SLOTS,0); - variables=array_alloc(variable,0); bVar2mVar=array_alloc(int,0); - createVars(variables,arg1,mgr,bVar2mVar,inames); + create_dot=YAP_IntOfTerm(arg4); + createVars(variables,arg1,mgr,bVar2mVar,create_dot,inames); + Cudd_PrintInfo(mgr,stderr); /* automatic variable reordering, default method CUDD_REORDER_SIFT used */ - Cudd_AutodynEnable(mgr,CUDD_REORDER_SAME); + printf("status %d\n",Cudd_ReorderingStatus(mgr,&order)); + printf("order %d\n",order); + + Cudd_AutodynEnable(mgr,CUDD_REORDER_SAME); +/* Cudd_AutodynEnable(mgr, CUDD_REORDER_RANDOM_PIVOT); + printf("status %d\n",Cudd_ReorderingStatus(mgr,&order)); + printf("order %d\n",order); + printf("%d",CUDD_REORDER_RANDOM_PIVOT); +*/ expression=array_alloc(array_t *,0); @@ -143,8 +155,9 @@ /* the BDD build by retFunction is converted to an ADD (algebraic decision diagram) because it is easier to interpret and to print */ add=Cudd_BddToAdd(mgr,function); + Cudd_PrintInfo(mgr,stderr); - if (YAP_IntOfTerm(arg4)) + if (create_dot) /* if specified by the user, a dot file for the BDD is written to cpl.dot */ { nBVar=array_n(bVar2mVar); Index: lpadclpbn.pl =================================================================== RCS file: /cvsroot/yap/cplint/lpadclpbn.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- lpadclpbn.pl 2 May 2008 14:21:00 -0000 1.7 +++ lpadclpbn.pl 8 Jun 2008 08:38:36 -0000 1.8 @@ -115,6 +115,7 @@ CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), WallTime1 is WT1/1000, + print_mem, build_ground_lpad(L2,0,CL), convert_to_clpbn(CL,GL,LV,P), statistics(cputime,[_,CT2]), @@ -122,6 +123,7 @@ statistics(walltime,[_,WT2]), WallTime2 is WT2/1000 ; + print_mem, P=0.0, statistics(cputime,[_,CT1]), CPUTime1 is CT1/1000, @@ -130,7 +132,9 @@ CPUTime2 =0.0, statistics(walltime,[_,WT2]), WallTime2 =0.0 - ),!. + ),!, + format(user_error,"Memory after inference~n",[]), + print_mem. /* sc(GoalsList,EvidenceList,Prob) compute the probability of a list of goals GoalsList given EvidenceList. Both lists can have variables, sc returns in @@ -151,6 +155,7 @@ CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), WallTime1 is WT1/1000, + print_mem, build_ground_lpad(LD1,0,CL), convert_to_clpbn(CL,GL,LV,P,GLC), statistics(cputime,[_,CT2]), @@ -159,6 +164,8 @@ WallTime2 is WT2/1000 ; P=0.0, + print_mem, + format(user_error,"Porb 0~n",[]), statistics(cputime,[_,CT1]), CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), @@ -168,13 +175,18 @@ ) ; P=undef, + print_mem, statistics(cputime,[_,CT1]), CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), WallTime1 is WT1/1000, CPUTime2 =0.0, - WallTime2 =0.0 - ). + WallTime2 =0.0, + print_mem, + format(user_error,"Undef~n",[]) + ), + format(user_error,"Memory after inference~n",[]), + print_mem. remove_head([],[]). @@ -435,6 +447,15 @@ find_atoms_head([H:P|T],[H|TA],[P|TP]):- find_atoms_head(T,TA,TP). +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), Index: lpadsld.pl =================================================================== RCS file: /cvsroot/yap/cplint/lpadsld.pl,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- lpadsld.pl 2 May 2008 06:22:23 -0000 1.7 +++ lpadsld.pl 8 Jun 2008 08:38:36 -0000 1.8 @@ -68,7 +68,11 @@ CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), WallTime1 is WT1/1000, - build_formula(L,Formula,[],Var), + print_mem, + build_formula(L,Formula,[],Var,0,Conj), + length(L,ND), + length(Var,NV), + format(user_error,"Disjunctions :~d~nConjunctions: ~d~nVariables ~d~n",[ND,Conj,NV]), var2numbers(Var,0,NewVar), (setting(save_dot,true)-> format("Variables: ~p~n",[Var]), @@ -81,6 +85,7 @@ statistics(walltime,[_,WT2]), WallTime2 is WT2/1000 ; + print_mem, Prob=0.0, statistics(cputime,[_,CT1]), CPUTime1 is CT1/1000, @@ -89,9 +94,19 @@ 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 @@ (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 @@ 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 @@ 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):- Index: lpadvel.pl =================================================================== RCS file: /cvsroot/yap/cplint/lpadvel.pl,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- lpadvel.pl 30 Apr 2008 18:06:46 -0000 1.9 +++ lpadvel.pl 8 Jun 2008 08:38:36 -0000 1.10 @@ -107,20 +107,36 @@ 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 @@ CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), WallTime1 is WT1/1000, + print_mem, (Undef=yes-> P=undef, CPUTime2=0.0, @@ -148,6 +165,7 @@ WallTime2 is WT2/1000 ) ; + print_mem, statistics(cputime,[_,CT1]), CPUTime1 is CT1/1000, statistics(walltime,[_,WT1]), @@ -155,7 +173,9 @@ CPUTime2=0.0, WallTime2=0.0, P=0.0 - ). + ), + format(user_error,"~nMemory after inference~n",[]), + print_mem. remove_head([],[]). |