SCIP-SDP  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
lapack_dsdp.c
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2 /* */
3 /* This file is part of SCIPSDP - a solving framework for mixed-integer */
4 /* semidefinite programms based on SCIP. */
5 /* */
6 /* Copyright (C) 2011-2013 Discrete Optimization, TU Darmstadt */
7 /* EDOM, FAU Erlangen-Nürnberg */
8 /* 2014-2015 Discrete Optimization, TU Darmstadt */
9 /* */
10 /* */
11 /* This program is free software; you can redistribute it and/or */
12 /* modify it under the terms of the GNU Lesser General Public License */
13 /* as published by the Free Software Foundation; either version 3 */
14 /* of the License, or (at your option) any later version. */
15 /* */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU Lesser General Public License for more details. */
20 /* */
21 /* You should have received a copy of the GNU Lesser General Public License */
22 /* along with this program; if not, write to the Free Software */
23 /* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.*/
24 /* */
25 /* */
26 /* Based on SCIP - Solving Constraint Integer Programs */
27 /* Copyright (C) 2002-2015 Zuse Institute Berlin */
28 /* SCIP is distributed under the terms of the SCIP Academic Licence, */
29 /* see file COPYING in the SCIP distribution. */
30 /* */
31 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
32 
33 /* #define SCIP_DEBUG*/
34 /* #define SCIP_MORE_DEBUG*/
35 
43 #include <assert.h>
44 
45 #include "lapack.h"
46 #include "config.h" /* for F77_FUNC */
47 
48 #include "scip/def.h"
49 #include "blockmemshell/memory.h"
50 #include "scip/type_retcode.h"
51 
52 
54 #define BMS_CALL(x) do \
55  { \
56  if( NULL == (x) ) \
57  { \
58  SCIPerrorMessage("No memory in function call\n"); \
59  return SCIP_NOMEMORY; \
60  } \
61  } \
62  while( FALSE )
63 
65 #define DOUBLETOINT(x) ((int) (x + 0.5))
66 
67 /*
68  * BLAS/LAPACK Calls
69  */
70 
75 void F77_FUNC(dsyevr, DSYEVR)(
76  char* JOBZ, char* RANGE, char* UPLO,
77  int* N, double* A, int* LDA,
78  double* VL, double* VU,
79  int* IL, int* IU,
80  double* ABSTOL, int* M, double* W, double* Z,
81  int* LDZ, int* ISUPPZ, double* WORK,
82  int* LWORK, int* IWORK, int* LIWORK,
83  int* INFO );
84 
85 
87 void F77_FUNC(dgemv, DGEMV)(char* TRANS, int* M, int* N, double* ALPHA, double* A, int* LDA, double* X, int* INCX, double* BETA, double* Y, int* INCY);
88 
89 
93 /*
94  * Functions
95  */
96 
101 SCIP_RETCODE SCIPlapackComputeIthEigenvalue(
102  BMS_BLKMEM* blkmem,
103  SCIP_Bool geteigenvectors,
104  int n,
105  SCIP_Real* A,
106  int i,
107  SCIP_Real* eigenvalue,
108  SCIP_Real* eigenvector
109  )
110 {
111  int N;
112  int INFO;
113  char JOBZ;
114  char RANGE;
115  char UPLO;
116  int LDA;
117  double* WORK;
118  int LWORK;
119  int* IWORK;
120  int LIWORK;
121  double* WTMP;
122  double ABSTOL;
123  int IL;
124  int IU;
125  int M;
126  int LDZ;
127  double WSIZE;
128  int WISIZE;
129  double VL;
130  double VU;
131  int* ISUPPZ;
132 
133 
134  assert( blkmem != NULL );
135  assert( n > 0 );
136  assert( A != NULL );
137  assert( 0 < i && i <= n );
138  assert( eigenvalue != NULL );
139  assert( ( ! geteigenvectors) || eigenvector != NULL );
140 
141  N = n;
142  JOBZ = geteigenvectors ? 'V' : 'N';
143  RANGE = 'I';
144  UPLO = 'L';
145  LDA = n;
146  ABSTOL = 0.0;
147  IL = i;
148  IU = i;
149  M = 1;
150  LDZ = n;
151 
152  /* standard LAPACK workspace query, to get the amount of needed memory */
153  LWORK = -1;
154  LIWORK = -1;
155 
156  /* this computes the internally needed memory and returns this as (the first entries of [the 1x1 arrays]) WSIZE and WISIZE */
157  F77_FUNC(dsyevr, DSYEVR)( &JOBZ, &RANGE, &UPLO,
158  &N, NULL, &LDA,
159  NULL, NULL,
160  &IL, &IU,
161  &ABSTOL, &M, NULL, NULL,
162  &LDZ, NULL, &WSIZE,
163  &LWORK, &WISIZE, &LIWORK,
164  &INFO );
165 
166  if ( INFO != 0 )
167  {
168  SCIPerrorMessage("There was an error when calling DSYEVR. INFO = %d\n", INFO);
169  return SCIP_ERROR;
170  }
171 
172  /* allocate workspace */
173  LWORK = DOUBLETOINT(WSIZE);
174  LIWORK = WISIZE;
175 
176  BMS_CALL( BMSallocBlockMemoryArray(blkmem, &WORK, LWORK) );
177  BMS_CALL( BMSallocBlockMemoryArray(blkmem, &IWORK, LIWORK) );
178  BMS_CALL( BMSallocBlockMemoryArray(blkmem, &WTMP, N) );
179  BMS_CALL( BMSallocBlockMemoryArray(blkmem, &ISUPPZ, 2) );
180 
181  /* call the function */
182  VL = -1e20;
183  VU = 1e20;
184 
185  F77_FUNC(dsyevr, DSYEVR)( &JOBZ, &RANGE, &UPLO,
186  &N, A, &LDA,
187  &VL, &VU,
188  &IL, &IU,
189  &ABSTOL, &M, WTMP, eigenvector,
190  &LDZ, ISUPPZ, WORK,
191  &LWORK, IWORK, &LIWORK,
192  &INFO );
193 
194  if ( INFO != 0 )
195  {
196  SCIPerrorMessage("There was an error when calling DSYEVR. INFO = %d\n", INFO);
197  return SCIP_ERROR;
198  }
199 
200  /* handle output */
201  *eigenvalue = WTMP[0];
202 
203  /* free memory */
204  BMSfreeBlockMemoryArray(blkmem, &ISUPPZ, 2);
205  BMSfreeBlockMemoryArray(blkmem, &WTMP, N);
206  BMSfreeBlockMemoryArray(blkmem, &IWORK, LIWORK);
207  BMSfreeBlockMemoryArray(blkmem, &WORK, LWORK);
208 
209  return SCIP_OKAY;
210 }
211 
214  int nrows,
215  int ncols,
216  SCIP_Real* matrix,
217  SCIP_Real* vector,
218  SCIP_Real* result
219  )
220 {
221  char TRANS;
222  int M;
223  int N;
224  double ALPHA;
225  double* A;
226  int LDA;
227  double* X;
228  int INCX;
229  double BETA;
230  double* Y;
231  int INCY;
232 
233  TRANS = 'N';
234  M = nrows;
235  N = ncols;
236  ALPHA = 1.0;
237  A = matrix;
238  LDA = nrows;
239  X = vector;
240  INCX = 1;
241  BETA = 0.0;
242  Y = result;
243  INCY = 1;
244 
245  F77_FUNC(dgemv, DGEMV)(&TRANS, &M, &N, &ALPHA, A, &LDA, X, &INCX, &BETA, Y, &INCY);
246 
247  return SCIP_OKAY;
248 }
249 
Macros for calling Fortran-functions.
SCIP_RETCODE SCIPlapackMatrixVectorMult(int nrows, int ncols, SCIP_Real *matrix, SCIP_Real *vector, SCIP_Real *result)
Definition: lapack_dsdp.c:213
#define DOUBLETOINT(x)
Definition: lapack_dsdp.c:65
#define BMS_CALL(x)
Definition: lapack_dsdp.c:54
#define F77_FUNC(name, NAME)
Definition: config.h:42
interface methods for eigenvector computation and matrix multiplication using different versions of L...
EXTERN SCIP_RETCODE SCIPlapackComputeIthEigenvalue(BMS_BLKMEM *blkmem, SCIP_Bool geteigenvectors, int n, SCIP_Real *A, int i, SCIP_Real *eigenvalue, SCIP_Real *eigenvector)