int main(void) { int i1 = 1, j1 = 2, k1 = 2; /* Give i1, j1 and k1 all possible values with 0 < i1 < j1 < k1 < 9. */ while (create_partition(&i1, &j1, &k1)) { int numbers1[4]; /* Store in numbers1 the number consisting * of the first i1 digits in digits[], * then the number consisting of the j1 - i1 next digits in digits[], * then the number consisting of the k1 - j1 next digits in digits[], * and eventually the number consisting * of the remaining digits in digits[], * with at least 2 of those remaining digits.*/ generate_numbers(i1, j1, k1, numbers1); int i2 = i1; int j2 = j1; int k2 = k1; /* Give i2, j2 and k2 all possible values with 0 < i2 < j2 < k2 < 9 * and (i1, j1, k1) < (i2, j2, k2). */ while (create_partition(&i2, &j2, &k2)) { int numbers2[4]; /* Store in numbers2 the number consisting * of the first i2 digits in digits[], * then the number consisting of the j2 - i2 next digits in digits[], * then the number consisting of the k2 - j2 next digits in digits[], * and eventually the number consisting * of the remaining digits in digits[], * with at least 2 of those remaining digits.*/ generate_numbers(i2, j2, k2, numbers2); int product = numbers1[0] * numbers1[1] * numbers1[2] * numbers1[3]; if (numbers2[0] * numbers2[1] * numbers2[2] * numbers2[3] == product) print_solution(numbers1, numbers2, product); } } return EXIT_SUCCESS; }
void Enumerator::create_partition(std::vector<Plane>& partition, Plane& left) { if (left.size() == 0) { Plane cen = centroid(partition); double costs = evaluate_partition(partition, cen, fix_costs); if (costs < best_costs) { best_costs = costs; best_sites = cen; best_partition = partition; //std::cout << "current best value = " << costs << std::endl; } return; } Point current = left.back(); left.pop_back(); // insert into each existing subset for (unsigned int i = 0; i < partition.size(); ++i) { if ((int) partition[i].size() < capacity) { //only if <capacity partition[i].push_back(current); create_partition(partition, left); partition[i].pop_back(); } } // deal with case: new subset for current element partition.push_back(Plane()); partition.back().push_back(current); create_partition(partition, left); partition.pop_back(); // restore left.push_back(current); }
static gboolean handle_create_partition (CockpitStorageBlock *object, GDBusMethodInvocation *invocation, guint64 arg_offset, guint64 arg_size, const gchar *arg_type, const gchar *arg_erase, const gchar *arg_label, const gchar *arg_passphrase, const gchar *arg_mount_point, const gchar *arg_mount_options, const gchar *arg_crypto_passphrase, const gchar *arg_crypto_options) { StorageBlock *block = STORAGE_BLOCK(object); GError *error = NULL; gboolean is_extended = (g_strcmp0 (arg_type, "dos-extended") == 0); if (!auth_check_sender_role (invocation, COCKPIT_ROLE_STORAGE_ADMIN)) return TRUE; UDisksBlock *partition_block = create_partition (block, arg_offset, arg_size, (is_extended ? "0x05" : ""), &error); if (partition_block == NULL) { g_dbus_error_strip_remote_error (error); g_dbus_method_invocation_return_error (invocation, COCKPIT_ERROR, COCKPIT_ERROR_FAILED, "%s", error->message); g_error_free (error); return TRUE; } if (!is_extended) { start_format_and_configure_block (storage_object_get_provider (block->object), partition_block, invocation, arg_type, arg_erase, arg_label, arg_passphrase, arg_mount_point, arg_mount_options, arg_crypto_passphrase, arg_crypto_options); } else cockpit_storage_block_complete_create_partition (object, invocation); return TRUE; }
int main(int argc, char *argv[]){ disk_info_t *disk_info, *disk_list; partition_info_t *partition_info; char buf[PATH_MAX]; usb_dbg("%d: Using myself to get information:\n", VERSION); if(argc == 3){ get_mount_path("sdb1", buf, PATH_MAX); printf("buf=%s.\n", buf); } else if(argc == 2){ if(is_disk_name(argv[1])){ // Disk usb_dbg("%d: Get disk(%s)'s information:\n", VERSION, argv[1]); create_disk(argv[1], &disk_info); print_disk(disk_info); free_disk_data(&disk_info); } else{ usb_dbg("%d: Get partition(%s)'s information:\n", VERSION, argv[1]); create_partition(argv[1], &partition_info); print_partition(partition_info); free_partition_data(&partition_info); } } else{ usb_dbg("%d: Get all Disk information:\n", VERSION); disk_list = read_disk_data(); print_disks(disk_list); free_disk_data(&disk_list); } return 0; }
disk_info_t *read_disk_data(void) { FILE *fp; char line[64], device_name[32]; u32 major, minor; disk_info_t *disk_info_list, *parent_disk_info, **follow_disk_info_list; partition_info_t *new_partition_info, **follow_partition_list; unsigned long long device_size; fp = fopen(PARTITION_FILE, "r"); if (!fp) return NULL; if (!fgets(line, sizeof(line), fp)) { fclose(fp); return NULL; } fgets(line, sizeof(line), fp); disk_info_list = NULL; while (fgets(line, sizeof(line), fp)) { device_name[0] = 0; if (sscanf(line, "%u %u %llu %[^\n ]", &major, &minor, &device_size, device_name) != 4) continue; if(major != USB_DISK_MAJOR) continue; if(device_size < 10) continue; if (is_disk_name(device_name)) { follow_disk_info_list = &disk_info_list; while(*follow_disk_info_list) follow_disk_info_list = &((*follow_disk_info_list)->next); create_disk(device_name, follow_disk_info_list); } else if (is_partition_name(device_name, NULL)) { parent_disk_info = disk_info_list; while(1) { if (!parent_disk_info) goto info_exit; if (!strncmp(device_name, parent_disk_info->device, 3)) break; parent_disk_info = parent_disk_info->next; } follow_partition_list = &(parent_disk_info->partitions); while(*follow_partition_list) follow_partition_list = &((*follow_partition_list)->next); new_partition_info = create_partition(device_name, follow_partition_list); if(new_partition_info) new_partition_info->disk = parent_disk_info; } } info_exit: fclose(fp); return disk_info_list; }
disk_info_t *create_disk(const char *device_name, disk_info_t **new_disk_info) { disk_info_t *follow_disk_info; u32 major, minor; u64 size_in_kilobytes = 0; int len; char buf[128], *vendor, *model, *ptr; partition_info_t *new_partition_info, **follow_partition_list; if(!new_disk_info) return NULL; *new_disk_info = NULL; // initial value. vendor = NULL; model = NULL; if(!device_name || !is_disk_name(device_name)) return NULL; if(!initial_disk_data(&follow_disk_info)) return NULL; len = strlen(device_name); follow_disk_info->device = (char *)malloc(len+1); if (!follow_disk_info->device){ free_disk_data(follow_disk_info); return NULL; } strcpy(follow_disk_info->device, device_name); if(!get_disk_major_minor(device_name, &major, &minor)){ free_disk_data(follow_disk_info); return NULL; } follow_disk_info->major = major; follow_disk_info->minor = minor; if(!get_disk_size(device_name, &size_in_kilobytes)){ free_disk_data(follow_disk_info); return NULL; } follow_disk_info->size_in_kilobytes = size_in_kilobytes; if(!strncmp(device_name, "sd", 2)){ if(!get_usb_root_port_by_device(device_name, buf, sizeof(buf))){ free_disk_data(follow_disk_info); return NULL; } len = strlen(buf); if(len > 0){ int port_num = get_usb_root_port_number(buf); if (port_num < 0) port_num = 0; follow_disk_info->port_root = port_num; } // start get vendor. if(!get_disk_vendor(device_name, buf, sizeof(buf))){ free_disk_data(follow_disk_info); return NULL; } len = strlen(buf); if(len > 0){ vendor = (char *)malloc(len+1); if(!vendor){ free_disk_data(follow_disk_info); return NULL; } strcpy(vendor, buf); strntrim(vendor); sanity_name(vendor); follow_disk_info->vendor = vendor; } // start get model. if(get_disk_model(device_name, buf, sizeof(buf)) == NULL){ free_disk_data(follow_disk_info); return NULL; } len = strlen(buf); if(len > 0){ model = (char *)malloc(len+1); if(!model){ free_disk_data(follow_disk_info); return NULL; } strcpy(model, buf); strntrim(model); sanity_name(model); follow_disk_info->model = model; } // get USB's tag memset(buf, 0, sizeof(buf)); len = 0; ptr = buf; if(vendor){ len += strlen(vendor); strcpy(ptr, vendor); ptr += len; } if(model){ if(len > 0){ ++len; // Add a space between vendor and model. strcpy(ptr, " "); ++ptr; } len += strlen(model); strcpy(ptr, model); ptr += len; } if(len > 0){ follow_disk_info->tag = (char *)malloc(len+1); if(!follow_disk_info->tag){ free_disk_data(follow_disk_info); return NULL; } strcpy(follow_disk_info->tag, buf); } else{ len = strlen(DEFAULT_USB_TAG); follow_disk_info->tag = (char *)malloc(len+1); if(!follow_disk_info->tag){ free_disk_data(follow_disk_info); return NULL; } strcpy(follow_disk_info->tag, DEFAULT_USB_TAG); } follow_partition_list = &(follow_disk_info->partitions); while(*follow_partition_list) follow_partition_list = &((*follow_partition_list)->next); new_partition_info = create_partition(device_name, follow_partition_list); if(new_partition_info){ new_partition_info->disk = follow_disk_info; ++(follow_disk_info->partition_number); ++(follow_disk_info->mounted_number); } } if(follow_disk_info->partition_number == 0) get_disk_partitionnumber(device_name, &(follow_disk_info->partition_number), &(follow_disk_info->mounted_number)); *new_disk_info = follow_disk_info; return *new_disk_info; }
disk_info_t *create_disk(const char *device_name, disk_info_t **new_disk_info){ disk_info_t *follow_disk_info; u32 major, minor; u64 size_in_kilobytes = 0; int len; char usb_node[32], port_path[8]; char buf[64], *port, *vendor = NULL, *model = NULL, *ptr; partition_info_t *new_partition_info, **follow_partition_list; if(new_disk_info == NULL){ usb_dbg("Bad input!!\n"); return NULL; } *new_disk_info = NULL; // initial value. if(device_name == NULL || !is_disk_name(device_name)) return NULL; if(initial_disk_data(&follow_disk_info) == NULL){ usb_dbg("No memory!!(follow_disk_info)\n"); return NULL; } len = strlen(device_name); follow_disk_info->device = (char *)malloc(len+1); if(follow_disk_info->device == NULL){ usb_dbg("No memory!!(follow_disk_info->device)\n"); free_disk_data(&follow_disk_info); return NULL; } strcpy(follow_disk_info->device, device_name); follow_disk_info->device[len] = 0; if(!get_disk_major_minor(device_name, &major, &minor)){ usb_dbg("Fail to get disk's major and minor: %s.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } follow_disk_info->major = major; follow_disk_info->minor = minor; if(!get_disk_size(device_name, &size_in_kilobytes)){ usb_dbg("Fail to get disk's size_in_kilobytes: %s.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } follow_disk_info->size_in_kilobytes = size_in_kilobytes; if(!strncmp(device_name, "sd", 2)){ // Get USB node. if(get_usb_node_by_device(device_name, usb_node, 32) == NULL){ usb_dbg("(%s): Fail to get usb node.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } if(get_path_by_node(usb_node, port_path, 8) == NULL){ usb_dbg("(%s): Fail to get usb path.\n", usb_node); free_disk_data(&follow_disk_info); return NULL; } // Get USB port. if(get_usb_port_by_string(usb_node, buf, 64) == NULL){ usb_dbg("Fail to get usb port: %s.\n", usb_node); free_disk_data(&follow_disk_info); return NULL; } len = strlen(buf); if(len > 0){ port = (char *)malloc(8); if(port == NULL){ usb_dbg("No memory!!(port)\n"); free_disk_data(&follow_disk_info); return NULL; } memset(port, 0, 8); strncpy(port, port_path, 8); follow_disk_info->port = port; } // start get vendor. if(get_disk_vendor(device_name, buf, 64) == NULL){ usb_dbg("Fail to get disk's vendor: %s.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } len = strlen(buf); if(len > 0){ vendor = (char *)malloc(len+1); if(vendor == NULL){ usb_dbg("No memory!!(vendor)\n"); free_disk_data(&follow_disk_info); return NULL; } strncpy(vendor, buf, len); vendor[len] = 0; strntrim(vendor); follow_disk_info->vendor = vendor; } // start get model. if(get_disk_model(device_name, buf, 64) == NULL){ usb_dbg("Fail to get disk's model: %s.\n", device_name); free_disk_data(&follow_disk_info); return NULL; } len = strlen(buf); if(len > 0){ model = (char *)malloc(len+1); if(model == NULL){ usb_dbg("No memory!!(model)\n"); free_disk_data(&follow_disk_info); return NULL; } strncpy(model, buf, len); model[len] = 0; strntrim(model); follow_disk_info->model = model; } // get USB's tag memset(buf, 0, 64); len = 0; ptr = buf; if(vendor != NULL){ len += strlen(vendor); strcpy(ptr, vendor); ptr += len; } if(model != NULL){ if(len > 0){ ++len; // Add a space between vendor and model. strcpy(ptr, " "); ++ptr; } len += strlen(model); strcpy(ptr, model); ptr += len; } if(len > 0){ follow_disk_info->tag = (char *)malloc(len+1); if(follow_disk_info->tag == NULL){ usb_dbg("No memory!!(follow_disk_info->tag)\n"); free_disk_data(&follow_disk_info); return NULL; } strcpy(follow_disk_info->tag, buf); follow_disk_info->tag[len] = 0; } else{ len = strlen(DEFAULT_USB_TAG); follow_disk_info->tag = (char *)malloc(len+1); if(follow_disk_info->tag == NULL){ usb_dbg("No memory!!(follow_disk_info->tag)\n"); free_disk_data(&follow_disk_info); return NULL; } strcpy(follow_disk_info->tag, DEFAULT_USB_TAG); follow_disk_info->tag[len] = 0; } follow_partition_list = &(follow_disk_info->partitions); while(*follow_partition_list != NULL) follow_partition_list = &((*follow_partition_list)->next); new_partition_info = create_partition(device_name, follow_partition_list); if(new_partition_info != NULL){ new_partition_info->disk = follow_disk_info; ++(follow_disk_info->partition_number); ++(follow_disk_info->mounted_number); if(!strcmp(new_partition_info->device, follow_disk_info->device)) new_partition_info->size_in_kilobytes = follow_disk_info->size_in_kilobytes-4; } } if(!strcmp(follow_disk_info->device, follow_disk_info->partitions->device)) get_disk_partitionnumber(device_name, &(follow_disk_info->partition_number), &(follow_disk_info->mounted_number)); *new_disk_info = follow_disk_info; return *new_disk_info; }
disk_info_t *read_disk_data(){ disk_info_t *disk_info_list = NULL, *new_disk_info, **follow_disk_info_list; char *partition_info = read_whole_file(PARTITION_FILE); char *follow_info; char line[64], device_name[16]; u32 major; disk_info_t *parent_disk_info; partition_info_t *new_partition_info, **follow_partition_list; u64 device_size; if(partition_info == NULL){ usb_dbg("Failed to open \"%s\"!!\n", PARTITION_FILE); return disk_info_list; } follow_info = partition_info; memset(device_name, 0, 16); while(get_line_from_buffer(follow_info, line, 64) != NULL){ follow_info += strlen(line); if(sscanf(line, "%u %*u %llu %[^\n ]", &major, &device_size, device_name) != 3) continue; if(major != USB_DISK_MAJOR) continue; if(device_size == 1) // extend partition. continue; if(is_disk_name(device_name)){ // Disk follow_disk_info_list = &disk_info_list; while(*follow_disk_info_list != NULL) follow_disk_info_list = &((*follow_disk_info_list)->next); new_disk_info = create_disk(device_name, follow_disk_info_list); } else if(is_partition_name(device_name, NULL)){ // Partition // Found a partition device. // Find the parent disk. parent_disk_info = disk_info_list; while(1){ if(parent_disk_info == NULL){ usb_dbg("Error while parsing %s: found " "partition '%s' but haven't seen the disk device " "of which it is a part.\n", PARTITION_FILE, device_name); free(partition_info); return disk_info_list; } if(!strncmp(device_name, parent_disk_info->device, 3)) break; parent_disk_info = parent_disk_info->next; } follow_partition_list = &(parent_disk_info->partitions); while(*follow_partition_list != NULL){ if((*follow_partition_list)->partition_order == 0){ free_partition_data(follow_partition_list); parent_disk_info->partitions = NULL; follow_partition_list = &(parent_disk_info->partitions); } else follow_partition_list = &((*follow_partition_list)->next); } new_partition_info = create_partition(device_name, follow_partition_list); if(new_partition_info != NULL) new_partition_info->disk = parent_disk_info; } } free(partition_info); return disk_info_list; }
int main (int argc, char** argv) { int rank; /* process id */ int P; /* number of processes */ int ret; /* return values */ uint64_t n; /* number of parameter */ int64_t* numbers; /* given numbers */ int64_t tmp; int64_t sum; partition part; /* local partition */ partition part_r; /* dst partition */ if (argc == 1) /* keine Parameter */ return EXIT_SUCCESS; if ((ret = MPI_Init(&argc, &argv)) != MPI_SUCCESS) { printf("Error initializing MPI\n"); MPI_Abort(MPI_COMM_WORLD, ret); } MPI_Comm_size(MPI_COMM_WORLD, &P); MPI_Comm_rank(MPI_COMM_WORLD, &rank); n = (uint64_t)argc - 1; create_partition(&part, n, (uint64_t)P, (uint64_t)rank); if (rank == 0) { numbers = malloc(n * sizeof(int64_t)); if (numbers == NULL) { printf("memory allocation failed\n"); MPI_Abort(MPI_COMM_WORLD, -1); } for (uint64_t i = 0; i < n; ++i) numbers[i] = atoi(argv[i + 1]); for (int r = 1; r < P; ++r) { create_partition(&part_r, n, (uint64_t)P, (uint64_t)r); /* distribute numbers */ if (part_r.len > 0) MPI_Send(numbers + part_r.start, (int)part_r.len, MPI_INT64_T, r, r, MPI_COMM_WORLD); } sum = 0; for (uint64_t i = 0; i < part.len; ++i) sum += numbers[i]; for (int r = 1; r < P; ++r) { /* recv and add sums */ MPI_Recv(&tmp, 1, MPI_INT64_T, r, r, MPI_COMM_WORLD, NULL); sum += tmp; } printf("Summe: %" PRIu64 "\n", sum); free(numbers); } else { tmp = 0; if (part.len > 0) { numbers = malloc(part.len * sizeof(int64_t)); if (numbers == NULL) { printf("memory allocation failed\n"); MPI_Abort(MPI_COMM_WORLD, -1); } /* recv numbers */ MPI_Recv(numbers, (int)part.len, MPI_INT64_T, 0, rank, MPI_COMM_WORLD, NULL); for (uint64_t i = 0; i < part.len; ++i) tmp += numbers[i]; free(numbers); } /* send sum */ MPI_Send(&tmp, 1, MPI_INT64_T, 0, rank, MPI_COMM_WORLD); } MPI_Finalize(); return EXIT_SUCCESS; }
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 */