1/* Copyright (C) 2021-2023 Free Software Foundation, Inc.
2   Contributed by Oracle.
3
4   This file is part of GNU Binutils.
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 3, or (at your option)
9   any later version.
10
11   This program is distributed in the hope that it will be useful,
12   but WITHOUT ANY WARRANTY; without even the implied warranty of
13   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   GNU General Public License for more details.
15
16   You should have received a copy of the GNU General Public License
17   along with this program; if not, write to the Free Software
18   Foundation, 51 Franklin Street - Fifth Floor, Boston,
19   MA 02110-1301, USA.  */
20
21#ifndef ALREADY_INCLUDED
22#define ALREADY_INCLUDED
23
24#include <stdlib.h>
25#include <stdio.h>
26#include <stdint.h>
27#include <stdbool.h>
28#include <string.h>
29#include <unistd.h>
30#include <float.h>
31#include <math.h>
32#include <malloc.h>
33#include <pthread.h>
34
35struct thread_arguments_data {
36	int     thread_id;
37	bool    verbose;
38	bool    do_work;
39	int64_t repeat_count;
40	int64_t row_index_start;
41	int64_t row_index_end;
42	int64_t m;
43	int64_t n;
44	double  *b;
45	double  *c;
46	double  **A;
47};
48
49typedef struct thread_arguments_data thread_data;
50
51void *driver_mxv (void *thread_arguments);
52
53void __attribute__ ((noinline)) mxv_core (int64_t row_index_start,
54					  int64_t row_index_end,
55					  int64_t m,
56					  int64_t n,
57					  double **restrict A,
58					  double *restrict b,
59					  double *restrict c);
60
61int get_user_options (int     argc,
62		      char    *argv[],
63		      int64_t *number_of_rows,
64		      int64_t *number_of_columns,
65		      int64_t *repeat_count,
66		      int64_t *number_of_threads,
67		      bool    *verbose);
68
69void init_data (int64_t m,
70		int64_t n,
71		double  **restrict A,
72		double  *restrict b,
73		double  *restrict c,
74		double  *restrict ref);
75
76void  allocate_data (int	 active_threads,
77		     int64_t     number_of_rows,
78		     int64_t     number_of_columns,
79		     double      ***A,
80		     double      **b,
81		     double      **c,
82		     double      **ref,
83		     thread_data **thread_data_arguments,
84		     pthread_t   **pthread_ids);
85
86int64_t check_results (int64_t m,
87		       int64_t n,
88		       double *c,
89		       double *ref);
90
91void get_workload_stats (int64_t number_of_threads,
92			 int64_t number_of_rows,
93			 int64_t number_of_columns,
94			 int64_t *rows_per_thread,
95			 int64_t *remainder_rows,
96			 int64_t *active_threads);
97
98void determine_work_per_thread (int64_t TID,
99				int64_t rows_per_thread,
100				int64_t remainder_rows,
101				int64_t *row_index_start,
102				int64_t *row_index_end);
103
104void mxv (int64_t m,
105	  int64_t n,
106	  double **restrict A,
107	  double *restrict b,
108	  double *restrict c);
109
110void print_all_results (int64_t number_of_rows,
111			int64_t number_of_columns,
112			int64_t number_of_threads,
113			int64_t errors);
114
115extern bool verbose;
116
117#endif
118