Esempio n. 1
0
int main(int argc, char** argv)
{
	if(argc > 3)
	{
		image_height=atoi(argv[1]);
		image_width=atoi(argv[1]);
		if(atoi(argv[2]) == 1)
			create_image();

		image = (char*)malloc(sizeof(char)*image_height*image_width);
		meet=(ConsensusGrid*)malloc(sizeof(ConsensusGrid)*image_height*image_width);
		basis = (int*)malloc(sizeof(int)*image_height*image_width);

		read_raw_image("image.raw",image,image_height,image_width);
		for(int i=0; i<image_height; i++)
		{
			for(int j = 0; j<image_width; j++)
			{
				if(atoi(argv[3]) == 1)
					meet[i*image_width+j]=consensus_parallel(i, j, image,image_height,image_width);
				else
					meet[i*image_width+j]=consensus(i, j, image,image_height,image_width);
			}
		}

		printf("Calculating list\n");
		if(atoi(argv[3]) == 1)
			calculate_list_parallel();
		else
			calculate_list();

		printf("Calculating basis\n");
		if(atoi(argv[3]) == 1)
			calculate_basis_parallel();
		else
			calculate_basis();

		cout << "Basis count = " << basis_count << endl;
	}

	else
	{
		cout << "Insufficient arguments\n" << endl;
		cout << "First argument = Image Size" << endl;
		cout << "Second argument = 1 to create image, 0 not to create image" << endl;
		cout << "Third argument = 1 for parallel, 0 for not parallel\n" << endl;
	}
}
int main(int argc, char** argv)
{
	if(argc > 3)
	{
		double t1, t2, t3;
		struct timeval t_s1, t_e1, t_s2, t_e2, t_s3, t_e3;

		image_height=atoi(argv[1]);
		image_width=atoi(argv[1]);
		if(atoi(argv[2]) == 1)
			create_image();

		image = (char*)malloc(sizeof(char)*image_height*image_width);
		meet=(ConsensusGrid*)malloc(sizeof(ConsensusGrid)*image_height*image_width);
		basis = (int*)malloc(sizeof(int)*image_height*image_width);

		read_raw_image("image.raw",image,image_height,image_width);

		cout << "Calculating consensus..." << endl << endl;
		for(int i=0; i<image_height; i++)
		{
			for(int j = 0; j<image_width; j++)
			{
				if(atoi(argv[3]) == 1)
				{
				        gettimeofday(&t_s1, NULL);

					meet[i*image_width+j]=consensus_parallel(i, j, image,image_height,image_width);

					gettimeofday(&t_e1, NULL);
        				t1 = (((double)t_e1.tv_sec-(double)t_s1.tv_sec)*1000) + ((double)t_e1.tv_usec - (double)t_s1.tv_usec)/1000;
				}
				else
				{
                                        gettimeofday(&t_s1, NULL);
					meet[i*image_width+j]=consensus(i, j, image,image_height,image_width);
                                        gettimeofday(&t_e1, NULL);
                                        t1 = (((double)t_e1.tv_sec-(double)t_s1.tv_sec)*1000) + ((double)t_e1.tv_usec - (double)t_s1.tv_usec)/1000;
				}
			}
		}

		cout << "Calculating list..." << endl << endl;
		if(atoi(argv[3]) == 1)
		{
        		gettimeofday(&t_s2, NULL);
			calculate_list_parallel();
			gettimeofday(&t_e2, NULL);
		        t2 = (((double)t_e2.tv_sec-(double)t_s2.tv_sec)*1000) + ((double)t_e2.tv_usec - (double)t_s2.tv_usec)/1000;

		}
		else
		{
                        gettimeofday(&t_s2, NULL);
			calculate_list();
                        gettimeofday(&t_e2, NULL);
                        t2 = (((double)t_e2.tv_sec-(double)t_s2.tv_sec)*1000) + ((double)t_e2.tv_usec - (double)t_s2.tv_usec)/1000;

		}
		cout << "Calculating basis..." << endl << endl;
		if(atoi(argv[3]) == 1)
		{
       		 	gettimeofday(&t_s3, NULL);
			calculate_basis();

			gettimeofday(&t_e3, NULL);
        		t3 = (((double)t_e3.tv_sec-(double)t_s3.tv_sec)*1000) + ((double)t_e3.tv_usec - (double)t_s3.tv_usec)/1000;
		}
		else
		{
                        gettimeofday(&t_s3, NULL);
			calculate_basis();
                        gettimeofday(&t_e3, NULL);
                        t3 = (((double)t_e3.tv_sec-(double)t_s3.tv_sec)*1000) + ((double)t_e3.tv_usec - (double)t_s3.tv_usec)/1000;

		}
		cout << "Basis count = " << basis_count << endl;

		cout << endl << "Time for Parallel Consensus Calculation = " << t1 << " msec" << endl;
		cout << "Time for Parallel List Calculation = " << t2 << " msec" << endl;
		cout << "Time for Basis  Calculation = " << t3 << " msec" << endl;
	}

	else
	{
		cout << "Insufficient arguments\n" << endl;
		cout << "First argument = Image Size" << endl;
		cout << "Second argument = 1 to create image, 0 not to create image" << endl;
		cout << "Third argument = 1 for parallel, 0 for not parallel\n" << endl;
	}
}
int main(int argc, char** argv)
{
	if(argc > 1)
	{
		int* basis_serial;
		int* basis_parallel;
		int basis_count1, basis_count2;

		image_height=atoi(argv[1]);
		image_width=atoi(argv[1]);
		

		create_image();

		image = (char*)malloc(sizeof(char)*image_height*image_width);
		meet=(ConsensusGrid*)malloc(sizeof(ConsensusGrid)*image_height*image_width);
		basis = (int*)malloc(sizeof(int)*image_height*image_width);

		read_raw_image("image.raw",image,image_height,image_width);

		struct timeval t_s, t_e;
        	gettimeofday(&t_s, NULL);
		/// For serial implementation
		for(int i=0; i<image_height; i++)
		{
			for(int j = 0; j<image_width; j++)
			{
				meet[i*image_width+j]=consensus(i, j, image,image_height,image_width);
			}
		}

		printf("Calculating list for serial\n");
		calculate_list();

		printf("Calculating basis for serial\n");
		calculate_basis();
		gettimeofday(&t_e, NULL);

        	double t1 = (((double)t_e.tv_sec-(double)t_s.tv_sec)*1000) + ((double)t_e.tv_usec - (double)t_s.tv_usec)/1000;

		basis_serial = basis;

		basis_count1 = basis_count;
		cout << "Serial Basis count = " << basis_count << endl << endl;;

		reset_values();
		
		/// For parallel implementation
		struct timeval t_s2, t_e2;
	        gettimeofday(&t_s2, NULL);

                for(int i=0; i<image_height; i++)
                {
                        for(int j = 0; j<image_width; j++)
                        {
                                meet[i*image_width+j]=consensus_parallel(i, j, image,image_height,image_width);
                        }
                }

                printf("Calculating list for parallel\n");
                calculate_list();

                printf("Calculating basis for parallel\n");
		calculate_basis();
		gettimeofday(&t_e2, NULL);
       		double t2 = (((double)t_e2.tv_sec-(double)t_s2.tv_sec)*1000) + ((double)t_e2.tv_usec - (double)t_s2.tv_usec)/1000;

                basis_parallel = basis;

		basis_count2 = basis_count;
                cout << "Parallel Basis count = " << basis_count << endl << endl;

		Assert_Output(basis_serial, basis_parallel, basis_count1, basis_count2);

	}

	else
	{
		cout << "Insufficient arguments\n" << endl;
		cout << "First argument = Image Size" << endl;
	}
}