int main (int argc, char *argv[]) { FILE *UPDATEFILE; struct anchorfileFormat anchorfileData; //tester for at vi har fåt hvilken fil vi skal bruke if (argc < 2) { printf("Usage: ./addanchors anchorfile\n\n\tanchorfile, fil med tekster på linker\n\n"); exit(1); } if ((UPDATEFILE = fopen(argv[1],"rb")) == NULL) { printf("Cant read anchorfile "); perror(argv[1]); exit(1); } lotlistLoad(); void lotlistMarkLocals(char server[]); while(!feof(UPDATEFILE)) { fread(&anchorfileData,sizeof(struct anchorfileFormat),1,UPDATEFILE); //printf("%i : %s\n",anchorfileData.DocID,anchorfileData.text); //sjekker om dette er en lokal lot //temp: utestet: if (lotlistIsLocal(rLotForDOCid(anchorfileData.DocID))) { anchoradd(anchorfileData.DocID,anchorfileData.text,sizeof(anchorfileData.text)); } else { printf("lot is not locale"); } } fclose(UPDATEFILE); }
void popopenMemArray(char servername[], char subname[], char rankfile[]) { FILE *FH; int i; int LocalLots; char LotFile[128]; int branksize; struct stat inode; off_t totsize = 0; lotlistLoad(); lotlistMarkLocals(servername); //aloker minne for rank for de forskjelige lottene LocalLots=0; for (i=0;i<maxLots;i++) { //sjekekr om dette er en lokal lot if (lotlistIsLocal(i)) { GetFilPathForLot(LotFile,i,subname); strcat(LotFile,rankfile); // prøver å opne if ( (FH = fopen(LotFile,"rb")) == NULL ) { perror(LotFile); popMemArray[i] = 0; } else { #ifdef DEBUG printf("loaded lot %i\n",i); #endif branksize = sizeof(unsigned char) * NrofDocIDsInLot; #ifdef MMAP_POP fstat(fileno(FH),&inode); if (inode.st_size != branksize) { fprintf(stderr,"popopenMemArray: file is smaler then size. file size %"PRId64", suposed to be %i\n",inode.st_size,branksize); continue; } if ((popMemArray[i] = mmap(0,branksize,PROT_READ,MAP_SHARED,fileno(FH),0) ) == NULL) { fprintf(stderr,"popopenMemArray: can't mmap for lot %i\n",i); perror("popopenMemArray mmap"); } #else if ((popMemArray[i] = (unsigned char*)malloc(branksize)) == NULL) { printf("malloc eror for lot %i\n",i); perror("malloc"); exit(1); } fread(popMemArray[i],branksize,1,FH); #endif //debug: viser alle rankene vi laster /* for(y=0;y<branksize;y++) { printf("DocID %i, rank %i\n",y,popMemArray[i][y]); } */ totsize += branksize; fclose(FH); ++LocalLots; } } else { popMemArray[i] = 0; } } printf("popopenMemArray: have %i local lots\n",LocalLots); printf("popopenMemArray: loaded a total of %"PRId64" bytes\n",totsize); }
void adultWeightopenMemArray(char servername[],char subname[]) { FILE *FH; int i; int LocalLots; char LotFile[128]; int branksize; off_t totsize = 0; struct stat inode; lotlistLoad(); lotlistMarkLocals(servername); //aloker minne for rank for de forskjelige lottene LocalLots=0; for (i=0;i<maxLots;i++) { //sjekekr om dette er en lokal lot if (lotlistIsLocal(i)) { GetFilPathForLot(LotFile,i,subname); strcat(LotFile,"AdultWeight"); // prøver å opne if ( (FH = fopen(LotFile,"r+b")) == NULL ) { perror(LotFile); adultWeightMemArray[i] = 0; } else { #ifdef DEBUG printf("loaded lot %i\n",i); #endif branksize = sizeof(unsigned char) * NrofDocIDsInLot; #ifdef MMAP_ADULT fstat(fileno(FH),&inode); if (inode.st_size < branksize) { fprintf(stderr,"adultWeightopenMemArray: file is smaler then size. file size %"PRId64", suposed to be %i\n",inode.st_size,branksize); /* Stretch the file size to the size of the (mmapped) array of ints */ if (fseek(FH, branksize +1, SEEK_SET) == -1) { perror("Error calling fseek() to 'stretch' the file"); exit(EXIT_FAILURE); } /* Something needs to be written at the end of the file to * have the file actually have the new size. * Just writing an empty string at the current file position will do. * * Note: * - The current position in the file is at the end of the stretched * file due to the call to fseek(). * - An empty string is actually a single '\0' character, so a zero-byte * will be written at the last byte of the file. */ if (fwrite("", 1, 1, FH) != 1) { perror("Error writing last byte of the file"); exit(EXIT_FAILURE); } } if ((adultWeightMemArray[i] = mmap(0,branksize,PROT_READ,MAP_SHARED,fileno(FH),0) ) == NULL) { fprintf(stderr,"adultWeightopenMemArray: can't mmap for lot %i\n",i); perror("mmap"); } #else if ((adultWeightMemArray[i] = (unsigned char*)malloc(branksize)) == NULL) { printf("malloc eror for lot %i\n",i); perror("malloc"); exit(1); } fread(adultWeightMemArray[i],branksize,1,FH); #endif //debug: viser alle rankene vi laster //for(y=0;y<branksize;y++) { // printf("DocID %i, rank %i\n",y,adultWeightMemArray[i][y]); //} fclose(FH); totsize += branksize; ++LocalLots; } } else { adultWeightMemArray[i] = 0; } } printf("adultWeightopenMemArray: have %i local lots\n",LocalLots); printf("adultWeightopenMemArray: loaded a total of %"PRId64" bytes\n",totsize); }