int read_md5_file(const char *c) { char buff[HASH_LENGTH], found_name[256], remaining_name[256]; /* Create the found and remaining names */ snprintf(found_name, sizeof(found_name), "%s%s", c, ".found"); snprintf(remaining_name, sizeof(remaining_name), "%s%s", c, ".remaining"); /* Open the file to get the number of lines */ FILE *file = fopen(c, "r"); if (!file) { printf("%s failed to open password file: %d\n", __func__, errno); return 0; } found = fopen(found_name, "a"); remaining = fopen(remaining_name, "w"); if (!found) { printf("%s failed to open found password file: %d\n", __func__, errno); return 0; } else if (!remaining) { printf("%s failed to open remaining password file: %d\n", __func__, errno); return 0; } /* Count the number of lines */ while (fgets(buff, HASH_LENGTH, file)) count++; /* Initialize the buckets */ init_buckets(count); /* Allocate the buffer */ hash_buff = allocate_buffer(count); if (hash_buff == NULL) return 1; /* Read in the buffer */ fseek(file, 0, SEEK_SET); count = 0; while (fgets(buff, HASH_LENGTH, file)) { md5_binary(buff, &hash_buff[count]); count++; } qsort(hash_buff, count, sizeof(md5_binary_t), compare_md5); fclose(file); /* Build the buckets */ build_buckets(count); return count; }
int main(int argc, char **argv) { FILE *handles[128]; FILE *finput; int currChar; DataBucket buckets[128]; int j; char tempFileName[32] = { '\0' }; char *tempBuff; int i; int numRecords = FILE_SEEK_SIZE; struct timeval start_time,end_time; gettimeofday(&start_time,NULL); for (i = 32; i < 127; i++) { init_buckets(&buckets[i]); } tempBuff = (char *) malloc(sizeof(char) * FILE_SEEK_SIZE * RECORD_LENGTH); finput = fopen(argv[1], "rb"); for (i = 32; i < 127; i++) { sprintf(tempFileName, "%s.%d", argv[1], i); handles[i] = fopen(tempFileName, "wb"); } j = 0; do { numRecords = fread(tempBuff, RECORD_LENGTH, FILE_SEEK_SIZE, finput); //printf("%d\n",numRecords); for (i = 0; i < numRecords; i++) { currChar = tempBuff[i * RECORD_LENGTH]; strncpy(&buckets[currChar].dataStore[RECORD_LENGTH * buckets[currChar].numRecords], &tempBuff[i * RECORD_LENGTH], RECORD_LENGTH); buckets[currChar].numRecords++; } j++; if (j > 90) { for (i = 32; i < 127; i++) //printf("\n Bucket : %d Num of records %d", i,buckets[i].numRecords); fwrite(buckets[i].dataStore, RECORD_LENGTH * buckets[i].numRecords, 1, handles[i]); j = 0; //reinit buffers for (i = 32; i < 127; i++) buckets[i].numRecords = 0; } } while (numRecords == FILE_SEEK_SIZE); if (j <= 90) { for (i = 32; i < 127; i++) fwrite(buckets[i].dataStore, RECORD_LENGTH * buckets[i].numRecords, 1, handles[i]); } fclose(finput); for (i = 32; i < 127; i++) { if (handles[i] != NULL) { fclose(handles[i]); } } gettimeofday(&end_time,NULL); printf("\nTotal execution time - %lf s\n",(end_time.tv_sec - start_time.tv_sec) + (end_time.tv_usec - start_time.tv_usec)/1000000.0); return 0; }
int main(int argc, char *argv[]) { /* definitions */ int nocells; /* number of cells */ int nonets; /* number of nets */ int nopins; /* number of pins */ int noparts; /* number of partitions */ int totsize; /* total net weight of the partition */ int totcellsize; /* total cell weight of the partition */ int cutsize; /* cutsize of the partition */ int max_gain; /* max gain of a cell */ int max_density; /* max density of a cell */ int max_cweight; /* max cell weight */ int max_nweight; /* max net weight */ int bucketsize; /* max size of a bucket array */ int msize; /* index to mcells */ if (argc < 5) { printf("\nUsage: %s InputFileName NoParts InCount OutCount [Seed]\n", argv[0]); printf("\t#cells moved per phase = incount * nocells / 4\n"); printf("\t\tUse 1, 2, 3, or 4 for incount.\n"); printf("\t#cells moved per pass = nocells if outcount = 1,\n"); printf("\t#cells moved per pass = nocells * noparts if outcount = 2, and\n"); printf("\t#cells moved per pass = nocells * noparts * noparts if outcount = 3.\n"); exit(1); } /* if */ char fname[STR_SIZE]; sprintf(fname, "%s", argv[1]); noparts = atoi(argv[2]); int incount = atoi(argv[3]); int outcount = atoi(argv[4]); long seed; if (argc > 5) { seed = (long) atoi(argv[5]); } else { seed = (long) -1; } seed = randomize((long) seed); printf("SEED = %ld fname = %s\n", seed, fname); read_graph_size(fname, &nocells, &nonets); nopins = 2 * nonets; /* determine what in- & out-count imply */ int max_moved_cells = incount * nocells / 4; switch (outcount) { case 1 : outcount = nocells; break; case 2 : outcount = nocells * noparts; break; case 3 : outcount = nocells * noparts * noparts; break; default : break; } /* max_noiter = outcount / max_moved_cells;*/ /* do that many iterations */ int max_noiter = outcount; /* alloc memory for all data structures */ cells_t *cells = (cells_t *) calloc(nocells, sizeof(cells_t)); assert(cells != NULL); cells_info_t *cells_info = (cells_info_t *) calloc(nocells, sizeof(cells_info_t)); assert(cells_info != NULL); for (int i = 0; i < nocells; i++) { cells_info[i].mgain = (int *) calloc(noparts, sizeof(int)); cells_info[i].partb_ptr = (bnode_ptr_t *) calloc(noparts - 1, sizeof(bnode_ptr_t)); cells_info[i].partb_gain_inx = (int *) calloc(noparts - 1, sizeof(int)); } nets_t *nets = (nets_t *) calloc(nonets, sizeof(nets_t)); assert(nets != NULL); /* cells of nets */ corn_t *cnets = (corn_t *) calloc(nopins, sizeof(corn_t)); assert(cnets != NULL); /* partition buckets */ partb_t partb[noparts][noparts - 1]; parts_info_t parts_info[noparts]; /* population (w/ one individual!) */ ind_t pop[MAX_POP]; for (int i = 0; i < MAX_POP; i++) { pop[i].chrom = (allele *) calloc(nocells, sizeof(allele)); pop[i].parts = (parts_t *) calloc(noparts, sizeof(parts_t)); } /* selected cell */ selected_cell_t scell[1]; /* moved cells */ mcells_t *mcells = (mcells_t *) calloc(2 * max_noiter, sizeof(mcells_t)); assert(mcells != NULL); /* temp chrom */ allele *tchrom = (allele *) calloc(nocells, sizeof(allele)); assert(tchrom != NULL); read_graph(fname, nocells, nonets, noparts, &totsize, &totcellsize, &max_density, &max_cweight, &max_nweight, cells, nets, cnets); max_gain = max_density * max_nweight; bucketsize = 2 * max_gain + 1; /* alloc memory (statically if possible) */ for (int i = 0; i < noparts; i++) { for (int j = 0; j < noparts - 1; ++j) { partb[i][j].bnode_ptr = (bnode_ptr_t *) calloc(bucketsize, sizeof(bnode_ptr_t)); } } create_partition(nocells, noparts, totcellsize, cells, &pop[0]); #ifdef DEBUG printf("Initial : Part_no min_size curr_size max_size\n"); for (int i = 0; i < noparts; i++) { printf("II %d %d %d %d\n", i, pop[0].parts[i].pmin_size, pop[0].parts[i].pcurr_size, pop[0].parts[i].pmax_size); } #endif init_buckets(noparts, bucketsize, partb); cutsize = find_cut_size(nonets, totsize, nets, &pop[0]); #ifdef DEBUG printf("Totalsize = %d Initial cutsize = %d\n", totsize, cutsize); #endif int gain_sum; int glob_inx = 0; int pass_no = 0; do { copy_partition(noparts, parts_info, &pop[0]); for (int i = 0; i < nocells; i++) { tchrom[i] = pop[0].chrom[i]; } msize = 0; int noiter = 0; while (noiter < max_noiter) { compute_gains(nocells, noparts, tchrom, cells, nets, cnets, cells_info); create_buckets(nocells, noparts, max_gain, tchrom, partb, cells_info); /* max_moved_cells = nocells / 2; */ int nlocked = 0; do { int move_possible = select_cell(noparts, scell, parts_info, cells, partb, cells_info); delete_partb_nodes_of_cell(noparts, scell[0].mov_cell_no, scell[0].from_part, partb, cells_info); /* lock cell */ cells_info[scell[0].mov_cell_no].locked = True; if (move_possible == True) { move_cell(mcells, msize, scell, tchrom); msize++; update_gains(noparts, max_gain, scell, tchrom, cells, nets, cnets, partb, cells_info); } /* if */ nlocked++; noiter++; } while ((nlocked < max_moved_cells) && (noiter < max_noiter)); free_nodes(noparts, bucketsize, partb); } /* while */ int max_mcells_inx; gain_sum = find_move_set(mcells, msize, &max_mcells_inx); #ifdef DEBUG printf("gain_sum=%d max_mcells_inx=%d msize = %d\n", gain_sum, max_mcells_inx, msize); #endif if (gain_sum > 0) { int cut_gain = move_cells(False, mcells, max_mcells_inx, cutsize, &glob_inx, &pop[0], cells); cutsize -= cut_gain; } /* if */ pass_no++; #ifdef DEBUG printf("pass_no = %d Final cutsize = %d Check cutsize = %d\n", pass_no, cutsize, find_cut_size(nonets, totsize, nets, &pop[0])); #endif } while ((gain_sum > 0) && (cutsize > 0)); printf("pass_no = %d Final cutsize = %d Check cutsize = %d\n", pass_no, cutsize, find_cut_size(nonets, totsize, nets, &pop[0])); free_nodes(noparts, bucketsize, partb); #ifdef DEBUG printf("Final : Part_no min_size curr_size max_size\n"); for (int i = 0; i < noparts; i++) { printf("FF %d %d %d %d\n", i, pop[0].parts[i].pmin_size, pop[0].parts[i].pcurr_size, pop[0].parts[i].pmax_size); } #endif /* free memory for all data structures */ cfree(cells); for (int i = 0; i < nocells; i++) { cfree(cells_info[i].mgain); cfree(cells_info[i].partb_ptr); cfree(cells_info[i].partb_gain_inx); } cfree(cells_info); cfree(nets); cfree(cnets); for (int i = 0; i < noparts; i++) { for (int j = 0; j < noparts - 1; ++j) { cfree(partb[i][j].bnode_ptr); } } for (int i = 0; i < MAX_POP; i++) { cfree(pop[i].chrom); cfree(pop[i].parts); } cfree(mcells); cfree(tchrom); return (0); } /* main-plm */
int __init buses_init(void) { init_buckets(_bus_buckets); return subsystem_register(&bus_subsys); }
Simulation::Simulation(){ init_buckets(); simulate(); }