void valid_ints( int eqdimpar, RAT *eqarpar, int neqpar,int eqrlpar, int iedimpar, RAT *iearpar, int niepar, int ierlpar, char *fname ) { RAT *eqsum = (RAT *)0; RAT *iesum = (RAT *)0; fprintf (prt,"computing all valid integral points "); fflush(prt); /* 17.01.1994: include logging on file porta.log */ porta_log( "computing all valid integral points "); fflush(logfile); if (!lowbds || !upbds) msg( "\nno bounds are given", "", 0 ); for (eqdim = 0 ; eqdim < eqdimpar; eqdim++) if (lowbds[eqdim] > upbds[eqdim]) msg("lower bound greater than upper bound", "", 0); neq = neqpar; eqdim = eqdimpar; eqar = eqarpar; eqrl = eqrlpar; ubea = eqar+neq*eqrl; nie = niepar; iedim = iedimpar; iear = iearpar; ierl = ierlpar; ubia = iear+nie*ierl; fname[strlen(fname)-4] = '\0'; strcat(fname,".poi"); fp = wfopen(fname); fprintf(fp,"DIM =%3d\n\nCONV_SECTION\n",dim); integ = (int *) allo(integ,0,eqdim*sizeof(int)); reknum = intnum = 0; eqsum = (RAT *) RATallo(eqsum,0,(1+neq)*(eqdim+1)); iesum = (RAT *) RATallo(iesum,0,(1+nie)*(iedim+1)); integ_rekurs(eqsum,iesum,0); #if defined WIN32 || defined __CYGWIN32__ || defined __APPLE__ free(integ); #else // WIN32 cfree(integ); #endif // WIN32 fprintf(fp,"\nEND\n"); fclose(fp); fprintf(prt,"\n\nnumber of valid integral points : %i\n\n",intnum); fprintf(prt,"integral points written to file %s\n",fname); /* 17.01.1994: include logging on file porta.log */ porta_log( "\n\nnumber of valid integral points : %i\n\n",intnum); porta_log( "integral points written to file %s\n",fname); }
int main() { int **b; int i; for(i=0;i<10000;i++) { b=allo(); free(b); } return 0; }
int main() { int idx, idx2; int cnt[10] = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100}; srandom(time(NULL)); /* reset counter */ TotalAlloc = 0; TotalFree = 0; NullAlloc = 0; NullFree = 0; TotalAllocSize = 0; TITLE(Test Start); for (idx = 0 ; idx < DESTROY_COUNT ; idx ++) { int i; /* Init mm spool */ for (i = 0 ; i < 10 ; i ++) cnt [i] = (random() % 100); /* Init */ upnp_mm_init(cnt); SUBSUBTITLE(Start Round......); /* Dump */ upnp_mm_dump(); for (idx2 = 0 ; idx2 < REINIT_COUNT ; idx2 ++) { int i; SUBSUBTITLE(Reinit mm system......); bzero(my_alloc, (sizeof(void *) * MAX_ALLOC)); for (i = 0 ; i < MAX_TEST_COUNT ; i ++) { allo(); callo(); reallo(); sdup(); hybrid(); ran(); } /* Reinit */ upnp_mm_reinit(); } SUBSUBTITLE(One Round Complete......); /* Dump */ upnp_mm_dump(); /* Destroy */ upnp_mm_destroy(); } /* Dump counter */ TITLE(Test Complete); printf("\tTotalAlloc\t(Total Allocation Count)\t:\t%u\n", TotalAlloc); printf("\tTotalFree\t(Total Free Count)\t\t:\t%u\n", TotalFree); printf("\tNullAlloc\t(Total Count of out-of-memory)\t:\t%u", NullAlloc); if (NullAlloc) printf("\t(This COULD cause daemon stop!)\n"); else printf("\n"); printf("\tNullFree\t(Free with the NULL pointer)\t:\t%u\n", NullFree); printf("\tTotalAllocSize\t(Total Allocated memory size)\t:\t%u\n", TotalAllocSize); printf("\n"); return 0; }
/*****************************************************************/ /* * n is the number of elements in the vector "old". * p is some fraction, e.g. the right hand side of the inequality * represented by "old". * If p != 0, then "new" = "old"/p. * If p == 0, then all numerators of "old" are divided by their gcd, * and all denominators of "old" are divided by their gcd. * The result is stored in "new" (not in "old"). * Fractions like 0/12 are converted to 0/1. */ { int *x; int m=0,ii,i,j,r; x = (int *) allo(CP 0,0,U n*sizeof(int)); for(i=0; i<n; i++) x[i] = 0; /* * Divide the elements of list "old" by "|p|", * and store the result in list "new" */ if (p->num != 0) { var[0].den.i = abs(p->num); var[0].num = p->den.i ; for (i = n; i; i--) (*RAT_mul)(*old++,var[0],new++); }
int read_input_file( char *fname, FILE *outfp, int *dim, RAT **ar, int *nel_ar, char *intkey1, int **intli1, char *intkey2, int **intli2, char *RATkey1, RAT **RATli1 ) /*****************************************************************/ /* * Read the dimension "dim", * a table "ar" of points (in case of a .poi file), * or of inequalities (in case of a .ieq file), * a line "intli1" of integers occurring after keyword "intkey1", * a line "intli2" of integers occurring after keyword "intkey2", * a line "RATli1" of rationals occurring after keyword "RATkey1". * "ar6" is a point that is output in the VALID section in the .ieq file. * * Change by M.S. 5.6.92: * If "outfp" exists (e.g. if is_set(Sort)), * copy the input file into outfp, * except for the INEQUALITIES_SECTION, the CONV_SECTION, and the CONE_SECTION, * and END. */ { int i,j,ieqs,nonempty,arrows=0,arrowl=0,cone = 0,conv = 0,line; int *hip; char *in,*end = "END", equalities[22], convstr[13],conestr[13],key_eli[18],key_val[6],key_low[13],key_upp[13], *comm = "COMMENT" ; char scanned_inline[MAXLINE]; char in_line[MAXLINE]; RAT val; line = 0; strcpy (equalities,"INEQUALITIES_SECTION"); strcpy (convstr,"CONV_SECTION"); strcpy (conestr,"CONE_SECTION"); strcpy (key_eli,"ELIMINATION_ORDER"); strcpy (key_val,"VALID"); strcpy (key_upp,"UPPER_BOUNDS"); strcpy (key_low,"LOWER_BOUNDS"); fp = fopen(fname,"r"); if (fp == 0) msg( "%s : no such file", fname, 0 ); /* * Read the first line into string "in_line". Leading blanks are skipped. * In_Line should start with "DIM=". */ do { nonempty = get_line(fp,fname,in_line,&line ); } while (!nonempty); scan_line(&val,3,0,line,fname,in_line,scanned_inline); if (strncmp(scanned_inline,"DIM=",4) == 0) { in = scanned_inline+4; *dim = atoi(in); if (*dim == 0) msg("%s, line %i : dimension error",fname,line); if (outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } ieqs = (strcmp(fname+strlen(fname)-4,".ieq") == 0); if( ieqs ) { equa = ineq = 0; convstr[0] = conestr[0] = '\n'; arrowl = *dim+2; if (!strcmp(intkey1,"ELIMINATION_ORDER") || !strcmp(intkey2,"ELIMINATION_ORDER")) key_eli[0] = '\n'; if (!strcmp(intkey1,"LOWER_BOUNDS") || !strcmp(intkey2,"LOWER_BOUNDS")) key_low[0] = '\n'; if (!strcmp(intkey1,"UPPER_BOUNDS") || !strcmp(intkey2,"UPPER_BOUNDS")) key_upp[0] = '\n'; if (!strcmp(RATkey1,"VALID")) key_val[0] = '\n'; } else { /* * key_eli, key_low, key_upp, and key_val are set to 0, * if they already appear as input parameters to this subroutine. * In this way, if e.g. the keyword "VALID" is encountered twice in the * input file, an error message is produced. * "convstr" and "conestr" are set to "\n", * so that the keywords "CONV_SECTION" and "CONE_SECTION" * result in an error message, if they appear in the .ieq file. */ cone = conv = 0; key_val[0] = key_upp[0] = key_low[0] = key_eli[0] = equalities[0] = '\n'; arrowl = *dim+1; } /* * ar6 is initialized to 0. * It is overwritten by a point in the CONV_SECTION, * or by a point in the VALID section. */ ar6 = (RAT *) RATallo(ar6,0,*dim); for (j = 0; j < *dim; j++) { ar6[j].num = 0; ar6[j].den.i = 1; } /* Read the next line into string "in_line" and scan it */ nonempty = get_line(fp,fname,in_line,&line ); scan_line(&val,3,0,line,fname,in_line,scanned_inline); do { if (!nonempty) { if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } else if (strncmp(scanned_inline,comm,7) == 0) { /* * Overread keyword COMMENT and all following lines, * until the next keyword (i.e. one of the arguments of nstrcmp() ) * is encountered. */ do { if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } while (nstrcmp(scanned_inline,conestr,equalities,end, intkey1,intkey2,RATkey1,convstr) || !nonempty); } else if (strcmp(scanned_inline,RATkey1) == 0) { /* * If the keyword RATkey1 is encountered, * read the next line of "dim" rationals into array RATli1. * RATkey1 is "VALID" for "traf *.ieq" applications. */ if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } /* When calling read_input_file, RATkey1 is always assigned to a const argument (string). Therefore it isn't allowed to assign new values to this argument. By the way, this statement causes a bus error on some architectures like the HP! 18.01.1994, Andreas Loebel RATkey1[0] = '\n'; *RATli1 = (RAT *) RATallo(*RATkey1,0,*dim); */ *RATli1 = (RAT *) RATallo(CP 0,0,*dim); do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line(*RATli1,1,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } else if (strcmp(scanned_inline,key_val) == 0) { /* * keyval[0] == "VALID", iff * Ratkey1 was not "VALID" at the start of function read_input_file() * Otherwise keyval[0] = '\n' * --> "VALID" is accepted as a keyword at most once. */ if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } key_val[0] = '\n'; /* * Change by M.S.: "ar6" was already allocated earlier, * and it is never freed in this loop. ar6 = (RAT *) RATallo(ar6,0,*dim); */ do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line(ar6,1,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); /* change by M.S. 31.5.92: * "ar6" is also used when reading the CONV_SECTION, so don't free it. ar6 = (RAT *) RATallo(ar6,*dim,0); */ } else if (strcmp(scanned_inline,intkey1) == 0) { if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } intkey1[0] = '\n'; *intli1 = (int *) allo(*intli1,0,*dim*sizeof(int)); do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line((RAT *)*intli1,2,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } else if (strcmp(scanned_inline,intkey2) == 0) { if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } intkey2[0] = '\n'; *intli2 = (int *) allo(*intli2,0,*dim*sizeof(int)); do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line((RAT *)*intli2,2,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); } else if (!strcmp(scanned_inline,key_eli) || !strcmp(scanned_inline,key_low) || !strcmp(scanned_inline,key_upp) ) { /* * array "hip" is just a temporary array. */ if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } if (!strcmp(scanned_inline,key_eli)) key_eli[0] = '\n'; if (!strcmp(scanned_inline,key_low)) key_low[0] = '\n'; if (!strcmp(scanned_inline,key_upp)) key_upp[0] = '\n'; hip = (int *) allo(CP 0,0,*dim*sizeof(int)); do { nonempty = get_line(fp,fname,in_line,&line); if(outfp) { fprintf(outfp,"%s",in_line); /* 17.01.1994: include logging on file porta.log */ porta_log( "%s",in_line); } } while (!nonempty); scan_line((RAT *)hip,2,*dim,line,fname,in_line,scanned_inline); nonempty = get_line(fp,fname,in_line,&line); scan_line(&val,3,0,line,fname,in_line,scanned_inline); hip = (int *) allo(hip,*dim*sizeof(int),0); } else if (strcmp(scanned_inline, convstr) == 0) { /* * Read the CONV_SECTION into array "ar". * For all points j=1,...,conv in the CONV_SECTION, * ar[j-1][dim] is set to 1. * "arrowl" was set to dim+1 earlier. */ convstr[0] = '\n'; *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; do { nonempty = get_line(fp,fname,in_line,&line); } while (!nonempty); while (scan_line(*ar+(conv+cone)*arrowl,0,*dim,line,fname, in_line,scanned_inline)) { (*ar+(conv+cone)*arrowl+*dim)->num = 1; if (conv+cone+2 > arrows) { *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; } do { nonempty = get_line(fp,fname,in_line,&line); } while (!nonempty); conv++; } /* repeat the last point in array "ar6" */ for (j = 0; j < *dim; j++) ar6[j] = (*ar+(conv+cone-1)*arrowl)[j]; } else if ((strcmp(scanned_inline, conestr) == 0)) { /* * Read the CONE_SECTION * ar[j-1][dim] is initialized by RATallo to 0. */ conestr[0] = '\n'; *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; do { nonempty = get_line(fp,fname,in_line,&line); } while (!nonempty); while (scan_line(*ar+(conv+cone)*arrowl,0,*dim,line,fname, in_line,scanned_inline)) { if (conv+cone+2 > arrows) { *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; } do { nonempty = get_line(fp,fname,in_line,&line); } while (!nonempty); cone++; } } else if ( (strcmp(scanned_inline, equalities) == 0)) { /* * Read the INEQUALITIES_SECTION * "arrowl" was set to dim+2 earlier. */ equalities[0] = '\n'; *ar = (RAT *) RATallo(*ar,arrows*arrowl, (arrows+INCR_INSYS_ROW)*arrowl); arrows += INCR_INSYS_ROW; read_eqie(ar,*dim,&equa,&ineq,&arrows,&line, fname,in_line,scanned_inline); nonempty = 1; } else if (strcmp(scanned_inline,end) == 0) { i = (ieqs) ? equa+ineq : conv+cone; *nel_ar = (i+1)*arrowl; *ar = (RAT *) RATallo(*ar,arrows*arrowl,*nel_ar); fclose(fp); fprintf(prt,"input file %s o.k.\n",fname); fprintf(prt, "dimension : %4i \n",*dim); /* 17.01.1994: include logging on file porta.log */ porta_log( "input file %s o.k.\n",fname); porta_log( "dimension : %4i \n",*dim); if (ieqs) { fprintf(prt,"number of equations : %4i \n",equa); fprintf(prt,"number of inequalities : %4i \n\n",ineq); /* 17.01.1994: include logging on file porta.log */ porta_log( "number of equations : %4i \n",equa); porta_log( "number of inequalities : %4i \n\n",ineq); } else { fprintf(prt,"number of cone-points : %4i \n",cone); fprintf(prt,"number of conv-points : %4i \n\n",conv); /* 17.01.1994: include logging on file porta.log */ porta_log( "number of cone-points : %4i \n",cone); porta_log( "number of conv-points : %4i \n\n",conv); } return (i); } else msg("%s, line %i : invalid format",fname,line); } while (1); }
void writepoionie( FILE *fp, int fineq, int lineq, int points, int poi_ieq ) { int i,ie,j,k,out,kk,*sumie,max; char *colstr = "POINTS",*rowstr = "INEQS ",*h; if (poi_ieq) { h = colstr; colstr = rowstr; rowstr = h; } sumie = (int*) allo(CP NULL,0,U points*sizeof(int),0); for (i = 0 ; i < points; i++) sumie[i] = 0; fprintf(fp,"\nstrong validity table : \n"); for (j = 0 ; j < 8; j++) { switch(j) { case 0 : fprintf(fp,"\\ %c |",*colstr++);break; case 1 : fprintf(fp," \\ %c |",*colstr++); break; case 2 : fprintf(fp,"%c \\ %c |",*rowstr++,*colstr++);break; case 3 : fprintf(fp," %c \\ %c | ",*rowstr++,*colstr++);break; case 4 : fprintf(fp," %c \\ %c |",*rowstr++,*colstr++);break; case 5 : fprintf(fp," %c \\ %c |",*rowstr++,*colstr++);break; case 6 : fprintf(fp," %c \\ |",*rowstr++);break; case 7 : fprintf(fp," %c \\ |",*rowstr++);break; } /* fprintf(fp,"\n"); */ if (j != 3) { for (i = 0; i < points+(points-1)/5+2;i++) fprintf(fp," "); fprintf(fp,"|\n"); } else { for (i = 1; i <= points; i += 5) fprintf(fp,"%-*d",(points/(i+5)) ? 6 : ((points%5) ? points%5+1: 6),i); fprintf(fp,"| #\n"); } } for (i = 0; i < points+(points-1)/5+16;i++) fprintf(fp,"-"); fprintf(fp,"\n"); for (i = fineq, ie = 0; i < lineq; i++, ie++) { fprintf(fp,"%-9d| ",ie+1); writemark( fp, porta_list[i]->mark, points, sumie ); } fprintf(fp," "); for (i = 0; i < points+(points-1)/5+6;i++) fprintf(fp,"."); fprintf(fp,"\n"); max = 0; for (i = 0; i < points; i++) if (sumie[i] > max) max = sumie[i]; for (j = 0; max > 0; max /= 10,j++) { (j == 0) ? fprintf(fp,"# | ") : fprintf(fp," | "); for (i = 0; i < points; i++) { if ((out = sumie[i]) > 0) { for (k = 10000; sumie[i]/k == 0 && k>9; k /= 10); for (kk = 0; kk < j && k > 9;kk++, k /= 10) out = out%k; fprintf(fp,"%d",out/k); if (k == 1) sumie[i] = -1 ; } else fprintf(fp," "); if ((i+1)%5 == 0) fprintf(fp," "); } fprintf(fp,"\n"); } fprintf(fp,"\n"); #if defined WIN32 || defined __CYGWIN32__ free(sumie); #else // WIN32 free(sumie); #endif }