Ejemplo n.º 1
0
static void do_partition(msieve_obj *obj,
			graph_t *graph, heap_t *heap,
			uint32 row_start, uint32 row_end,
			uint32 col_start, uint32 col_end) {

	uint32 min_edge_cut, edge_cut;
	uint32 row_start1, row_start2;
	uint32 col_start1, col_start2;
#ifdef VERBOSE
	printf("optimize [%u,%u] x [%u,%u]\n",
			row_start, row_end, col_start, col_end);
#endif
	edge_cut = heap_init(obj, graph, heap,
		       		row_start, row_end,
				col_start, col_end);
	do {
		min_edge_cut = edge_cut;
#ifdef VERBOSE
		printf("edge cut = %u\n", edge_cut);
#endif
		edge_cut = do_partition_core(graph, heap, edge_cut,
						row_start, row_end,
						col_start, col_end);
	} while (min_edge_cut - edge_cut > 1000);

#ifdef VERBOSE
	printf("edge cut = %u\n", edge_cut);
#endif

	permute_graph(graph,
			row_start, row_end,
			col_start, col_end,
			&row_start1, &row_start2,
			&col_start1, &col_start2);

	if (col_end - col_start2 > MIN_BLOCKSIZE) {
		do_partition(obj, graph, heap,
				row_start2, row_end,
				col_start2, col_end);
	}
	if (col_start2 - col_start1 > MIN_BLOCKSIZE) {
		do_partition(obj, graph, heap,
				row_start1, row_start2 - 1,
				col_start1, col_start2 - 1);
	}
	if (col_start1 - col_start > MIN_BLOCKSIZE) {
		do_partition(obj, graph, heap,
				row_start, row_start1 - 1,
				col_start, col_start1 - 1);
	}
}
 vector<vector<string> > partition(string s) {
     vector<vector<string> > res;
     if(s.size() == 0)
         return res;
     vector<string> tmp_res;
     do_partition(s, 0, res, tmp_res);
     return res;
 }
Ejemplo n.º 3
0
/*--------------------------------------------------------------------*/
void reorder_matrix(msieve_obj *obj, 
		    uint32 **rowperm, 
		    uint32 **colperm) {

	graph_t graph;
	heap_t heap;

	logprintf(obj, "permuting matrix for faster multiplies\n");

	graph_init(obj, &graph, &heap);

	do_partition(obj, &graph, &heap,
			graph.num_cols, 
			graph.num_cols + graph.num_rows - 1,
			0, 
			graph.num_cols - 1);

	graph_free(&graph, rowperm, colperm);
}
 void do_partition(string &s, int cur_pos,
                     vector<vector<string> >  &res, vector<string> &tmp_res)
 {
     if(cur_pos == s.size()) {
         if(!tmp_res.empty())
             res.push_back(tmp_res);
         return ;
     }
     int start;
     string cur = "";
     for(start = cur_pos; start < s.size(); start++) {
         cur += s[start];
         if(check(cur)) {
             tmp_res.push_back(cur);
             do_partition(s, start + 1, res, tmp_res);
             tmp_res.pop_back();
         }
     }
 }