1 #include <limits.h>
2 
3 #ifdef  __DECC				/* use local "/tmp" on clusters: */
4 #define	USE_TMP_DIR	(1)		/* write aux-files to "/tmp"     */
5 #else
6 #define	USE_TMP_DIR	(0)
7 #endif
8 
9 #define	NUC_Nmax	256
10 
11 /*	on 32-bit architectures the GNU C compiler requires flags:	     *
12  *	-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE			     *
13  *	moreover, fseek and ftell have to be replaced by fseeko and ftello   */
14 #ifdef	_LARGEFILE_SOURCE
15 #define FTELL ftello
16 #define FSEEK fseeko
17 #else
18 #define FTELL ftell
19 #define FSEEK fseek
20 #endif
21 
22 /*	Target dimensions: 2^32 polytopes (unsigned!) ... 80GB/DB 	*/
23 /*	Along=64bit for polytopes except on bin-files::unsigned  	*/
24 /*	SL, self-mirror, NFnum[nv][nu]<2^32,  rec-depth?		*/
25 
26 #define MAX_REC_DEPTH	16383	 /* present "dirty fix" workes till 128^2-1 */
27 
28 
29 /* large files with gcc -> -D_FILE_OFFSET_BITS=64 and ftell -> ftello */
30 
31 #define	Along		long long	/* signed > addresses bytes DBpolys */
32 #define	UPint		unsigned	/* unsigned > #polys in RAM & aux   */
33 
34 #define FORCE_SAVE_TIME         (28800) /* real time for Aux-IO in seconds */
35 #define GOOD_SAVE_TIME          (21600) /* same at multiple of 1000 polys */
36 
37 #define	WRITE_DIM	4		/* File IO after weight if WD<= dim */
38 #define MIN_NEW		1		/* write file if MIN_NEW <= #newREF */
39 #define MIN_W_SAVE_TIME		(7200)  /* min real time for IO after poly */
40 
41 
42 #if	(POLY_Dmax < 5)
43 
44 #define	WATCHREF	(100000)	/* print some info after X refs    */
45 #define	SAVE_INC	(1000000)	/* save PolyNFlist after X refs    */
46 #define	CperR_MAX	(32)		/* 4*9 is safe for CY (average=10) */
47 #define	BASE_MAX	(905)		/* 191->317  184->338  218->464 */
48 #define BLOCK_LENGTH    (64)	     /* fraction of data base stored in RAM */
49 
50 #else
51 
52 #define	WATCHREF	(100000)	    /* print some info after X refs */
53 #define	SAVE_INC	(4000000)	    /* save PolyNFlist after X refs */
54 #define	CperR_MAX	(40)	    	/*  average is 35 for PolyDim=5  */
55 #define	BASE_MAX    (1631723)	/* 1631721 1 903 37947 233103 543907 815860 */
56 #define BLOCK_LENGTH    (128)	     /* fraction of data base stored in RAM */
57 
58 #endif
59 
60 #define subl_int	LLong
61 #define NB_MAX		POLY_Dmax*VERT_Nmax	/* an uneducated guess */
62 
63 #if(POLY_Dmax<5)
64 #define SL_Nmax		(65536)
65 #else
66 #define SL_Nmax		(300000)
67 #endif
68 
69 /* ====	    this should be o.k. (only change if you know what you do)  ==== */
70 
71 #define File_Ext_NCmax  5		 /* space for following FILE_EXTs */
72 #define	SAVE_FILE_EXT	".aux"		/* aux. O/I file for big allocation */
73 #define	TEMP_FILE_EXT	".tmp"	       /* undefine to directly overwrite aux */
74 #define	MOVE_SAVE_FILE	".bak"	      /* move SAVE-file after read  */
75 				 /* undef: risk data loss -> save disk space */
76 #undef	MOVE_SAVE_FILE		 /* undefine to directly overwrite SAVE file */
77 #undef	TEMP_FILE_EXT		 /* undefine to directly overwrite aux file */
78 
79 
80 #ifdef	MOVE_SAVE_FILE			/* consistency of these options */
81 #if	USE_TMP_DIR			/* is not yet implemented:      */
82 #error		Inconsistent options  USE_TMP_DIR  and  MOVE_SAVE_FILE !!!
83 #endif
84 #endif
85 
86 typedef struct {
87   Along nNF, nNM; int nSM,  /* #ref=2*nNF-nSelfMir.-nNoMir. */
88     d, v, nu, p, sl_nNF, sl_SM, sl_NM, sl_NB, list_num,
89     nV, nNUC[VERT_Nmax], nVmax, NUCmax, NFnum[VERT_Nmax][NUC_Nmax];
90   Along  Fv_pos[VERT_Nmax][NUC_Nmax]; UPint RAM_pos[VERT_Nmax][NUC_Nmax];
91   unsigned char *RAM_NF; long long NB;
92   FILE *Finfo, *Fsl, *Fv[VERT_Nmax];   }                           DataBase;
93 
94 typedef	struct {
95   Along nNF, nNM; int nSM;	    /* #ref=2*nNF-nSelfMir.-nNoMir. */
96   unsigned char nV, nNUC[VERT_Nmax+1], nVmax, NUCmax;
97   unsigned int NFnum[VERT_Nmax+1][NUC_Nmax]; long long NB;
98   unsigned char *NF[VERT_Nmax+1][NUC_Nmax],*NFli;}                FInfoList;
99 
100 typedef struct {unsigned int n, c; }  /* below n in NFptr, @NewNF[c] */	PEnt;
101 typedef struct {int n; PEnt pe; }     /* below #n in PEnt[], PEnt    */	PPEnt;
102 
103 typedef struct {
104   /* flags and file names: */
105   int SL, of, rf, kf, rd, b[POINT_Nmax];   /* orig/omit-flag, recov-flag,
106                                               keep-flag, rec.depth, branch */
107   char *iname, *oname, *dbname;	     /* file names : &(Constant Strings) !! */
108   /* Statistics: */
109   UPint nNF, nIP; unsigned int nSLNF,  hc, con;         /* #refhit #con.ref */
110   int V, F, VN, FN, d, Nmin, Nmax, Xdif, Xnuc;             /* max values */
111   time_t TIME, SAVE; clock_t CLOCK; long long IP_Time, NF_Time;
112   /* Results */
113   Along NP, savedNP, NC; int nSLP;   		/* NC = # unit-encode */
114   /* Lists */
115   DataBase DB; FInfoList Aux, In; PEnt *PE; PPEnt *PPE;
116   unsigned char *NewNF;
117   Along NewNB, ANB; /* allocate*/ 	int RemNB; /* SL-remove */
118   int *SLp, SLN, PEN, PPEN, peNM, peSM, slNM, slSM;
119                                                /* no/self mirror's on NewNF */
120                                                  		 }    NF_List;
121 
122 /* 	NP (HP)=#(honest) refpolys         NNF=#nf's, NSM=#self mirror,  */
123 /*		NP==HRP+SLRP	HRP==2*HNF-HSM-HnoMirror
124  *		HNF=PEN+PPEN+Aux.nNF	HSM=peSM+Aux.nSM    HNM=peNM+Aux.nNM
125  *		SLRP=2*SLN-slNM-slSM                                      */
126 /* watch: #R=NP (nSLP) #C=NC #IP=nIP #NF=nNF (nSLNF) Nmin..Nmax vV fF dx=dX */
127 
128 /*  ==========          	checks and warnigs		 ========== */
129 
130 #if	( FORCE_SAVE_TIME <= MIN_W_SAVE_TIME )
131 #error	MIN_W_SAVE_TIME should be smaller than AUX-file save_times
132 #endif
133 
134 
135 void Make_ANF(PolyPointList *P,VertexNumList *V,       /* affine normal form */
136 	      EqList *E, Long ANF[POLY_Dmax][VERT_Nmax]);
137 void Gen_Ascii_to_Binary(CWS *W, PolyPointList *P,
138 		     char *dbin, char *polyi, char *polyo);
139 void Gen_Bin_2_ascii(char *pi,char *dbi,int max,int vf,int vt,PolyPointList *);
140 
141 
142 /*  ==========          Functions from Subpoly.c                 ========== */
143 void DPircheck(CWS *_W, PolyPointList *_P);
144 void DPvircheck(CWS *_W, PolyPointList *_P);
145 void Max_check(CWS *_W, PolyPointList *_P);
146 void Overall_check(CWS *_W, PolyPointList *_P);
147 void Do_the_Classification(CWS *W, PolyPointList *P, /* char *fn, */
148        int oFlag, int rFlag, int kFlag, char *polyi, char *polyo, char *dbin);
149 void Find_Sublat_Polys(char mFlag, char *dbi, char *polyi, char *slout,
150 		       PolyPointList *_P);
151 void Ascii_to_Binary(CWS *W, PolyPointList *P,
152 		     char *dbin, char *polyi, char *polyo);
153 int  Start_Find_Ref_Subpoly(PolyPointList *_P/*, NF_List *_NFL*/);
154 void uc_nf_to_P(PolyPointList *_P, int *MS, int *d, int *v, int *nuc,
155                 unsigned char *uc);
156 void Make_All_Sublat(NF_List *_L, int n, int v, subl_int diag[POLY_Dmax],
157                      subl_int u[][VERT_Nmax], char *mFlag, PolyPointList *P);
158 int  Poly_Max_check(PolyPointList *_P, VertexNumList *_V, EqList *_E);
159 int  Poly_Min_check(PolyPointList *_P, VertexNumList *_V, EqList *_E);
160 
161 /*  ==========        Functions from Subdb.c                     ========== */
162 void Init_DB(NF_List *_NFL);
163 void Check_NF_Order(char *polyi,char *polyo,int cFlag, PolyPointList *P);
164 void Add_Polya_2_DBi(char *dbi,char *polya,char *dbo);
165 void Polyi_2_DBo(char *polyi,char *dbo);
166 void Reduce_Aux_File(char *polyi,char *polys,char *dbsub,char *polyo);
167 void Bin_2_ascii(char *polyi,char *dbi,int max,int vf,int vt,PolyPointList *P);
168 int  Is_in_DB(int *nv, int *nuc, unsigned char *uc, NF_List *_L);
169 
170 #if (POLY_Dmax <6)
171   void DB_to_Hodge(char *dbin,char *dbout, int vfrom,int vto, PolyPointList *P);
172   void Sort_Hodge(char *dbaux, char *dbout);
173   void Test_Hodge_file(char *filename, PolyPointList *_P);
174   void Test_Hodge_db(char *dbname);
175   void Extract_from_Hodge_db(char *dname, char *x_string, PolyPointList *P);
176 #endif
177 
178 void Open_DB(char *dbin, DataBase **DB, int info);
179 int  Read_H_poly_from_DB(DataBase *DB,PolyPointList *_P);
180 void Close_DB(DataBase *DB);
181 void VPHM_Sublat_Polys(char sFlag,char mr,char *dbin,char *polyi,char *polyo,
182 		       PolyPointList *P);
183 
184 
185 /*  ==========        Functions from Subadd.c                    ========== */
186 void Add_Polya_2_Polyi(char *polyi,char *polya,char *polyo);
187 void Init_NF_List(NF_List *);
188 void Init_FInfoList(FInfoList *FI);
189 void Read_File_2_List(char *polyi,NF_List *_NFL);
190 void Write_List_2_File(char *polyo,NF_List *_NFL);
191 void Print_Weight_Info(CWS *_W, NF_List *_L);
192 void fputUI(unsigned int l,FILE *F);
193 void UCnf2vNF(int *d, int *v, int *nuc, unsigned char *uc,  	      /* IN */
194 	      Long NF[POLY_Dmax][VERT_Nmax], int *MS);	             /* OUT */
195 int  Add_NF_to_List(PolyPointList *_P, VertexNumList *_V, EqList *_F,
196 		    NF_List *_NFL);				/* 1 if new */
197 int  RIGHTminusLEFT(unsigned char *ucL, unsigned char *ucR, int *nuc);
198 unsigned int fgetUI(FILE *F);
199 void Test_ucNF(int *d, int *tnv, int *tnuc, unsigned char *tuc,
200 	       PolyPointList *P);
201 int  InfoSize(int rd, int lists, FInfoList *FI);
202 int  Make_Poly_NF(PolyPointList *_P, VertexNumList *_V, EqList *_E,
203 		Long pNF[POLY_Dmax][VERT_Nmax]);	  /* 1 if reflexive */
204 void ANF_2_ucNF(PolyPointList *P, VertexNumList *V, EqList *E,	      /* IN */
205      		 int *NV, int *nUC, unsigned char *UC);		     /* OUT */
206 void UCnf_2_ANF(int *d, int *v, int *nuc, unsigned char *uc,          /* IN */
207               Long NF[POLY_Dmax][VERT_Nmax], int *MS);                /* OUT */
208 
209 void Print_Expect(FInfoList *L);
210 
211 /* ====    headers of aux-Routines for Add_Polya_2_DBi in Subadd.c ==== */
212 
213 void Read_Bin_Info(FILE *F, int *d, unsigned *li, int *slNF, int *slSM,
214 		int *slNM, Along *NewNB, FInfoList *FI);
215 void AuxGet_vn_uc(FILE *F,int *v, int *nu, unsigned char *uc);
216 void AuxGet_uc(FILE *F,int *nu, unsigned char *uc);
217 void AuxPut_hNF(FILE *F,int *v,int *nu,unsigned char *Huc,FInfoList *Io,
218         int *slNF,int *slSM,int *slNM,int *slNB,unsigned char *ucSL,int *SLp);
219 
220 #define min(a,b)	(((a) < (b)) ? (a) : (b))
221 #define max(a,b)	(((a) > (b)) ? (a) : (b))
222 
223