コード例 #1
0
ファイル: cp_seq.c プロジェクト: YArane/Parallel-RREF
int main(int argc, char * argv[])
{
	struct timeval start, end; //struct used to compute execution time
	/* setup */
	int rows, columns;
	if (argc != 2) printf("please provide a user matrix!");
	gettimeofday(&start, NULL);
	double **A = read_user_matrix_from_file(argv[1], &rows, &columns);
	double *cp = malloc(columns * sizeof(double)); // clicking probabilities

	/* computation */
	RREF(A, rows, columns);
	divide_by_max(A, rows, columns);

	/* results */
	input_clicking_probabilities(A, rows, columns, cp);
	print_best_acceptance_threshold(cp, rows);
	write_clicking_probabilities_to_file(cp, rows);
	free_matrix(A, rows);
	free(cp);
		gettimeofday(&end, NULL);
		printf("\n\nAlgorithm's computational part duration :%ld\n", \
					((end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec)));
	return 0;
}
コード例 #2
0
ファイル: cp_mpi.c プロジェクト: njfaries/fall2015
int main(int argc, char * argv[])
{
	if (argc != 2) {printf("Please provide a matrix");}

	int ierr = MPI_Init(&argc, &argv);
	MPI_Comm_rank(MPI_COMM_WORLD, &rank); //sets rank
	MPI_Comm_size(MPI_COMM_WORLD, &size); //gets number of processes
	current_pivot = 0;

	if (rank == 0) { //master process
		get_number_of_rows(argv[1], &numrows);
		numcols = numrows + 1; //specified by assignment
		int i;
		for (i = 1; i < size; i++) { //sending out information to slaves about what rows they are reading.
			MPI_Isend(&numrows, 1, MPI_INT, i, MASTER_TO_SLAVE_TAG, MPI_COMM_WORLD, &request);
		}
	}
	else {
		MPI_Recv(&numrows, 1, MPI_INT, 0, MASTER_TO_SLAVE_TAG, MPI_COMM_WORLD, &status);
		numcols = numrows + 1;
	}
	if (rank >= numrows) {
		ierr = MPI_Finalize();
		return 0;
	} else if (rank < (numrows % size)) {
		numrows = (numrows / size) + 1;
	} else {
		numrows = (numrows / size);
	}
	matrix = allocate_matrix(numrows, numcols);
	read_rows(argv[1], matrix);
	RREF(matrix);
	absolute(matrix, &numrows, &numcols);
	reduction(matrix, &numrows, &numcols);
	get_best_threshold();
	collect(matrix);
	// print_matrix(matrix, numrows, numcols);
	print_matrix(final_matrix, numcols - 1, numcols);
	if (rank == 0) {
		// output_to_file(final_matrix);
	}
	free_matrix(matrix, &numrows);
	ierr = MPI_Finalize();
}