PLASMA  2.4.5
PLASMA - Parallel Linear Algebra for Scalable Multi-core Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
descriptor.c
Go to the documentation of this file.
1 
14 #include "common.h"
15 #include "auxiliary.h"
16 #include "descriptor.h"
17 
18 #include <stdlib.h>
19 /***************************************************************************/
22 PLASMA_desc plasma_desc_init(PLASMA_enum dtyp, int mb, int nb, int bsiz,
23  int lm, int ln, int i, int j, int m, int n)
24 {
25  PLASMA_desc desc;
26 
27  // Matrix address
28  desc.mat = NULL;
29  desc.A21 = (lm - lm%mb)*(ln - ln%nb);
30  desc.A12 = ( lm%mb)*(ln - ln%nb) + desc.A21;
31  desc.A22 = (lm - lm%mb)*( ln%nb) + desc.A12;
32  // Matrix properties
33  desc.dtyp = dtyp;
34  desc.mb = mb;
35  desc.nb = nb;
36  desc.bsiz = bsiz;
37  // Large matrix parameters
38  desc.lm = lm;
39  desc.ln = ln;
40  // Large matrix derived parameters
41  desc.lm1 = (lm/mb);
42  desc.ln1 = (ln/nb);
43  desc.lmt = (lm%mb==0) ? (lm/mb) : (lm/mb+1);
44  desc.lnt = (ln%nb==0) ? (ln/nb) : (ln/nb+1);
45  // Submatrix parameters
46  desc.i = i;
47  desc.j = j;
48  desc.m = m;
49  desc.n = n;
50  // Submatrix derived parameters
51  desc.mt = (i+m-1)/mb - i/mb + 1;
52  desc.nt = (j+n-1)/nb - j/nb + 1;
53 
54  return desc;
55 }
56 
57 /***************************************************************************/
60 PLASMA_desc plasma_desc_submatrix(PLASMA_desc descA, int i, int j, int m, int n)
61 {
62  PLASMA_desc descB;
63  int mb, nb;
64 
65  descB = descA;
66  mb = descA.mb;
67  nb = descA.nb;
68  // Submatrix parameters
69  descB.i = i;
70  descB.j = j;
71  descB.m = m;
72  descB.n = n;
73  // Submatrix derived parameters
74  descB.mt = (i+m-1)/mb - i/mb + 1;
75  descB.nt = (j+n-1)/nb - j/nb + 1;
76  return descB;
77 }
78 
79 /***************************************************************************/
83 {
84  if (desc->mat == NULL) {
85  plasma_error("plasma_desc_check", "NULL matrix pointer");
87  }
88  if (desc->dtyp != PlasmaRealFloat &&
89  desc->dtyp != PlasmaRealDouble &&
90  desc->dtyp != PlasmaComplexFloat &&
91  desc->dtyp != PlasmaComplexDouble ) {
92  plasma_error("plasma_desc_check", "invalid matrix type");
94  }
95  if (desc->mb <= 0 || desc->nb <= 0) {
96  plasma_error("plasma_desc_check", "negative tile dimension");
98  }
99  if (desc->bsiz < desc->mb*desc->nb) {
100  plasma_error("plasma_desc_check", "tile memory size smaller than the product of dimensions");
102  }
103  if (desc->lm <= 0 || desc->ln <= 0) {
104  plasma_error("plasma_desc_check", "negative matrix dimension");
106  }
107  if (desc->i >= desc->lm || desc->j >= desc->ln) {
108  plasma_error("plasma_desc_check", "beginning of the matrix out of scope");
110  }
111  if (desc->i+desc->m > desc->lm || desc->j+desc->n > desc->ln) {
112  plasma_error("plasma_desc_check", "submatrix out of scope");
114  }
115  return PLASMA_SUCCESS;
116 }
117 
118 /***************************************************************************/
122 {
123  size_t size;
124 
125  size = (size_t)desc->lm * (size_t)desc->ln * (size_t)plasma_element_size(desc->dtyp);
126  if ((desc->mat = malloc(size)) == NULL) {
127  plasma_error("plasma_desc_mat_alloc", "malloc() failed");
129  }
130 
131  memset(desc->mat, 0, size );
132  return PLASMA_SUCCESS;
133 }
134 
135 /***************************************************************************/
139 {
140  if (desc->mat != NULL) {
141  free(desc->mat);
142  desc->mat = NULL;
143  }
144  return PLASMA_SUCCESS;
145 }
146 
147 /***************************************************************************/
201 int PLASMA_Desc_Create(PLASMA_desc **desc, void *mat, PLASMA_enum dtyp, int mb, int nb, int bsiz,
202  int lm, int ln, int i, int j, int m, int n)
203 {
205  int status;
206 
207  plasma = plasma_context_self();
208  if (plasma == NULL) {
209  plasma_error("PLASMA_Desc_Create", "PLASMA not initialized");
211  }
212  /* Allocate memory and initialize the descriptor */
213  *desc = (PLASMA_desc*)malloc(sizeof(PLASMA_desc));
214  if (*desc == NULL) {
215  plasma_error("PLASMA_Desc_Create", "malloc() failed");
217  }
218  **desc = plasma_desc_init(dtyp, mb, nb, bsiz, lm, ln, i, j, m, n);
219  (**desc).mat = mat;
220  status = plasma_desc_check(*desc);
221  if (status != PLASMA_SUCCESS) {
222  plasma_error("PLASMA_Desc_Create", "invalid descriptor");
223  return status;
224  }
225  return PLASMA_SUCCESS;
226 }
227 
228 /***************************************************************************/
246 {
248 
249  plasma = plasma_context_self();
250  if (plasma == NULL) {
251  plasma_error("PLASMA_Desc_Destroy", "PLASMA not initialized");
253  }
254  if (*desc == NULL) {
255  plasma_error("PLASMA_Desc_Destroy", "attempting to destroy a NULL descriptor");
256  return PLASMA_ERR_UNALLOCATED;
257  }
258  free(*desc);
259  *desc = NULL;
260  return PLASMA_SUCCESS;
261 }