PLASMA
Parallel Linear Algebra Software for Multicore Architectures
plasma_descriptor.h
1
10#ifndef PLASMA_DESCRIPTOR_H
11#define PLASMA_DESCRIPTOR_H
12
13#include "plasma_types.h"
14#include "plasma_error.h"
15
16#include <stdlib.h>
17#include <assert.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/***************************************************************************/
40typedef struct {
41 // matrix properties
42 plasma_enum_t type;
43 plasma_enum_t uplo;
44 plasma_enum_t precision;
45
46 // pointer and offsets
47 void *matrix;
48 size_t A21;
49 size_t A12;
50 size_t A22;
51
52 // tile parameters
53 int mb;
54 int nb;
55
56 // main matrix parameters
57 int gm;
58 int gn;
59 int gmt;
60 int gnt;
61
62 // submatrix parameters
63 int i;
64 int j;
65 int m;
66 int n;
67 int mt;
68 int nt;
69
70 // submatrix parameters for a band matrix
71 int kl;
72 int ku;
73 int klt;
74 int kut;
77
78/******************************************************************************/
79static inline size_t plasma_element_size(int type)
80{
81 switch (type) {
82 case PlasmaByte: return 1;
83 case PlasmaInteger: return sizeof(int);
84 case PlasmaRealFloat: return sizeof(float);
85 case PlasmaRealDouble: return sizeof(double);
86 case PlasmaComplexFloat: return 2*sizeof(float);
87 case PlasmaComplexDouble: return 2*sizeof(double);
88 default: assert(0);
89 }
90}
91
92/******************************************************************************/
93static inline void *plasma_tile_addr_general(plasma_desc_t A, int m, int n)
94{
95 int mm = m + A.i/A.mb;
96 int nn = n + A.j/A.nb;
97 size_t eltsize = plasma_element_size(A.precision);
98 size_t offset = 0;
99
100 int lm1 = A.gm/A.mb;
101 int ln1 = A.gn/A.nb;
102
103 if (mm < lm1)
104 if (nn < ln1)
105 offset = A.mb*A.nb*(mm + (size_t)lm1 * nn);
106 else
107 offset = A.A12 + ((size_t)A.mb * (A.gn%A.nb) * mm);
108 else
109 if (nn < ln1)
110 offset = A.A21 + ((size_t)A.nb * (A.gm%A.mb) * nn);
111 else
112 offset = A.A22;
113
114 return (void*)((char*)A.matrix + (offset*eltsize));
115}
116
117/******************************************************************************/
118static inline void *plasma_tile_addr_triangle(plasma_desc_t A, int m, int n)
119{
120 int mm = m + A.i/A.mb;
121 int nn = n + A.j/A.nb;
122 size_t eltsize = plasma_element_size(A.precision);
123 size_t offset = 0;
124
125 int lm1 = A.gm/A.mb;
126 int ln1 = A.gn/A.nb;
127
128 if (mm < lm1) {
129 if (nn < ln1) {
130 if (A.type == PlasmaUpper) {
131 offset = A.mb*A.nb*(mm + (nn * (nn + 1))/2);
132 }
133 else {
134 offset = A.mb*A.nb*((mm - nn) + (nn * (2*lm1 - (nn-1)))/2);
135 }
136 }
137 else {
138 offset = A.A12 + ((size_t)A.mb * (A.gn%A.nb) * mm);
139 }
140 }
141 else {
142 if (nn < ln1) {
143 offset = A.A21 + ((size_t)A.nb * (A.gm%A.mb) * nn);
144 }
145 else {
146 offset = A.A22;
147 }
148 }
149
150 return (void*)((char*)A.matrix + (offset*eltsize));
151}
152
153/******************************************************************************/
154static inline void *plasma_tile_addr_general_band(plasma_desc_t A, int m, int n)
155{
156 return plasma_tile_addr_general(A, (A.kut-1)+m-n, n);
157}
158
159/******************************************************************************/
160static inline void *plasma_tile_addr(plasma_desc_t A, int m, int n)
161{
162 if (A.type == PlasmaGeneral) {
163 return plasma_tile_addr_general(A, m, n);
164 }
165 else if (A.type == PlasmaGeneralBand) {
166 return plasma_tile_addr_general_band(A, m, n);
167 }
168 else if (A.type == PlasmaUpper || A.type == PlasmaLower) {
169 return plasma_tile_addr_triangle(A, m, n);
170 }
171 else {
172 plasma_fatal_error("invalid matrix type");
173 return NULL;
174 }
175}
176
177/***************************************************************************/
182static inline int plasma_tile_mmain(plasma_desc_t A, int k)
183{
184 if (A.type == PlasmaGeneralBand) {
185 return A.mb;
186 }
187 else {
188 if (A.i/A.mb+k < A.gm/A.mb)
189 return A.mb;
190 else
191 return A.gm%A.mb;
192 }
193}
194
195/***************************************************************************/
200static inline int plasma_tile_nmain(plasma_desc_t A, int k)
201{
202 if (A.j/A.nb+k < A.gn/A.nb)
203 return A.nb;
204 else
205 return A.gn%A.nb;
206}
207
208/***************************************************************************/
214static inline int plasma_tile_mview(plasma_desc_t A, int k)
215{
216 if (k < A.mt-1)
217 return A.mb;
218 else
219 if ((A.i+A.m)%A.mb == 0)
220 return A.mb;
221 else
222 return (A.i+A.m)%A.mb;
223}
224
225/***************************************************************************/
231static inline int plasma_tile_nview(plasma_desc_t A, int k)
232{
233 if (k < A.nt-1)
234 return A.nb;
235 else
236 if ((A.j+A.n)%A.nb == 0)
237 return A.nb;
238 else
239 return (A.j+A.n)%A.nb;
240}
241
242/******************************************************************************/
243static inline int plasma_tile_mmain_band(plasma_desc_t A, int m, int n)
244{
245 return plasma_tile_mmain(A, (A.kut-1)+m-n);
246}
247
248/******************************************************************************/
249int plasma_desc_general_create(plasma_enum_t dtyp, int mb, int nb,
250 int lm, int ln, int i, int j, int m, int n,
251 plasma_desc_t *A);
252
253int plasma_desc_general_band_create(plasma_enum_t dtyp, plasma_enum_t uplo,
254 int mb, int nb, int lm, int ln,
255 int i, int j, int m, int n, int kl, int ku,
256 plasma_desc_t *A);
257
258int plasma_desc_triangular_create(plasma_enum_t dtyp, plasma_enum_t uplo, int mb, int nb,
259 int lm, int ln, int i, int j, int m, int n,
260 plasma_desc_t *A);
261
262int plasma_desc_destroy(plasma_desc_t *A);
263
264int plasma_desc_general_init(plasma_enum_t precision, void *matrix,
265 int mb, int nb, int lm, int ln, int i, int j,
266 int m, int n, plasma_desc_t *A);
267
268int plasma_desc_general_band_init(plasma_enum_t precision, plasma_enum_t uplo,
269 void *matrix, int mb, int nb, int lm, int ln,
270 int i, int j, int m, int n, int kl, int ku,
271 plasma_desc_t *A);
272
273int plasma_desc_triangular_init(plasma_enum_t precision, plasma_enum_t uplo, void *matrix,
274 int mb, int nb, int lm, int ln, int i, int j,
275 int m, int n, plasma_desc_t *A);
276
277int plasma_desc_check(plasma_desc_t A);
278int plasma_desc_general_check(plasma_desc_t A);
279int plasma_desc_general_band_check(plasma_desc_t A);
280
281plasma_desc_t plasma_desc_view(plasma_desc_t A, int i, int j, int m, int n);
282
283int plasma_descT_create(plasma_desc_t A, int ib, plasma_enum_t householder_mode,
284 plasma_desc_t *T);
285
286#ifdef __cplusplus
287} // extern "C"
288#endif
289
290#endif // PLASMA_DESCRIPTOR_H
Definition: plasma_descriptor.h:40
int j
column index to the beginning of the submatrix
Definition: plasma_descriptor.h:64
int n
number of columns of the submatrix
Definition: plasma_descriptor.h:66
int mt
number of tile rows of the submatrix
Definition: plasma_descriptor.h:67
int klt
number of tile rows below the diagonal tile
Definition: plasma_descriptor.h:73
size_t A12
pointer to the beginning of A12
Definition: plasma_descriptor.h:49
int i
row index to the beginning of the submatrix
Definition: plasma_descriptor.h:63
int nt
number of tile columns of the submatrix
Definition: plasma_descriptor.h:68
int m
number of rows of the submatrix
Definition: plasma_descriptor.h:65
void * matrix
pointer to the beginning of the matrix
Definition: plasma_descriptor.h:47
int mb
number of rows in a tile
Definition: plasma_descriptor.h:53
int gnt
number of tile columns of the entire matrix
Definition: plasma_descriptor.h:60
size_t A21
pointer to the beginning of A21
Definition: plasma_descriptor.h:48
int gmt
number of tile rows of the entire matrix
Definition: plasma_descriptor.h:59
plasma_enum_t uplo
upper, lower, etc.
Definition: plasma_descriptor.h:43
plasma_enum_t precision
precision of the matrix
Definition: plasma_descriptor.h:44
size_t A22
pointer to the beginning of A22
Definition: plasma_descriptor.h:50
plasma_enum_t type
general, general band, etc.
Definition: plasma_descriptor.h:42
int ku
number of rows above the diagonal
Definition: plasma_descriptor.h:72
int kl
number of rows below the diagonal
Definition: plasma_descriptor.h:71
int gm
number of rows of the entire matrix
Definition: plasma_descriptor.h:57
int nb
number of columns in a tile
Definition: plasma_descriptor.h:54
int kut
Definition: plasma_descriptor.h:74
int gn
number of columns of the entire matrix
Definition: plasma_descriptor.h:58