1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/* Copyright (C) 2021-2025 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. */
#include "mydefs.h"
/*
* -----------------------------------------------------------------------------
* This function allocates the data and sets up the data structures to be used
* in the remainder.
* -----------------------------------------------------------------------------
*/
void allocate_data (int active_threads,
int64_t number_of_rows,
int64_t number_of_columns,
double ***A,
double **b,
double **c,
double **ref,
thread_data **thread_data_arguments,
pthread_t **pthread_ids)
{
if ((*b = (double *) malloc (number_of_columns * sizeof (double))) == NULL)
{
printf ("Error: allocation of vector b failed\n");
perror ("vector b");
exit (-1);
}
else
{
if (verbose) printf ("Vector b allocated\n");
}
if ((*c = (double *) malloc (number_of_rows * sizeof (double))) == NULL)
{
printf ("Error: allocation of vector c failed\n");
perror ("vector c");
exit (-1);
}
else
{
if (verbose) printf ("Vector c allocated\n");
}
if ((*ref = (double *) malloc (number_of_rows * sizeof (double))) == NULL)
{
printf ("Error: allocation of vector ref failed\n");
perror ("vector ref");
exit (-1);
}
else
{
if (verbose) printf ("Vector ref allocated\n");
}
if ((*A = (double **) malloc (number_of_rows * sizeof (double))) == NULL)
{
printf ("Error: allocation of matrix A failed\n");
perror ("matrix A");
exit (-1);
}
else
{
for (int64_t i=0; i<number_of_rows; i++)
{
if (((*A)[i] = (double *) malloc (number_of_columns
* sizeof (double))) == NULL)
{
printf ("Error: allocation of matrix A columns failed\n");
perror ("matrix A[i]");
exit (-1);
}
}
if (verbose) printf ("Matrix A allocated\n");
}
if ((*thread_data_arguments = (thread_data *) malloc ((active_threads)
* sizeof (thread_data))) == NULL)
{
perror ("malloc thread_data_arguments");
exit (-1);
}
else
{
if (verbose) printf ("Structure thread_data_arguments allocated\n");
}
if ((*pthread_ids = (pthread_t *) malloc ((active_threads)
* sizeof (pthread_t))) == NULL)
{
perror ("malloc pthread_ids");
exit (-1);
}
else
{
if (verbose) printf ("Structure pthread_ids allocated\n");
}
}
/*
* -----------------------------------------------------------------------------
* This function initializes the data.
* -----------------------------------------------------------------------------
*/
void init_data (int64_t m,
int64_t n,
double **restrict A,
double *restrict b,
double *restrict c,
double *restrict ref)
{
(void) srand48 (2020L);
for (int64_t j=0; j<n; j++)
b[j] = 1.0;
for (int64_t i=0; i<m; i++)
{
ref[i] = n*i;
c[i] = -2022;
for (int64_t j=0; j<n; j++)
A[i][j] = drand48 ();
}
for (int64_t i=0; i<m; i++)
{
double row_sum = 0.0;
for (int64_t j=0; j<n; j++)
row_sum += A[i][j];
ref[i] = row_sum;
}
}
|