Ignore:
Timestamp:
Dec 8, 2014, 7:27:21 AM (5 years ago)
Author:
cameron
Message:

Clean out non-mmap code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/icgrep.cpp

    r4288 r4323  
    7070
    7171
    72 #define USE_MMAP
    73 #ifndef USE_MMAP
    74 void do_process(FILE *infile, FILE *outfile, int count_only_option, int carry_count, int advance_count, process_block_fcn process_block);
    75 #endif
    76 #ifdef USE_MMAP
    7772void do_process(char * infile_buffer, size_t infile_size, FILE *outfile, int count_only_option, int carry_count, int advance_count, process_block_fcn process_block);
    78 #endif
    7973
    8074
     
    8680    FILE *infile, *outfile, *regexfile;
    8781
    88 #ifdef USE_MMAP
    8982    int fdSrc;
    9083    struct stat infile_sb;
    9184    char * infile_buffer;
    92 #endif
    9385
    9486    int opt_code;
     
    179171
    180172    infilename = argv[optind++];
    181 #ifndef USE_MMAP
    182     infile = fopen(infilename, "rb");
    183     if (!infile) {
    184         fprintf(stderr, "Error: cannot open %s for processing.\n", infilename);
    185         exit(-1);
    186     }
    187 #endif
    188173
    189174    if (optind >= argc) {
     
    206191    }
    207192
    208 #ifdef USE_MMAP
    209193    fdSrc = open(infilename, O_RDONLY);
    210194    if (fdSrc == -1) {
     
    225209        exit(-1);
    226210    }
    227 #endif
    228211
    229212    if (print_version_option)
     
    248231    {
    249232        void (*FP)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output) = (void (*)(const Basis_bits &basis_bits, BitBlock carry_q[], BitBlock advance_q[], Output &output))(void*)llvm_codegen.process_block_fptr;
    250 #ifndef USE_MMAP
    251         do_process(infile, outfile, count_only_option, llvm_codegen.carry_q_size, llvm_codegen.advance_q_size, FP);
    252 #endif
    253 #ifdef USE_MMAP
    254233        do_process(infile_buffer, infile_sb.st_size, outfile, count_only_option, llvm_codegen.carry_q_size, llvm_codegen.advance_q_size, FP);
    255 #endif
    256     }
    257 
    258 #ifndef USE_MMAP
    259     fclose(infile);
    260 #endif
    261 #ifdef USE_MMAP
     234    }
     235
    262236    munmap((void *) infile_buffer, infile_sb.st_size);
    263237    close(fdSrc);
    264 #endif
    265238    fclose(outfile);
    266239    if (regex_from_file_option) free(fileregex);
     
    314287
    315288
    316 #ifndef USE_MMAP
    317 void do_process(FILE *infile, FILE *outfile, int count_only_option, int carry_count, int advance_count, process_block_fcn process_block) {
    318 #endif
    319 #ifdef USE_MMAP
    320289void do_process(char * infile_buffer, size_t infile_size, FILE *outfile, int count_only_option, int carry_count, int advance_count, process_block_fcn process_block) {
    321 #endif
    322290
    323291    struct Basis_bits basis_bits;
     
    346314
    347315    char * buffer_ptr;
    348 #ifndef USE_MMAP
    349     ATTRIBUTE_SIMD_ALIGN char src_buffer[SEGMENT_SIZE];
    350     buffer_ptr = &src_buffer;
    351     chars_read = fread((void *)&src_buffer[0], 1, SEGMENT_SIZE, infile);
    352     chars_avail = chars_read;
    353     if (chars_avail >= SEGMENT_SIZE) chars_avail = SEGMENT_SIZE;
    354 #endif
    355 #ifdef USE_MMAP
    356316    int segment = 0;
    357317    int segment_base = 0;
    358318    chars_avail = infile_size;
    359319
    360 #endif
    361320//////////////////////////////////////////////////////////////////////////////////////////
    362321// Full Segments
     
    367326    while (chars_avail >= SEGMENT_SIZE) {
    368327
    369 #ifdef USE_MMAP
    370328        segment_base = segment * SEGMENT_SIZE;
    371 #endif
    372329        LF_scanner.init();
    373330        match_scanner.init();
    374331
    375332        for (blk = 0; blk < SEGMENT_BLOCKS; blk++) {
    376 #ifndef USE_MMAP
    377             block_base = blk*BLOCK_SIZE;
    378             s2p_do_block((BytePack *) &src_buffer[block_base], basis_bits);
    379 #endif
    380 #ifdef USE_MMAP
    381333            block_base = blk*BLOCK_SIZE + segment_base;
    382334            s2p_do_block((BytePack *) &infile_buffer[block_base], basis_bits);
    383 #endif
    384335            process_block(basis_bits, carry_q, advance_q, output);
    385336
     
    401352        }
    402353
    403 #ifndef USE_MMAP
    404         int copy_back_pos = 0;
    405 
    406 
    407         if (LF_scanner.count() > 0) {
    408             copy_back_pos = LF_scanner.get_final_pos() + 1;
    409             memset (carry_q, 0, sizeof(BitBlock) * carry_count);
    410             memset (advance_q, 0, sizeof(BitBlock) * advance_count);
    411         }
    412         else {
    413             copy_back_pos =  SEGMENT_SIZE;
    414         }
    415 
    416         int  copy_back_size = SEGMENT_SIZE - copy_back_pos;
    417 #endif
    418 #ifdef USE_MMAP
    419354    buffer_ptr = &infile_buffer[segment_base];
    420 #endif
    421355
    422356        if (!count_only_option) {
    423357          line_start = write_matches(outfile, LF_scanner, match_scanner, buffer_ptr, line_start);
    424358        }
    425 #ifndef USE_MMAP
    426         memmove(&src_buffer[0], &src_buffer[copy_back_pos], copy_back_size);
    427 
    428         //Do another read.
    429         chars_read = fread(&src_buffer[copy_back_size], 1, copy_back_pos, infile);
    430         chars_avail = chars_read + copy_back_size;
    431         if (chars_avail >= SEGMENT_SIZE) chars_avail = SEGMENT_SIZE;
    432         buffer_pos += chars_avail;
    433 #endif
    434 #ifdef USE_MMAP
    435359        segment++;
    436360        line_start -= SEGMENT_SIZE;  /* Will be negative offset for use within next segment. */
    437361        chars_avail -= SEGMENT_SIZE;
    438 #endif
    439362    }
    440363
     
    444367//////////////////////////////////////////////////////////////////////////////////////////
    445368
    446 #ifdef USE_MMAP
    447369    segment_base = segment * SEGMENT_SIZE;
    448 #endif
    449370    int remaining = chars_avail;
    450371
     
    456377    while (remaining >= BLOCK_SIZE) {
    457378    //fprintf(outfile, "Remaining = %i\n", remaining);
    458 #ifndef USE_MMAP
    459         block_base = block_pos;
    460         s2p_do_block((BytePack *) &src_buffer[block_base], basis_bits);
    461 #endif
    462 #ifdef USE_MMAP
    463379        block_base = block_pos + segment_base;
    464380        s2p_do_block((BytePack *) &infile_buffer[block_base], basis_bits);
    465 #endif
    466381        process_block(basis_bits, carry_q, advance_q, output);
    467382
     
    493408    //For the last partial block, or for any carry.
    494409    EOF_mask = bitblock::srl(simd<1>::constant<1>(), convert(BLOCK_SIZE-remaining));
    495 #ifndef USE_MMAP
    496      block_base = block_pos;
    497      s2p_do_final_block((BytePack *) &src_buffer[block_base], basis_bits, EOF_mask);
    498 #endif
    499 #ifdef USE_MMAP
    500410     block_base = block_pos + segment_base;
    501411     s2p_do_final_block((BytePack *) &infile_buffer[block_base], basis_bits, EOF_mask);
    502 #endif
    503412    process_block(basis_bits, carry_q, advance_q, output);
    504413
     
    522431            match_scanner.load_block(simd<1>::constant<0>(), i);
    523432        }
    524 #ifndef USE_MMAP
    525         line_start = 0;
    526 #endif
    527 #ifdef USE_MMAP
    528433        buffer_ptr = &infile_buffer[segment_base];
    529 #endif
    530434        line_start = write_matches(outfile, LF_scanner, match_scanner, buffer_ptr, line_start);
    531435    }
Note: See TracChangeset for help on using the changeset viewer.