Fixing copyright issues and code contributors
[alexxy/gromacs.git] / src / gmxlib / gmx_lapack / sgelqf.c
1 /*
2  * This file is part of the GROMACS molecular simulation package.
3  *
4  * Copyright (c) 2012,2013, by the GROMACS development team, led by
5  * David van der Spoel, Berk Hess, Erik Lindahl, and including many
6  * others, as listed in the AUTHORS file in the top-level source
7  * directory and at http://www.gromacs.org.
8  *
9  * GROMACS is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * as published by the Free Software Foundation; either version 2.1
12  * of the License, or (at your option) any later version.
13  *
14  * GROMACS is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with GROMACS; if not, see
21  * http://www.gnu.org/licenses, or write to the Free Software Foundation,
22  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA.
23  *
24  * If you want to redistribute modifications to GROMACS, please
25  * consider that scientific software is very special. Version
26  * control is crucial - bugs must be traceable. We will be happy to
27  * consider code for inclusion in the official distribution, but
28  * derived work must not be called official GROMACS. Details are found
29  * in the README & COPYING files - if they are missing, get the
30  * official version at http://www.gromacs.org.
31  *
32  * To help us fund GROMACS development, we humbly ask that you cite
33  * the research papers on the package. Check out http://www.gromacs.org.
34  */
35 #include <math.h>
36 #include "gmx_lapack.h"
37 #include "lapack_limits.h"
38
39
40
41 void
42 F77_FUNC(sgelqf,SGELQF)(int *m,
43         int *n, 
44         float *a, 
45         int *lda, 
46         float *tau,
47         float *work, 
48         int *lwork, 
49         int *info)
50 {
51     int a_dim1, a_offset, i__1, i__2, i__3, i__4;
52
53     int i__, k, ib, nb, nx, iws, nbmin, iinfo;
54     int ldwork, lwkopt;
55
56     a_dim1 = *lda;
57     a_offset = 1 + a_dim1;
58     a -= a_offset;
59     --tau;
60     --work;
61
62     *info = 0;
63     nb = DGELQF_BLOCKSIZE;
64     lwkopt = *m * nb;
65     work[1] = (float) lwkopt;
66
67     if (*lwork==-1) {
68         return;
69     }
70
71     k =(*m < *n) ? *m : *n;
72     if (k == 0) {
73         work[1] = 1.;
74         return;
75     }
76
77     nbmin = 2;
78     nx = 0;
79     iws = *m;
80     if (nb > 1 && nb < k) {
81         nx = DGELQF_CROSSOVER;
82         if (nx < k) {
83             ldwork = *m;
84             iws = ldwork * nb;
85             if (*lwork < iws) {
86
87                 nb = *lwork / ldwork;
88                 nbmin = DGELQF_MINBLOCKSIZE;
89             }
90         }
91     }
92
93     if (nb >= nbmin && nb < k && nx < k) {
94
95         i__1 = k - nx;
96         i__2 = nb;
97         for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
98             i__3 = k - i__ + 1;
99             ib = (i__3 < nb) ? i__3 : nb;
100
101             i__3 = *n - i__ + 1;
102             F77_FUNC(sgelq2,SGELQ2)(&ib, &i__3, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[
103                     1], &iinfo);
104             if (i__ + ib <= *m) {
105
106                 i__3 = *n - i__ + 1;
107                 F77_FUNC(slarft,SLARFT)("Forward", "Rowwise", &i__3, &ib, &a[i__ + i__ * 
108                         a_dim1], lda, &tau[i__], &work[1], &ldwork);
109
110                 i__3 = *m - i__ - ib + 1;
111                 i__4 = *n - i__ + 1;
112                 F77_FUNC(slarfb,SLARFB)("Right", "No transpose", "Forward", "Rowwise", &i__3, 
113                         &i__4, &ib, &a[i__ + i__ * a_dim1], lda, &work[1], &
114                         ldwork, &a[i__ + ib + i__ * a_dim1], lda, &work[ib + 
115                         1], &ldwork);
116             }
117         }
118     } else {
119         i__ = 1;
120     }
121
122     if (i__ <= k) {
123         i__2 = *m - i__ + 1;
124         i__1 = *n - i__ + 1;
125         F77_FUNC(sgelq2,SGELQ2)(&i__2, &i__1, &a[i__ + i__ * a_dim1], lda, &tau[i__], &work[1]
126                 , &iinfo);
127     }
128
129     work[1] = (float) iws;
130     return;
131
132 }