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
workspace.c
Go to the documentation of this file.
1 
14 #include "common.h"
15 #include "allocate.h"
16 #include "auxiliary.h"
17 #include "workspace.h"
18 
19 #include <stdlib.h>
20 
21 /***************************************************************************/
24 int plasma_alloc_ibnb(int M, int N, PLASMA_enum func, int type, void **memptr)
25 {
26  size_t size;
27  int status;
28  int IB, NB, MT, NT;
30 
31  plasma = plasma_context_self();
32  if (plasma == NULL) {
33  plasma_fatal_error("plasma_alloc_ibnb", "PLASMA not initialized");
35  }
36  /* Tune NB & IB depending on M & N; Set IBNBSIZE */
37  status = plasma_tune(func, M, N, 0);
38  if (status != PLASMA_SUCCESS) {
39  plasma_error("plasma_alloc_ibnb", "plasma_tune() failed");
40  return PLASMA_ERR_UNEXPECTED;
41  }
42  /* Set MT & NT & allocate */
43  NB = PLASMA_NB;
44  IB = PLASMA_IB;
45  MT = (M%NB==0) ? (M/NB) : (M/NB+1);
46  NT = (N%NB==0) ? (N/NB) : (N/NB+1);
47 
48  /* Size is doubled for RH QR to store the reduction T */
49  if ((plasma->householder != PLASMA_FLAT_HOUSEHOLDER) &&
50  (func == PLASMA_FUNC_SGELS ||
51  func == PLASMA_FUNC_DGELS ||
52  func == PLASMA_FUNC_CGELS ||
53  func == PLASMA_FUNC_ZGELS ||
54  func == PLASMA_FUNC_SGESVD ||
55  func == PLASMA_FUNC_DGESVD ||
56  func == PLASMA_FUNC_CGESVD ||
57  func == PLASMA_FUNC_ZGESVD ))
58  NT *= 2;
59 
60  size = (size_t)MT*NT*IB*NB * plasma_element_size(type);
61  if (size <= 0) {
62  *memptr = NULL;
63  return PLASMA_SUCCESS;
64  }
65 // status = posix_memalign(memptr, STANDARD_PAGE_SIZE, size);
66  *memptr = malloc(size);
67 // if (status != 0) {
68  if (*memptr == NULL) {
69  plasma_error("plasma_alloc_ibnb_tile", "malloc() failed");
71  }
72  return PLASMA_SUCCESS;
73 }
74 
75 /***************************************************************************/
78 int plasma_alloc_ibnb_tile(int M, int N, PLASMA_enum func, int type, PLASMA_desc **desc)
79 {
80  int status;
81  int IB, NB, MT, NT;
83 
84  plasma = plasma_context_self();
85  if (plasma == NULL) {
86  plasma_fatal_error("plasma_alloc_ibnb_tile", "PLASMA not initialized");
88  }
89  /* Tune NB & IB depending on M & N; Set IBNBSIZE */
90  status = plasma_tune(func, M, N, 0);
91  if (status != PLASMA_SUCCESS) {
92  plasma_error("plasma_alloc_ibnb_tile", "plasma_tune() failed");
93  return PLASMA_ERR_UNEXPECTED;
94  }
95 
96  /* Set MT & NT & allocate */
97  NB = PLASMA_NB;
98  IB = PLASMA_IB;
99  MT = (M%NB==0) ? (M/NB) : (M/NB+1);
100  NT = (N%NB==0) ? (N/NB) : (N/NB+1);
101 
102  /* Size is doubled for RH QR to store the reduction T */
103  if ((plasma->householder != PLASMA_FLAT_HOUSEHOLDER) &&
104  ((func == PLASMA_FUNC_SGELS) ||
105  (func == PLASMA_FUNC_DGELS) ||
106  (func == PLASMA_FUNC_CGELS) ||
107  (func == PLASMA_FUNC_ZGELS) ||
108  (func == PLASMA_FUNC_SGESVD) ||
109  (func == PLASMA_FUNC_DGESVD) ||
110  (func == PLASMA_FUNC_CGESVD) ||
111  (func == PLASMA_FUNC_ZGESVD)))
112  NT *= 2;
113 
114  /* Allocate and initialize descriptor */
115  *desc = (PLASMA_desc*)malloc(sizeof(PLASMA_desc));
116  if (*desc == NULL) {
117  plasma_error("plasma_alloc_ibnb_tile", "malloc() failed");
119  }
120  **desc = plasma_desc_init(type, IB, NB, IB*NB, MT*IB, NT*NB, 0, 0, MT*IB, NT*NB);
121 
122  /* Allocate matrix */
123  if (plasma_desc_mat_alloc(*desc)) {
124  plasma_error("plasma_alloc_ibnb_tile", "malloc() failed");
126  }
127 
128  /* Check that everything is ok */
129  status = plasma_desc_check(*desc);
130  if (status != PLASMA_SUCCESS) {
131  plasma_error("plasma_alloc_ibnb_tile", "invalid descriptor");
132  return status;
133  }
134  return PLASMA_SUCCESS;
135 }
136 
137 /***************************************************************************/
140 int plasma_alloc_ipiv(int M, int N, PLASMA_enum func, void **memptr)
141 {
142  size_t size;
143  int status;
144  int NB, MT, NT;
146 
147  plasma = plasma_context_self();
148  if (plasma == NULL) {
149  plasma_fatal_error("plasma_alloc_ipiv", "PLASMA not initialized");
151  }
152  /* Tune NB & IB depending on M & N; Set IBNBSIZE */
153  status = plasma_tune(func, M, N, 0);
154  if (status != PLASMA_SUCCESS) {
155  plasma_error("plasma_alloc_ipiv", "plasma_tune() failed");
156  return PLASMA_ERR_UNEXPECTED;
157  }
158  /* Set MT & NT & allocate */
159  NB = PLASMA_NB;
160  NT = (N%NB==0) ? (N/NB) : ((N/NB)+1);
161  MT = (M%NB==0) ? (M/NB) : ((M/NB)+1);
162  size = (size_t)MT*NT * NB * sizeof(int);
163  if (size <= 0) {
164  *memptr = NULL;
165  return PLASMA_SUCCESS;
166  }
167 // status = posix_memalign(memptr, CACHE_LINE_SIZE, size);
168  *memptr = malloc(size);
169 // if (status != 0) {
170  if (*memptr == NULL) {
171  plasma_error("plasma_alloc_ipiv", "malloc() failed");
173  }
174  return PLASMA_SUCCESS;
175 }
176 
177 /***************************************************************************/
194 int PLASMA_Dealloc_Handle(void **handle)
195 {
197 
198  plasma = plasma_context_self();
199  if (plasma == NULL) {
200  plasma_fatal_error("PLASMA_Dealloc_Handle", "PLASMA not initialized");
202  }
203  if (*handle == NULL) {
204  plasma_error("PLASMA_Dealloc_Handle", "attempting to deallocate a NULL handle");
205  return PLASMA_ERR_UNALLOCATED;
206  }
207  free(*handle);
208  *handle = NULL;
209  return PLASMA_SUCCESS;
210 }
211 
212 /***************************************************************************/
230 {
232 
233  plasma = plasma_context_self();
234  if (plasma == NULL) {
235  plasma_fatal_error("PLASMA_Dealloc_Handle_Tile", "PLASMA not initialized");
237  }
238  if (*desc == NULL) {
239  plasma_error("PLASMA_Dealloc_Handle_Tile", "attempting to deallocate a NULL descriptor");
240  return PLASMA_ERR_UNALLOCATED;
241  }
242  if ((*desc)->mat == NULL) {
243  plasma_error("PLASMA_Dealloc_Handle_Tile", "attempting to deallocate a NULL pointer");
244  return PLASMA_ERR_UNALLOCATED;
245  }
246  free((*desc)->mat);
247  free(*desc);
248  *desc = NULL;
249  return PLASMA_SUCCESS;
250 }