/*------------------------------------------------------------------*/ int main(int argc, char* argv[]) { long thread; pthread_t* thread_handles; double start, finish; if (argc != 4) Usage(argv[0]); thread_count = strtol(argv[1], NULL, 10); m = strtol(argv[2], NULL, 10); n = strtol(argv[3], NULL, 10); # ifdef DEBUG printf("thread_count = %d, m = %d, n = %d\n", thread_count, m, n); # endif thread_handles = malloc(thread_count*sizeof(pthread_t)); sem_init(&sem, 0, 1); /* Initial value is 1 */ A = malloc(m*n*sizeof(double)); x = malloc(n*sizeof(double)); y = malloc(m*sizeof(double)); srandom(1); Gen_matrix(A, m, n); # ifdef DEBUG Print_matrix("We generated", A, m, n); # endif Gen_vector(x, n); # ifdef DEBUG Print_vector("We generated", x, n); # endif GET_TIME(start); for (thread = 0; thread < thread_count; thread++) pthread_create(&thread_handles[thread], NULL, Pth_mat_vect, (void*) thread); for (thread = 0; thread < thread_count; thread++) pthread_join(thread_handles[thread], NULL); GET_TIME(finish); # ifdef DEBUG Print_vector("The product is", y, m); # endif printf("Elapsed time = %e seconds\n", finish - start); free(A); free(x); free(y); sem_destroy(&sem); free(thread_handles); return 0; } /* main */
/*------------------------------------------------------------------*/ int main(int argc, char* argv[]) { int thread_count; int m, n; double* A; double* x; double* y; Get_args(argc, argv, &thread_count, &m, &n); A = malloc(m*n*sizeof(double)); x = malloc(n*sizeof(double)); y = malloc(m*sizeof(double)); # ifdef DEBUG Read_matrix("Enter the matrix", A, m, n); Print_matrix("We read", A, m, n); Read_vector("Enter the vector", x, n); Print_vector("We read", x, n); # else Gen_matrix(A, m, n); /* Print_matrix("We generated", A, m, n); */ Gen_vector(x, n); /* Print_vector("We generated", x, n); */ # endif Omp_mat_vect(A, x, y, m, n, thread_count); # ifdef DEBUG Print_vector("The product is", y, m); # else /* Print_vector("The product is", y, m); */ # endif free(A); free(x); free(y); return 0; } /* main */