| [f2eb077] | 1 | #include <stdio.h>
|
|---|
| 2 | #include <stdlib.h>
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 |
|
|---|
| 5 | #include "adc.h"
|
|---|
| 6 |
|
|---|
| 7 | #define BlockSize 1024
|
|---|
| 8 |
|
|---|
| 9 | void swap4(void * num){
|
|---|
| 10 | char t, *p;
|
|---|
| 11 | p = (char *) num;
|
|---|
| 12 | t = *p; *p = *(p + 3); *(p + 3) = t;
|
|---|
| 13 | t = *(p + 1); *(p + 1) = *(p + 2); *(p + 2) = t;
|
|---|
| 14 | }
|
|---|
| 15 | void swap8(void * num){
|
|---|
| 16 | char t, *p;
|
|---|
| 17 | p = (char *) num;
|
|---|
| 18 | t = *p; *p = *(p + 7); *(p + 7) = t;
|
|---|
| 19 | t = *(p + 1); *(p + 1) = *(p + 6); *(p + 6) = t;
|
|---|
| 20 | t = *(p + 2); *(p + 2) = *(p + 5); *(p + 5) = t;
|
|---|
| 21 | t = *(p + 3); *(p + 3) = *(p + 4); *(p + 4) = t;
|
|---|
| 22 | }
|
|---|
| 23 | void initADCpar(ADC_PAR *par){
|
|---|
| 24 | par->ndid=0;
|
|---|
| 25 | par->dim=5;
|
|---|
| 26 | par->mnum=1;
|
|---|
| 27 | par->tuplenum=100;
|
|---|
| 28 | /* par->isascii=1; */
|
|---|
| 29 | par->inverse_endian=0;
|
|---|
| 30 | par->filename="ADC";
|
|---|
| 31 | par->clss='U';
|
|---|
| 32 | }
|
|---|
| 33 | int ParseParFile(char* parfname,ADC_PAR *par);
|
|---|
| 34 | int GenerateADC(ADC_PAR *par);
|
|---|
| 35 |
|
|---|
| 36 | typedef struct Factorization{
|
|---|
| 37 | long int *mlt;
|
|---|
| 38 | long int *exp;
|
|---|
| 39 | long int dim;
|
|---|
| 40 | } Factorization;
|
|---|
| 41 |
|
|---|
| 42 | void ShowFactorization(Factorization *nmbfct){
|
|---|
| 43 | int i=0;
|
|---|
| 44 | for(i=0;i<nmbfct->dim;i++){
|
|---|
| 45 | if(nmbfct->mlt[i]==1){
|
|---|
| 46 | if(i==0) fprintf(stdout,"prime.");
|
|---|
| 47 | break;
|
|---|
| 48 | }
|
|---|
| 49 | if(i>0) fprintf(stdout,"*");
|
|---|
| 50 | if(nmbfct->exp[i]==1)
|
|---|
| 51 | fprintf(stdout,"%ld",nmbfct->mlt[i]);
|
|---|
| 52 | else
|
|---|
| 53 | fprintf(stdout,"%ld^%ld",nmbfct->mlt[i],
|
|---|
| 54 | nmbfct->exp[i]);
|
|---|
| 55 | }
|
|---|
| 56 | fprintf(stdout,"\n");
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | long int adcprime[]={
|
|---|
| 60 | 421,601,631,701,883,
|
|---|
| 61 | 419,443,647,21737,31769,
|
|---|
| 62 | 1427,18353,22817,34337,98717,
|
|---|
| 63 | 3527,8693,9677,11093,18233};
|
|---|
| 64 |
|
|---|
| 65 | long int ListFirstPrimes(long int mpr,long int *prlist){
|
|---|
| 66 | /*
|
|---|
| 67 | fprintf(stdout,"ListFirstPrimes: listing primes less than %ld...\n",
|
|---|
| 68 | mpr);
|
|---|
| 69 | */
|
|---|
| 70 | long int prnum=0;
|
|---|
| 71 | int composed=0;
|
|---|
| 72 | long int nmb=0,j=0;
|
|---|
| 73 | prlist[prnum++]=2;
|
|---|
| 74 | prlist[prnum++]=3;
|
|---|
| 75 | prlist[prnum++]=5;
|
|---|
| 76 | prlist[prnum++]=7;
|
|---|
| 77 | for(nmb=8;nmb<mpr;nmb++){
|
|---|
| 78 | composed=0;
|
|---|
| 79 | for(j=0;prlist[j]*prlist[j]<=nmb;j++){
|
|---|
| 80 | if(nmb-prlist[j]*((long int)(nmb/prlist[j]))==0){
|
|---|
| 81 | composed=1;
|
|---|
| 82 | break;
|
|---|
| 83 | }
|
|---|
| 84 | }
|
|---|
| 85 | if(composed==0) prlist[prnum++]=nmb;
|
|---|
| 86 | }
|
|---|
| 87 | /* fprintf(stdout,"ListFirstPrimes: Done.\n"); */
|
|---|
| 88 | return prnum;
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | long long int LARGE_NUM=0x4FFFFFFFFFFFFFFFLL;
|
|---|
| 92 | long long int maxprmfctr=59;
|
|---|
| 93 |
|
|---|
| 94 | long long int GetLCM(long long int mask,
|
|---|
| 95 | Factorization **fctlist,
|
|---|
| 96 | long int *adcexpons){
|
|---|
| 97 | int i=0,j=0,k=0;
|
|---|
| 98 | int* expons=(int*) calloc(maxprmfctr+1,sizeof(int));
|
|---|
| 99 | long long int LCM=1;
|
|---|
| 100 | long int pr=2;
|
|---|
| 101 | int genexp=1,lexp=1,fct=2;
|
|---|
| 102 |
|
|---|
| 103 | for(i=0;i<maxprmfctr+1;i++)expons[i]=0;
|
|---|
| 104 | i=0;
|
|---|
| 105 | while(mask>0){
|
|---|
| 106 | if(mask==2*(mask/2)){
|
|---|
| 107 | mask=mask>>1;
|
|---|
| 108 | i++;
|
|---|
| 109 | continue;
|
|---|
| 110 | }
|
|---|
| 111 | pr=adcprime[i];
|
|---|
| 112 | genexp=adcexpons[i];
|
|---|
| 113 | /*
|
|---|
| 114 | fprintf(stdout,"[%ld,%ld]\n",pr,genexp);
|
|---|
| 115 | ShowFactorization(fctlist[genexp]);
|
|---|
| 116 | */
|
|---|
| 117 | for(j=0;j<fctlist[pr-1]->dim;j++){
|
|---|
| 118 | fct=fctlist[pr-1]->mlt[j];
|
|---|
| 119 | lexp=fctlist[pr-1]->exp[j];
|
|---|
| 120 |
|
|---|
| 121 | for(k=0;k<fctlist[genexp]->dim;k++){
|
|---|
| 122 | if(fctlist[genexp]->mlt[k]==1) break;
|
|---|
| 123 | if(fct!=fctlist[genexp]->mlt[k]) continue;
|
|---|
| 124 | lexp-=fctlist[genexp]->exp[k];
|
|---|
| 125 | break;
|
|---|
| 126 | }
|
|---|
| 127 | if(expons[fct]<lexp)expons[fct]=lexp;
|
|---|
| 128 | }
|
|---|
| 129 | mask=mask>>1;
|
|---|
| 130 | i++;
|
|---|
| 131 | }
|
|---|
| 132 | /*
|
|---|
| 133 | for(i=0;i<maxprmfctr;i++){
|
|---|
| 134 | if(expons[i]>0) fprintf(stdout,"*%ld^%ld",i,expons[i]);
|
|---|
| 135 | }
|
|---|
| 136 | fprintf(stdout,"\n");
|
|---|
| 137 | */
|
|---|
| 138 | for(i=0;i<=maxprmfctr;i++){
|
|---|
| 139 | while(expons[i]>0){
|
|---|
| 140 | LCM*=i;
|
|---|
| 141 | if(LCM>LARGE_NUM/maxprmfctr) return LCM;
|
|---|
| 142 | expons[i]--;
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 | /* fprintf(stdout,"==== %lld\n",LCM); */
|
|---|
| 146 | free(expons);
|
|---|
| 147 | return LCM;
|
|---|
| 148 | }
|
|---|
| 149 | void ExtendFactors(long int nmb,long int firstdiv,
|
|---|
| 150 | Factorization *nmbfct,Factorization **fctlist){
|
|---|
| 151 | Factorization *divfct=fctlist[nmb/firstdiv];
|
|---|
| 152 | int fdivused=0;
|
|---|
| 153 | int multnum=0;
|
|---|
| 154 | int i=0;
|
|---|
| 155 | /* fprintf(stdout,"==== %lld %ld %ld\n",divfct->dim,nmb,firstdiv); */
|
|---|
| 156 | for(i=0;i<divfct->dim;i++){
|
|---|
| 157 | if(divfct->mlt[i]==1){
|
|---|
| 158 | if(fdivused==0){
|
|---|
| 159 | nmbfct->mlt[multnum]=firstdiv;
|
|---|
| 160 | nmbfct->exp[multnum]=1;
|
|---|
| 161 | }
|
|---|
| 162 | break;
|
|---|
| 163 | }
|
|---|
| 164 | if(divfct->mlt[i]<firstdiv){
|
|---|
| 165 | nmbfct->mlt[i]=divfct->mlt[i];
|
|---|
| 166 | nmbfct->exp[i]=divfct->exp[i];
|
|---|
| 167 | multnum++;
|
|---|
| 168 | }else if(divfct->mlt[i]==firstdiv){
|
|---|
| 169 | nmbfct->mlt[i]=divfct->mlt[i];
|
|---|
| 170 | nmbfct->exp[i]=divfct->exp[i]+1;
|
|---|
| 171 | fdivused=1;
|
|---|
| 172 | }else{
|
|---|
| 173 | int j=i;
|
|---|
| 174 | if(fdivused==0) j=i+1;
|
|---|
| 175 | nmbfct->mlt[j]=divfct->mlt[i];
|
|---|
| 176 | nmbfct->exp[j]=divfct->exp[i];
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 | }
|
|---|
| 180 | void GetFactorization(long int prnum,long int *prlist,
|
|---|
| 181 | Factorization **fctlist){
|
|---|
| 182 | /*fprintf(stdout,"GetFactorization: factorizing first %ld numbers.\n",
|
|---|
| 183 | prnum);*/
|
|---|
| 184 | long int i=0,j=0;
|
|---|
| 185 | Factorization *fct=(Factorization*)malloc(2*sizeof(Factorization));
|
|---|
| 186 | long int len=0,isft=0,div=1,firstdiv=1;
|
|---|
| 187 |
|
|---|
| 188 | fct->dim=2;
|
|---|
| 189 | fct->mlt=(long int*)malloc(2*sizeof(long int));
|
|---|
| 190 | fct->exp=(long int*)malloc(2*sizeof(long int));
|
|---|
| 191 | for(i=0;i<fct->dim;i++){
|
|---|
| 192 | fct->mlt[i]=1;
|
|---|
| 193 | fct->exp[i]=0;
|
|---|
| 194 | }
|
|---|
| 195 | fct->mlt[0]=2;
|
|---|
| 196 | fct->exp[0]=1;
|
|---|
| 197 | fctlist[2]=fct;
|
|---|
| 198 |
|
|---|
| 199 | fct=(Factorization*)malloc(2*sizeof(Factorization));
|
|---|
| 200 | fct->dim=2;
|
|---|
| 201 | fct->mlt=(long int*)malloc(2*sizeof(long int));
|
|---|
| 202 | fct->exp=(long int*)malloc(2*sizeof(long int));
|
|---|
| 203 | for(i=0;i<fct->dim;i++){
|
|---|
| 204 | fct->mlt[i]=1;
|
|---|
| 205 | fct->exp[i]=0;
|
|---|
| 206 | }
|
|---|
| 207 | fct->mlt[0]=3;
|
|---|
| 208 | fct->exp[0]=1;
|
|---|
| 209 | fctlist[3]=fct;
|
|---|
| 210 |
|
|---|
| 211 | for(i=0;i<prlist[prnum-1];i++){
|
|---|
| 212 | len=0;
|
|---|
| 213 | isft=i;
|
|---|
| 214 | while(isft>0){
|
|---|
| 215 | len++;
|
|---|
| 216 | isft=isft>>1;
|
|---|
| 217 | }
|
|---|
| 218 | fct=(Factorization*)malloc(2*sizeof(Factorization));
|
|---|
| 219 | fct->dim=len;
|
|---|
| 220 | if (len==0) len=1;
|
|---|
| 221 | fct->mlt=(long int*)malloc(len*sizeof(long int));
|
|---|
| 222 | fct->exp=(long int*)malloc(len*sizeof(long int));
|
|---|
| 223 | for(j=0;j<fct->dim;j++){
|
|---|
| 224 | fct->mlt[j]=1;
|
|---|
| 225 | fct->exp[j]=0;
|
|---|
| 226 | }
|
|---|
| 227 | div=1;
|
|---|
| 228 | for(j=0;prlist[j]*prlist[j]<=i;j++){
|
|---|
| 229 | firstdiv=prlist[j];
|
|---|
| 230 | if(i-firstdiv*((long int)i/firstdiv)==0){
|
|---|
| 231 | div=firstdiv;
|
|---|
| 232 | if(firstdiv*firstdiv==i){
|
|---|
| 233 | fct->mlt[0]=firstdiv;
|
|---|
| 234 | fct->exp[0]=2;
|
|---|
| 235 | }else{
|
|---|
| 236 | ExtendFactors(i,firstdiv,fct,fctlist);
|
|---|
| 237 | }
|
|---|
| 238 | break;
|
|---|
| 239 | }
|
|---|
| 240 | }
|
|---|
| 241 | if(div==1){
|
|---|
| 242 | fct->mlt[0]=i;
|
|---|
| 243 | fct->exp[0]=1;
|
|---|
| 244 | }
|
|---|
| 245 | fctlist[i]=fct;
|
|---|
| 246 | /*
|
|---|
| 247 | ShowFactorization(fct);
|
|---|
| 248 | */
|
|---|
| 249 | }
|
|---|
| 250 | /* fprintf(stdout,"GetFactorization: Done.\n"); */
|
|---|
| 251 | }
|
|---|
| 252 |
|
|---|
| 253 | long int adcexp[]={
|
|---|
| 254 | 11,13,17,19,23,
|
|---|
| 255 | 23,29,31,37,41,
|
|---|
| 256 | 41,43,47,53,59,
|
|---|
| 257 | 3,5,7,11,13};
|
|---|
| 258 | long int adcexpS[]={
|
|---|
| 259 | 11,13,17,19,23};
|
|---|
| 260 | long int adcexpW[]={
|
|---|
| 261 | 2*2,2*2*2*5,2*3,2*2*5,2*3*7,
|
|---|
| 262 | 23,29,31,2*2,2*2*19};
|
|---|
| 263 | long int adcexpA[]={
|
|---|
| 264 | 2*2,2*2*2*5,2*3,2*2*5,2*3*7,
|
|---|
| 265 | 2*19,2*13,2*19,2*2*2*13*19,2*2*2*19*19,
|
|---|
| 266 | 2*23,2*2*2*2,2*2*2*2*2*23,2*2*2*2*2,2*2*23};
|
|---|
| 267 | long int adcexpB[]={
|
|---|
| 268 | 2*2*7,2*2*2*5,2*3*7,2*2*5*7,2*3*7*7,
|
|---|
| 269 | 2*19,2*13,2*19,2*2*2*13*19,2*2*2*19*19,
|
|---|
| 270 | 2*31,2*2*2*2*31,2*2*2*2*2*31,2*2*2*2*2*29,2*2*29,
|
|---|
| 271 | 2*43,2*2,2*2,2*2*47,2*2*2*43};
|
|---|
| 272 | long int UpPrimeLim=100000;
|
|---|
| 273 |
|
|---|
| 274 | typedef struct dc_view{
|
|---|
| 275 | long long int vsize;
|
|---|
| 276 | long int vidx;
|
|---|
| 277 | } DC_view;
|
|---|
| 278 |
|
|---|
| 279 | int CompareSizesByValue( const void* sz0, const void* sz1) {
|
|---|
| 280 | long long int *size0=(long long int*)sz0,
|
|---|
| 281 | *size1=(long long int*)sz1;
|
|---|
| 282 | int res=0;
|
|---|
| 283 | if(*size0-*size1>0) res=1;
|
|---|
| 284 | else if(*size0-*size1<0) res=-1;
|
|---|
| 285 | return res;
|
|---|
| 286 | }
|
|---|
| 287 | int CompareViewsBySize( const void* vw0, const void* vw1) {
|
|---|
| 288 | DC_view *lvw0=(DC_view *)vw0, *lvw1=(DC_view *)vw1;
|
|---|
| 289 | int res=0;
|
|---|
| 290 | if(lvw0->vsize>lvw1->vsize) res=1;
|
|---|
| 291 | else if(lvw0->vsize<lvw1->vsize) res=-1;
|
|---|
| 292 | else if(lvw0->vidx>lvw1->vidx) res=1;
|
|---|
| 293 | else if(lvw0->vidx<lvw1->vidx) res=-1;
|
|---|
| 294 | return res;
|
|---|
| 295 | }
|
|---|
| 296 |
|
|---|
| 297 | int CalculateVeiwSizes(ADC_PAR *par){
|
|---|
| 298 | unsigned long long totalInBytes = 0;
|
|---|
| 299 | unsigned long long nViewDims, nCubeTuples = 0;
|
|---|
| 300 |
|
|---|
| 301 | const char *adcfname=par->filename;
|
|---|
| 302 | int NDID=par->ndid;
|
|---|
| 303 | char clss=par->clss;
|
|---|
| 304 | int dcdim=par->dim;
|
|---|
| 305 | long long int tnum=par->tuplenum;
|
|---|
| 306 | long long int i=0,j=0;
|
|---|
| 307 | Factorization
|
|---|
| 308 | **fctlist=(Factorization **) calloc(UpPrimeLim,sizeof(Factorization *));
|
|---|
| 309 | long int *prlist=(long int *) calloc(UpPrimeLim,sizeof(long int));
|
|---|
| 310 | int prnum=ListFirstPrimes(UpPrimeLim,prlist);
|
|---|
| 311 | DC_view *dcview=(DC_view *)calloc((1<<dcdim),sizeof(DC_view));
|
|---|
| 312 | const char* vszefname0;
|
|---|
| 313 | char *vszefname=NULL;
|
|---|
| 314 | FILE* view=NULL;
|
|---|
| 315 | int minvn=1, maxvn=(1<<dcdim), vinc=1;
|
|---|
| 316 | long idx=0;
|
|---|
| 317 |
|
|---|
| 318 | GetFactorization(prnum,prlist,fctlist);
|
|---|
| 319 | for(i=1;i<(1<<dcdim);i++){
|
|---|
| 320 | long long int LCM=1;
|
|---|
| 321 | switch(clss){
|
|---|
| 322 | case 'U':
|
|---|
| 323 | LCM=GetLCM(i,fctlist,adcexp);
|
|---|
| 324 | break;
|
|---|
| 325 | case 'S':
|
|---|
| 326 | LCM=GetLCM(i,fctlist,adcexpS);
|
|---|
| 327 | break;
|
|---|
| 328 | case 'W':
|
|---|
| 329 | LCM=GetLCM(i,fctlist,adcexpW);
|
|---|
| 330 | break;
|
|---|
| 331 | case 'A':
|
|---|
| 332 | LCM=GetLCM(i,fctlist,adcexpA);
|
|---|
| 333 | break;
|
|---|
| 334 | case 'B':
|
|---|
| 335 | LCM=GetLCM(i,fctlist,adcexpB);
|
|---|
| 336 | break;
|
|---|
| 337 | }
|
|---|
| 338 | if(LCM>tnum) LCM=tnum;
|
|---|
| 339 | dcview[i].vsize=LCM;
|
|---|
| 340 | dcview[i].vidx=i;
|
|---|
| 341 | }
|
|---|
| 342 | for(i=0;i<UpPrimeLim;i++){
|
|---|
| 343 | if(!fctlist[i]) continue;
|
|---|
| 344 | if(fctlist[i]->mlt) free(fctlist[i]->mlt);
|
|---|
| 345 | if(fctlist[i]->exp) free(fctlist[i]->exp);
|
|---|
| 346 | free(fctlist[i]);
|
|---|
| 347 | }
|
|---|
| 348 | free(fctlist);
|
|---|
| 349 | free(prlist);
|
|---|
| 350 |
|
|---|
| 351 | vszefname0="view.sz";
|
|---|
| 352 | vszefname=(char*)calloc(BlockSize,sizeof(char));
|
|---|
| 353 | sprintf(vszefname,"%s.%s.%d",adcfname,vszefname0,NDID);
|
|---|
| 354 | if(!(view = fopen(vszefname, "w+")) ) {
|
|---|
| 355 | fprintf(stderr,"CalculateVeiwSizes: Can't open file: %s\n",vszefname);
|
|---|
| 356 | return 0;
|
|---|
| 357 | }
|
|---|
| 358 | qsort( dcview, (1<<dcdim), sizeof(DC_view),CompareViewsBySize);
|
|---|
| 359 |
|
|---|
| 360 | switch(clss){
|
|---|
| 361 | case 'U':
|
|---|
| 362 | vinc=1<<3;
|
|---|
| 363 | break;
|
|---|
| 364 | case 'S':
|
|---|
| 365 | break;
|
|---|
| 366 | case 'W':
|
|---|
| 367 | break;
|
|---|
| 368 | case 'A':
|
|---|
| 369 | vinc=1<<6;
|
|---|
| 370 | break;
|
|---|
| 371 | case 'B':
|
|---|
| 372 | vinc=1<<14;
|
|---|
| 373 | break;
|
|---|
| 374 | }
|
|---|
| 375 | for(i=minvn;i<maxvn;i+=vinc){
|
|---|
| 376 | nViewDims = 0;
|
|---|
| 377 | fprintf(view,"Selection:");
|
|---|
| 378 | idx=dcview[i].vidx;
|
|---|
| 379 | for(j=0;j<dcdim;j++)
|
|---|
| 380 | if((idx>>j)&0x1==1) { fprintf(view," %lld",j+1); nViewDims++;}
|
|---|
| 381 | fprintf(view,"\nView Size: %lld\n",dcview[i].vsize);
|
|---|
| 382 |
|
|---|
| 383 | totalInBytes += (8+4*nViewDims)*dcview[i].vsize;
|
|---|
| 384 | nCubeTuples += dcview[i].vsize;
|
|---|
| 385 |
|
|---|
| 386 | }
|
|---|
| 387 | fprintf(view,"\nTotal in bytes: %lld Number of tuples: %lld\n",
|
|---|
| 388 | totalInBytes, nCubeTuples);
|
|---|
| 389 |
|
|---|
| 390 | fclose(view);
|
|---|
| 391 | free(dcview);
|
|---|
| 392 | fprintf(stdout,"View sizes are written into %s\n",vszefname);
|
|---|
| 393 | free(vszefname);
|
|---|
| 394 | return 1;
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | int ParseParFile(char* parfname,ADC_PAR *par){
|
|---|
| 398 | char line[BlockSize];
|
|---|
| 399 | FILE* parfile=NULL;
|
|---|
| 400 | char* pos=strchr(parfname,'.');
|
|---|
| 401 | int linenum=0,i=0;
|
|---|
| 402 | const char *kwd;
|
|---|
| 403 |
|
|---|
| 404 | if(!(parfile = fopen(parfname, "r")) ) {
|
|---|
| 405 | fprintf(stderr,"ParseParFile: Can't open file: %s\n",parfname);
|
|---|
| 406 | return 0;
|
|---|
| 407 | }
|
|---|
| 408 | if(pos) pos=strchr(pos+1,'.');
|
|---|
| 409 | if(pos) sscanf(pos+1,"%d",&(par->ndid));
|
|---|
| 410 | linenum=0;
|
|---|
| 411 | while(fgets(&line[0],BlockSize,parfile)){
|
|---|
| 412 | i=0;
|
|---|
| 413 | kwd=adcKeyword[i];
|
|---|
| 414 | while(kwd){
|
|---|
| 415 | if(strstr(line,"#")) {
|
|---|
| 416 | ;/*comment line, do nothing*/
|
|---|
| 417 | }else if(strstr(line,kwd)){
|
|---|
| 418 | char *pos=line+strlen(kwd)+1;
|
|---|
| 419 | switch(i){
|
|---|
| 420 | case 0:
|
|---|
| 421 | sscanf(pos,"%d",&(par->dim));
|
|---|
| 422 | break;
|
|---|
| 423 | case 1:
|
|---|
| 424 | sscanf(pos,"%d",&(par->mnum));
|
|---|
| 425 | break;
|
|---|
| 426 | case 2:
|
|---|
| 427 | sscanf(pos,"%lld",&(par->tuplenum));
|
|---|
| 428 | break;
|
|---|
| 429 | case 3:
|
|---|
| 430 | /* sscanf(pos,"%d",&(par->isascii));*/
|
|---|
| 431 | break;
|
|---|
| 432 | case 4:
|
|---|
| 433 | sscanf(pos,"%d",&(par->inverse_endian));
|
|---|
| 434 | break;
|
|---|
| 435 | case 5:
|
|---|
| 436 | par->filename=(char*) malloc(strlen(pos)*sizeof(char));
|
|---|
| 437 | sscanf(pos,"%s",par->filename);
|
|---|
| 438 | break;
|
|---|
| 439 | case 6:
|
|---|
| 440 | sscanf(pos,"%c",&(par->clss));
|
|---|
| 441 | break;
|
|---|
| 442 | }
|
|---|
| 443 | break;
|
|---|
| 444 | }
|
|---|
| 445 | i++;
|
|---|
| 446 | kwd=adcKeyword[i];
|
|---|
| 447 | }
|
|---|
| 448 | linenum++;
|
|---|
| 449 | }
|
|---|
| 450 | fclose(parfile);
|
|---|
| 451 | switch(par->clss){/* overwriting parameters according the class */
|
|---|
| 452 | case 'S':
|
|---|
| 453 | par->dim=5;
|
|---|
| 454 | par->mnum=1;
|
|---|
| 455 | par->tuplenum=1000;
|
|---|
| 456 | break;
|
|---|
| 457 | case 'W':
|
|---|
| 458 | par->dim=10;
|
|---|
| 459 | par->mnum=1;
|
|---|
| 460 | par->tuplenum=100000;
|
|---|
| 461 | break;
|
|---|
| 462 | case 'A':
|
|---|
| 463 | par->dim=15;
|
|---|
| 464 | par->mnum=1;
|
|---|
| 465 | par->tuplenum=1000000;
|
|---|
| 466 | break;
|
|---|
| 467 | case 'B':
|
|---|
| 468 | par->dim=20;
|
|---|
| 469 | par->mnum=1;
|
|---|
| 470 | par->tuplenum=10000000;
|
|---|
| 471 | break;
|
|---|
| 472 | }
|
|---|
| 473 | return 1;
|
|---|
| 474 | }
|
|---|
| 475 | int WriteADCPar(ADC_PAR *par,char* fname){
|
|---|
| 476 | char *lname=(char*) calloc(BlockSize,sizeof(char));
|
|---|
| 477 | FILE *parfile=NULL;
|
|---|
| 478 |
|
|---|
| 479 | sprintf(lname,"%s",fname);
|
|---|
| 480 | parfile=fopen(lname,"w");
|
|---|
| 481 | if(!parfile){
|
|---|
| 482 | fprintf(stderr,"WriteADCPar: can't open file %s\n",lname);
|
|---|
| 483 | return 0;
|
|---|
| 484 | }
|
|---|
| 485 | fprintf(parfile,"attrNum=%d\n",par->dim);
|
|---|
| 486 | fprintf(parfile,"measuresNum=%d\n",par->mnum);
|
|---|
| 487 | fprintf(parfile,"tuplesNum=%lld\n",par->tuplenum);
|
|---|
| 488 | fprintf(parfile,"class=%c\n",par->clss);
|
|---|
| 489 | /* fprintf(parfile,"isASCII=%d\n",par->isascii); */
|
|---|
| 490 | fprintf(parfile,"INVERSE_ENDIAN=%d\n",par->inverse_endian);
|
|---|
| 491 | fprintf(parfile,"fileName=%s\n",par->filename);
|
|---|
| 492 | fclose(parfile);
|
|---|
| 493 | return 1;
|
|---|
| 494 | }
|
|---|
| 495 | void ShowADCPar(ADC_PAR *par){
|
|---|
| 496 | fprintf(stdout,"********************* ADC paramters\n");
|
|---|
| 497 | fprintf(stdout," id %d\n",par->ndid);
|
|---|
| 498 | fprintf(stdout," attributes %d\n",par->dim);
|
|---|
| 499 | fprintf(stdout," measures %d\n",par->mnum);
|
|---|
| 500 | fprintf(stdout," tuples %lld\n",par->tuplenum);
|
|---|
| 501 | fprintf(stdout," class \t%c\n",par->clss);
|
|---|
| 502 | fprintf(stdout," filename %s\n",par->filename);
|
|---|
| 503 | fprintf(stdout,"***********************************\n");
|
|---|
| 504 | }
|
|---|
| 505 |
|
|---|
| 506 | long int adcgen[]={
|
|---|
| 507 | 2,7,3,2,2,
|
|---|
| 508 | 2,2,5,31,7,
|
|---|
| 509 | 2,3,3,3,2,
|
|---|
| 510 | 5,2,2,2,3};
|
|---|
| 511 |
|
|---|
| 512 | int GetNextTuple(int dcdim, int measnum,
|
|---|
| 513 | long long int* attr,long long int* meas,
|
|---|
| 514 | char clss){
|
|---|
| 515 | static int tuplenum=0;
|
|---|
| 516 | static const int maxdim=20;
|
|---|
| 517 | static int measbound=31415;
|
|---|
| 518 | int i=0,j=0;
|
|---|
| 519 | int maxattr=0;
|
|---|
| 520 | static long int seed[20];
|
|---|
| 521 | long int *locexp=NULL;
|
|---|
| 522 |
|
|---|
| 523 | if(dcdim>maxdim){
|
|---|
| 524 | fprintf(stderr,"GetNextTuple: number of dcdim is too large:%d",
|
|---|
| 525 | dcdim);
|
|---|
| 526 | return 0;
|
|---|
| 527 | }
|
|---|
| 528 | if(measnum>measbound){
|
|---|
| 529 | fprintf(stderr,"GetNextTuple: number of mes is too large:%d",
|
|---|
| 530 | measnum);
|
|---|
| 531 | return 0;
|
|---|
| 532 | }
|
|---|
| 533 | locexp=adcexp;
|
|---|
| 534 | switch(clss){
|
|---|
| 535 | case 'S':
|
|---|
| 536 | locexp=adcexpS;
|
|---|
| 537 | break;
|
|---|
| 538 | case 'W':
|
|---|
| 539 | locexp=adcexpW;
|
|---|
| 540 | break;
|
|---|
| 541 | case 'A':
|
|---|
| 542 | locexp=adcexpA;
|
|---|
| 543 | break;
|
|---|
| 544 | case 'B':
|
|---|
| 545 | locexp=adcexpB;
|
|---|
| 546 | break;
|
|---|
| 547 | }
|
|---|
| 548 | if(tuplenum==0){
|
|---|
| 549 | for(i=0;i<dcdim;i++){
|
|---|
| 550 | int tmpgen=adcgen[i];
|
|---|
| 551 | for(j=0;j<locexp[i]-1;j++){
|
|---|
| 552 | tmpgen*=adcgen[i];
|
|---|
| 553 | tmpgen=tmpgen%adcprime[i];
|
|---|
| 554 | }
|
|---|
| 555 | adcgen[i]=tmpgen;
|
|---|
| 556 | }
|
|---|
| 557 | fprintf(stdout,"Prime \tGenerator \tSeed\n");
|
|---|
| 558 | for(i=0;i<dcdim;i++){
|
|---|
| 559 | seed[i]=(adcprime[i]+1)/2;
|
|---|
| 560 | fprintf(stdout," %ld\t %ld\t\t %ld\n",adcprime[i],adcgen[i],seed[i]);
|
|---|
| 561 | }
|
|---|
| 562 | }
|
|---|
| 563 | tuplenum++;
|
|---|
| 564 | maxattr=0;
|
|---|
| 565 | for(i=0;i<dcdim;i++){
|
|---|
| 566 | attr[i]=seed[i]*adcgen[i];
|
|---|
| 567 | attr[i]-=adcprime[i]*((long long int)attr[i]/adcprime[i]);
|
|---|
| 568 | seed[i]=attr[i];
|
|---|
| 569 | if(seed[i]>maxattr) maxattr=seed[i];
|
|---|
| 570 | }
|
|---|
| 571 | for(i=0;i<measnum;i++){
|
|---|
| 572 | meas[i]=(long long int)(seed[i]*maxattr);
|
|---|
| 573 | meas[i]-=measbound*(meas[i]/measbound);
|
|---|
| 574 | }
|
|---|
| 575 | return 1;
|
|---|
| 576 | }
|
|---|
| 577 |
|
|---|
| 578 | int GenerateADC(ADC_PAR *par){
|
|---|
| 579 | int dcdim=par->dim,
|
|---|
| 580 | mesnum=par->mnum,
|
|---|
| 581 | tplnum=par->tuplenum;
|
|---|
| 582 | char *adcfname=(char*)calloc(BlockSize,sizeof(char));
|
|---|
| 583 |
|
|---|
| 584 | FILE *adc;
|
|---|
| 585 | int i=0,j=0;
|
|---|
| 586 | long long int* attr=NULL,*mes=NULL;
|
|---|
| 587 | /*
|
|---|
| 588 | if(par->isascii==1){
|
|---|
| 589 | sprintf(adcfname,"%s.tpl.%d",par->filename,par->ndid);
|
|---|
| 590 | if(!(adc = fopen(adcfname, "w+"))) {
|
|---|
| 591 | fprintf(stderr,"GenerateADC: Can't open file: %s\n",adcfname);
|
|---|
| 592 | return 0;
|
|---|
| 593 | }
|
|---|
| 594 | }else{
|
|---|
| 595 | */
|
|---|
| 596 | sprintf(adcfname,"%s.dat.%d",par->filename,par->ndid);
|
|---|
| 597 | if(!(adc = fopen(adcfname, "wb+"))){
|
|---|
| 598 | fprintf(stderr,"GenerateADC: Can't open file: %s\n",adcfname);
|
|---|
| 599 | return 0;
|
|---|
| 600 | }
|
|---|
| 601 | /* } */
|
|---|
| 602 | attr=(long long int *)malloc(dcdim*sizeof(long long int));
|
|---|
| 603 | mes=(long long int *)malloc(mesnum*sizeof(long long int));
|
|---|
| 604 |
|
|---|
| 605 | fprintf(stdout,"\nGenerateADC: writing %d tuples of %d attributes and %d measures to %s\n",
|
|---|
| 606 | tplnum,dcdim,mesnum,adcfname);
|
|---|
| 607 | for(i=0;i<tplnum;i++){
|
|---|
| 608 | if(!GetNextTuple(dcdim,mesnum,attr,mes,par->clss)) return 0;
|
|---|
| 609 | /*
|
|---|
| 610 | if(par->isascii==1){
|
|---|
| 611 | for(int j=0;j<dcdim;j++)fprintf(adc,"%lld ",attr[j]);
|
|---|
| 612 | for(int j=0;j<mesnum;j++)fprintf(adc,"%lld ",mes[j]);
|
|---|
| 613 | fprintf(adc,"\n");
|
|---|
| 614 | }else{
|
|---|
| 615 | */
|
|---|
| 616 | for(j=0;j<mesnum;j++){
|
|---|
| 617 | long long mv = mes[j];
|
|---|
| 618 | if(par->inverse_endian==1) swap8(&mv);
|
|---|
| 619 | fwrite(&mv, 8, 1, adc);
|
|---|
| 620 | }
|
|---|
| 621 | for(j=0;j<dcdim;j++){
|
|---|
| 622 | int av = attr[j];
|
|---|
| 623 | if(par->inverse_endian==1) swap4(&av);
|
|---|
| 624 | fwrite(&av, 4, 1, adc);
|
|---|
| 625 | }
|
|---|
| 626 | }
|
|---|
| 627 | /* } */
|
|---|
| 628 | fclose(adc);
|
|---|
| 629 | fprintf(stdout,"Binary ADC file %s ",adcfname);
|
|---|
| 630 | fprintf(stdout,"have been generated.\n");
|
|---|
| 631 | free(attr);
|
|---|
| 632 | free(mes);
|
|---|
| 633 | free(adcfname);
|
|---|
| 634 | CalculateVeiwSizes(par);
|
|---|
| 635 | return 1;
|
|---|
| 636 | }
|
|---|