ergo
template_lapack_larnv.h
Go to the documentation of this file.
1 /* Ergo, version 3.7, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
30  /* This file belongs to the template_lapack part of the Ergo source
31  * code. The source files in the template_lapack directory are modified
32  * versions of files originally distributed as CLAPACK, see the
33  * Copyright/license notice in the file template_lapack/COPYING.
34  */
35 
36 
37 #ifndef TEMPLATE_LAPACK_LARNV_HEADER
38 #define TEMPLATE_LAPACK_LARNV_HEADER
39 
40 
41 template<class Treal>
42 int template_lapack_larnv(const integer *idist, integer *iseed, const integer *n,
43  Treal *x)
44 {
45 /* -- LAPACK auxiliary routine (version 3.0) --
46  Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
47  Courant Institute, Argonne National Lab, and Rice University
48  September 30, 1994
49 
50 
51  Purpose
52  =======
53 
54  DLARNV returns a vector of n random real numbers from a uniform or
55  normal distribution.
56 
57  Arguments
58  =========
59 
60  IDIST (input) INTEGER
61  Specifies the distribution of the random numbers:
62  = 1: uniform (0,1)
63  = 2: uniform (-1,1)
64  = 3: normal (0,1)
65 
66  ISEED (input/output) INTEGER array, dimension (4)
67  On entry, the seed of the random number generator; the array
68  elements must be between 0 and 4095, and ISEED(4) must be
69  odd.
70  On exit, the seed is updated.
71 
72  N (input) INTEGER
73  The number of random numbers to be generated.
74 
75  X (output) DOUBLE PRECISION array, dimension (N)
76  The generated random numbers.
77 
78  Further Details
79  ===============
80 
81  This routine calls the auxiliary routine DLARUV to generate random
82  real numbers from a uniform (0,1) distribution, in batches of up to
83  128 using vectorisable code. The Box-Muller method is used to
84  transform numbers from a uniform to a normal distribution.
85 
86  =====================================================================
87 
88 
89  Parameter adjustments */
90  /* System generated locals */
91  integer i__1, i__2, i__3;
92  /* Local variables */
93  integer i__;
94  Treal u[128];
95  integer il, iv;
96  integer il2;
97 
98  --x;
99  --iseed;
100 
101  /* Function Body */
102  i__1 = *n;
103  for (iv = 1; iv <= i__1; iv += 64) {
104 /* Computing MIN */
105  i__2 = 64, i__3 = *n - iv + 1;
106  il = minMACRO(i__2,i__3);
107  if (*idist == 3) {
108  il2 = il << 1;
109  } else {
110  il2 = il;
111  }
112 
113 /* Call DLARUV to generate IL2 numbers from a uniform (0,1)
114  distribution (IL2 <= LV) */
115 
116  dlaruv_(&iseed[1], &il2, u);
117 
118  if (*idist == 1) {
119 
120 /* Copy generated numbers */
121 
122  i__2 = il;
123  for (i__ = 1; i__ <= i__2; ++i__) {
124  x[iv + i__ - 1] = u[i__ - 1];
125 /* L10: */
126  }
127  } else if (*idist == 2) {
128 
129 /* Convert generated numbers to uniform (-1,1) distribution */
130 
131  i__2 = il;
132  for (i__ = 1; i__ <= i__2; ++i__) {
133  x[iv + i__ - 1] = u[i__ - 1] * 2. - 1.;
134 /* L20: */
135  }
136  } else if (*idist == 3) {
137 
138 /* Convert generated numbers to normal (0,1) distribution */
139 
140  i__2 = il;
141  for (i__ = 1; i__ <= i__2; ++i__) {
142  x[iv + i__ - 1] = template_blas_sqrt(template_blas_log(u[(i__ << 1) - 2]) * -2.) * template_blas_cos(u[(
143  i__ << 1) - 1] * 6.2831853071795864769252867663);
144 /* L30: */
145  }
146  }
147 /* L40: */
148  }
149  return 0;
150 
151 /* End of DLARNV */
152 
153 } /* dlarnv_ */
154 
155 #endif
Treal template_blas_cos(Treal x)
int template_lapack_larnv(const integer *idist, integer *iseed, const integer *n, Treal *x)
Definition: template_lapack_larnv.h:42
int integer
Definition: template_blas_common.h:40
#define minMACRO(a, b)
Definition: template_blas_common.h:46
Treal template_blas_log(Treal x)
Treal template_blas_sqrt(Treal x)
int dlaruv_(integer *iseed, const integer *n, Treal *x)
Definition: template_lapack_laruv.h:42