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
|
/* lapack.c: LAPACK interface
Copyright 2008 Bjoern Butscher, Hendrik Weimer
This file is part of libquantum
libquantum 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 of the License,
or (at your option) any later version.
libquantum 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 libquantum; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
MA 02110-1301, USA
*/
#include <stdlib.h>
#include "lapack.h"
#include "matrix.h"
#include "complex.h"
#include "qureg.h"
#include "error.h"
#include "config.h"
extern void cheev_(char *jobz, char *uplo, int *n, float _Complex *A, int *lda,
float *w, float _Complex *work, int *lwork, float *rwork,
int *info);
void
quantum_diag_time(float t, quantum_reg *reg0, quantum_reg *regt,
quantum_reg *tmp1, quantum_reg *tmp2, quantum_matrix H,
float **w)
{
#ifdef HAVE_LIBLAPACK
char jobz = 'V';
char uplo = 'U';
int dim = H.cols;
COMPLEX_FLOAT *work;
int lwork = -1;
float rwork[3*dim-2];
int info;
int i;
void *p;
if(tmp2->size != reg0->size)
{
/* perform diagonalization */
p = regt->node;
*regt = *reg0;
regt->node = realloc(p, regt->size*sizeof(quantum_reg_node));
for(i=0; i<reg0->size; i++)
regt->node[i].state = i;
p = tmp1->node;
*tmp1 = *reg0;
tmp1->node = realloc(p, regt->size*sizeof(quantum_reg_node));
for(i=0; i<reg0->size; i++)
tmp1->node[i].state = i;
p = tmp2->node;
*tmp2 = *reg0;
tmp2->node = realloc(p, regt->size*sizeof(quantum_reg_node));
for(i=0; i<reg0->size; i++)
tmp2->node[i].state = i;
*w = malloc(dim*sizeof(float));
if(!*w)
quantum_error(QUANTUM_ENOMEM);
work = malloc(sizeof(COMPLEX_FLOAT));
if(!work)
quantum_error(QUANTUM_ENOMEM);
cheev_(&jobz, &uplo, &dim, H.t, &dim, *w, work, &lwork, rwork, &info);
if(info < 0)
quantum_error(QUANTUM_ELAPACKARG);
else if(info > 0)
quantum_error(QUANTUM_ELAPACKCHEEV);
lwork = (int) work[0];
work = realloc(work, lwork*sizeof(COMPLEX_FLOAT));
if(!work)
quantum_error(QUANTUM_ENOMEM);
cheev_(&jobz, &uplo, &dim, H.t, &dim, *w, work, &lwork, rwork, &info);
if(info < 0)
quantum_error(QUANTUM_ELAPACKARG);
else if(info > 0)
quantum_error(QUANTUM_ELAPACKCHEEV);
free(work);
quantum_mvmult(tmp1, H, reg0);
quantum_adjoint(&H);
}
if(tmp1->size != reg0->size)
{
p = regt->node;
*regt = *reg0;
regt->node = realloc(p, regt->size*sizeof(quantum_reg_node));
for(i=0; i<reg0->size; i++)
regt->node[i].state = i;
p = tmp1->node;
*tmp1 = *reg0;
tmp1->node = realloc(p, regt->size*sizeof(quantum_reg_node));
for(i=0; i<reg0->size; i++)
tmp1->node[i].state = i;
quantum_adjoint(&H);
quantum_mvmult(tmp1, H, reg0);
quantum_adjoint(&H);
}
for(i=0; i<dim; i++)
tmp2->node[i].amplitude = quantum_cexp(-(*w)[i]*t)*tmp1->node[i].amplitude;
quantum_mvmult(regt, H, tmp2);
#else
quantum_error(QUANTUM_ENOLAPACK);
#endif /* HAVE_LIBLAPACK */
}
|