Exemplo n.º 1
0
int main(int argc, char** argv) {
	Options options;
	ParseOptions(argc, argv, &options);

	srand(options.seed);

	std::vector<float> matrix_a(options.row_a * options.column_a);
	std::vector<float> matrix_b(options.row_b * options.column_b);
	std::vector<float> matrix_c(options.row_b * options.column_a);

	SetRandomInit(matrix_a.size(), &matrix_a[0]);
	SetRandomInit(matrix_b.size(), &matrix_b[0]);

	//std::cout << "Matrix a" << std::endl;
	//PrintMatrix(options.column_a, options.row_a, &matrix_a[0]);
	std::cout << "Matrix a size=(\t" << options.column_a << ",\t"
			<< options.row_a << ")" << std::endl;
	//std::cout << "Matrix b" << std::endl;
	//PrintMatrix(options.column_b, options.row_b, &matrix_b[0]);
	std::cout << "Matrix b size=(\t" << options.column_b << ",\t"
			<< options.row_b << ")" << std::endl;

	std::cout << "Matrix c size=(\t" << options.column_a << ",\t"
				<< options.row_b << ")" << std::endl;
       
	std::cout << "Selected implimentation is " << GetName(options.implementation) << std::endl;
	double start_time = GetTimeSec();
	if (MultiplyMatrices(options.implementation, options.column_a,
			options.row_a, &matrix_a[0], options.column_b, options.row_b,
			&matrix_b[0], &matrix_c[0])) {
		std::cerr << "Error : multiply" << std::endl;
	}
	double end_time = GetTimeSec();

	//std::cout << "Matrix c" << std::endl;
	//PrintMatrix(options.column_a, options.row_b, &matrix_c[0]);

	std::cout << "Time : ";
	std::cout.precision(6);
	std::cout.width(10);
	std::cout << end_time - start_time << " sec" << std::endl;

	if (options.checking_result) {
		std::cout << "Checking Result" << std::endl;
		std::vector<float> reference_matrix_c(options.row_b * options.column_a);
		if (MultiplyMatrices(kCpuReference, options.column_a, options.row_a,
				&matrix_a[0], options.column_b, options.row_b, &matrix_b[0],
				&reference_matrix_c[0])) {
			std::cerr << "Error : multiply" << std::endl;
		}
		PrintDiff(options.column_a, options.row_b, &reference_matrix_c[0],
				&matrix_c[0], 100, 1.0e-5f);
	}
}
Exemplo n.º 2
0
int main(int argc, char *argv[]){

	if(argc != 4){
		std::cerr << "usage: ./matmult A.in B.in C.out" << std::endl;
		return -1;
	}
	
	Matrix matrix_a(argv[1]);
	Matrix matrix_b(argv[2]);
	Matrix matrix_c = matrix_a*matrix_b;
	matrix_c.print(argv[3]);
	return 0;
}
Exemplo n.º 3
0
void network_generator::network_evolution(const char **file){
	
	long double coolant_flow_rate;
	long double unit_pressure_drop = 100.0;
	
	stringstream ss;
	ss << file[channel_layer+2];
	ss >> coolant_flow_rate;
	
	if(!Is_Meaningful()){
		return ;
	}
	while(1){
		print_network();
		long double total_Q = 0;
		vector <int> network_col(101,0);
		vector < vector <int> > single_network(101,network_col);
        vector < vector < vector <int> > > network(channel_layer,single_network);
        vector <int> channel_info_col(101,-1);
        vector < vector <int> > single_channel_info(101,channel_info_col);
		vector < vector < vector <int> > > channel_info(channel_layer,single_channel_info);
		vector <long double> flowrate_col(101,0);
		vector < vector <long double> > single_flow_rate(101,flowrate_col);
		vector < vector < vector <long double> > > flow_rate(channel_layer,single_flow_rate);
		vector < vector < vector <int> > > direction(channel_layer,single_network);
		vector < matrix > matrix_a(channel_layer);
		vector < vector <node> > tempnode(channel_layer);
		vector < vector <edge_info> > edges(channel_layer);
		for (int i = 0; i < channel_layer; i++) {
			network_graph( &liquid_network[i], &tempnode[i], &edges[i]);
			cout << "network_graph done!" << endl;
			matrix_a[i].get_num_channel(&tempnode[i], &edges[i]);
			cout << "get_num_channel done!" << endl;
            matrix_a[i].initial_direction(&tempnode[i], &edges[i]);
            cout << "initial_direction done!" << endl;
            matrix_a[i].write_spice_input(&i, &tempnode[i],unit_pressure_drop);
            cout << "write_spice_input done!" << endl;
            string spice_sim = "hspice spice_";
			spice_sim += i + 48;
			spice_sim += ".txt";
			spice_sim += " > test_";
			spice_sim += i + 48;
			spice_sim += ".txt";
			cout << spice_sim << endl;
			system(spice_sim.c_str());
            matrix_a[i].read_spice_result(&i);
            cout << "read_spice_result done!" << endl;
            matrix_a[i].get_inlet_Q(&tempnode[i]);
		}
		for (int i = 0; i < channel_layer; i++) {
			total_Q += matrix_a[i].inlet_Q;
			//cout << i << " " << "total_Q " << total_Q << "\t" ;
		}
		for (int i = 0; i < channel_layer; i++) {
			cout << "\nchannel_layer " << i << endl;
			matrix_a[i].get_pressure_drop(chip.width, chip.height, chip.length, coolant_flow_rate, unit_pressure_drop, total_Q);
			matrix_a[i].fill_flow_rate(&tempnode[i] ,&edges[i],&flow_rate[i],&channel_info[i]);
			matrix_a[i].fill_direction(&tempnode[i] ,&edges[i],&direction[i]);
			matrix_a[i].write_output(&i,&liquid_network[i], &tempnode[i],&flow_rate[i],&direction[i],&channel_info[i]);
		}
		
		//cout << "file done !" << endl;
		vector < RTree<int, int, 2, float>* > edge_rtree(channel_layer);
		for( int i=0;i<channel_layer;i++ ){
			edge_rtree[i] = new RTree<int, int, 2, float>;
			int minp[2], maxp[2];
			for( int j=0;j<edges[i].size();j++ ){
				minp[0] = min(tempnode[i][edges[i][j].nodes.first].coordinate.first, tempnode[i][edges[i][j].nodes.second].coordinate.first);
				minp[1] = min(tempnode[i][edges[i][j].nodes.first].coordinate.second, tempnode[i][edges[i][j].nodes.second].coordinate.second);
				maxp[0] = max(tempnode[i][edges[i][j].nodes.first].coordinate.first, tempnode[i][edges[i][j].nodes.second].coordinate.first);
				maxp[1] = max(tempnode[i][edges[i][j].nodes.first].coordinate.second, tempnode[i][edges[i][j].nodes.second].coordinate.second);
				if(edges[i][j].HV == 'H'){
					minp[0] += 1;
					maxp[0] -= 1;
					/*cout << tempnode[i][edges[i][j].nodes.first].coordinate.first << " " << tempnode[i][edges[i][j].nodes.second].coordinate.first << endl;
					cout << tempnode[i][edges[i][j].nodes.first].coordinate.second << " " << tempnode[i][edges[i][j].nodes.second].coordinate.second << endl;
					cout << minp[0] << " " << maxp[0] << endl;
					cout << minp[1] << " " << maxp[1] << endl;*/
					//getchar();
				}
				else if(edges[i][j].HV == 'V'){
					minp[1] += 1;
					maxp[1] -= 1;
				}
				if(edges[i][j].HV != 'N'){
					edge_rtree[i]->Insert(minp, maxp, j);
				}
			}
		}
		//cout << "Rtree done !" << endl;
		/*int minp[2], maxp[2];
		minp[0] = 17;
		minp[1] = 0;
		maxp[0] = 17;
		maxp[1] = 4;
		vector <int> edge_list;
		for( int i=0;i<channel_layer;i++ ){
			edge_list.clear();
			edge_rtree[i]->Search(minp, maxp, &edge_list);
			for( int k=0;k<edge_list.size();k++ ){
				cout << tempnode[i][edges[i][edge_list[k]].nodes.first].coordinate.first << " " << tempnode[i][edges[i][edge_list[k]].nodes.first].coordinate.second << endl;
				cout << tempnode[i][edges[i][edge_list[k]].nodes.second].coordinate.first << " " << tempnode[i][edges[i][edge_list[k]].nodes.second].coordinate.second << endl;
			}
			cout << edge_list.size() << endl;
		}
		getchar();*/
		
		chdir("3d-ice/bin/");
		string simulator = "./3D-ICE-Emulator test_case_0";
		simulator += chip.case_num + 48;
		simulator += ".stk";
		for( int i=0;i<channel_layer;i++ ){
			simulator += " ../../network_";
			simulator += i+48;
			simulator += " ../../flowrate_";
			simulator += i+48;
			simulator += " ../../direction_";
			simulator += i+48;
		}
		//cout << simulator << endl;
		system(simulator.c_str());
		//getchar();
		
		chdir("../../");
		ifstream *fin = new ifstream[channel_layer+1];
		vector < vector < vector <double> > > T_map;
		double T_max = 0, T_min = 1<<30;
		pair<int, int> target;
		for( int i=0;i<channel_layer+1;i++ ){
			string file_location = "3d-ice/bin/testcase_0";
			vector < vector <double> > temp_T_map(101, vector <double>(101));
			file_location += chip.case_num+48;
			file_location += "/output_";
			file_location += i+48;
			file_location += ".txt";
			cout << file_location << endl;
			
			fin[i].open(file_location.c_str());
			if(fin[i].eof()){
				cout << "error tmap !" << endl;
				return ;
			}
			else{
				for( int k=0;k<temp_T_map.size();k++ ){
					for( int j=0;j<temp_T_map[k].size();j++ ){
						fin[i] >> temp_T_map[k][j];
						if(T_max < temp_T_map[k][j]){
							T_max = temp_T_map[k][j];
							target.first = j;
							target.second = k;
						}
						if(T_min > temp_T_map[k][j]){
							T_min = temp_T_map[k][j];
						}
					}
				}
			}
			fin[i].close();
			T_map.push_back(temp_T_map);
			print_heat_color_picture(&temp_T_map, i);
		}
		if(T_max - T_min >= chip.T_gredient){
			cout << "T_gredient fail !!!" << endl;
			cout << "T_gredient : " << chip.T_gredient << endl;
			cout << "your gragient : " << T_max - T_min << endl;
		}
		if(T_max > chip.T_max+273){
			cout << "T_max fail !!!" << endl;
			cout << "T_max : " << chip.T_max << endl;
			cout << "your T_max : " << T_max << endl;
		}
		cout << "your T_max : " << T_max << endl;
		pout(target);
		cout << endl;
		cout << "sim over !!!!!!!!!!!!!!!!!!" << endl;
		return;
		
		cout << endl;
		cout << T_max << endl;
		if(optimization_move_channel(target, &edge_rtree, &edges, &tempnode)){
			cout << "good" << endl;
		}
		else{
			cout << "bad" << endl;
		}
		getchar();
	}
	
	
}