/* Copyright (C) 2021-2023 Free Software Foundation, Inc. Contributed by Oracle. This file is part of GNU Binutils. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ /* * ----------------------------------------------------------------------------- * This program implements the multiplication of an m by n matrix with a vector * of length n. The Posix Threads parallel programming model is used to * parallelize the core matrix-vector multiplication algorithm. * ----------------------------------------------------------------------------- */ #include "mydefs.h" int main (int argc, char **argv) { bool verbose = false; thread_data *thread_data_arguments; pthread_t *pthread_ids; int64_t remainder_rows; int64_t rows_per_thread; int64_t active_threads; int64_t number_of_rows; int64_t number_of_columns; int64_t number_of_threads; int64_t repeat_count; double **A; double *b; double *c; double *ref; int64_t errors; /* * ----------------------------------------------------------------------------- * Start the ball rolling - Get the user options and parse them. * ----------------------------------------------------------------------------- */ (void) get_user_options ( argc, argv, &number_of_rows, &number_of_columns, &repeat_count, &number_of_threads, &verbose); if (verbose) printf ("Verbose mode enabled\n"); /* * ----------------------------------------------------------------------------- * Allocate storage for all data structures. * ----------------------------------------------------------------------------- */ (void) allocate_data ( number_of_threads, number_of_rows, number_of_columns, &A, &b, &c, &ref, &thread_data_arguments, &pthread_ids); if (verbose) printf ("Allocated data structures\n"); /* * ----------------------------------------------------------------------------- * Initialize the data. * ----------------------------------------------------------------------------- */ (void) init_data (number_of_rows, number_of_columns, A, b, c, ref); if (verbose) printf ("Initialized matrix and vectors\n"); /* * ----------------------------------------------------------------------------- * Determine the main workload settings. * ----------------------------------------------------------------------------- */ (void) get_workload_stats ( number_of_threads, number_of_rows, number_of_columns, &rows_per_thread, &remainder_rows, &active_threads); if (verbose) printf ("Defined workload distribution\n"); for (int64_t TID=active_threads; TID threads, with the number of threads specified on the commandline, * or the default if the -t option was not used. * * Per the pthread_create () call, the threads start executing right away. * ----------------------------------------------------------------------------- */ for (int TID=0; TID] " \ "[-n ] " \ "[-t SMALL) { relerr = fabs ((c[i]-ref[i])/ref[i]); } else { relerr = fabs ((c[i]-ref[i])); } if (relerr <= TOL) { marker[i] = ' '; } else { errors++; marker[i] = '*'; } } if (errors > 0) { printf ("Found %ld differences in results for m = %ld n = %ld:\n", errors,m,n); for (int64_t i=0; i