LIBINT 2.9.0
ITR_xs_xs.h
1/*
2 * Copyright (C) 2004-2024 Edward F. Valeev
3 *
4 * This file is part of Libint library.
5 *
6 * Libint library is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser 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 * Libint library 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 Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with Libint library. If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21#ifndef _libint2_src_lib_libint_itrxsxs_h_
22#define _libint2_src_lib_libint_itrxsxs_h_
23
24#include <libint2.h>
25#include <libint2/cgshell_ordering.h>
26#include <util_types.h>
27
28#include <cstdlib>
29
30namespace libint2 {
31
32template <int part, int La, int Lc, bool InBra, bool vectorize>
33struct ITR_xs_xs {
34 static void compute(const Libint_t* inteval, LIBINT2_REALTYPE* target,
35 const LIBINT2_REALTYPE* src0,
36 const LIBINT2_REALTYPE* src1,
37 const LIBINT2_REALTYPE* src2,
38 const LIBINT2_REALTYPE* src3);
39};
40
47template <int La, int Lc, bool InBra, bool vectorize>
48struct ITR_xs_xs<0, La, Lc, InBra, vectorize> {
49 static void compute(const Libint_t* inteval, LIBINT2_REALTYPE* target,
50 const LIBINT2_REALTYPE* src0,
51 const LIBINT2_REALTYPE* src1,
52 const LIBINT2_REALTYPE* src2,
53 const LIBINT2_REALTYPE* src3) {
54 // works for (ds|ps) and higher
55 if (La < 2 || Lc < 1) abort();
56
57 const unsigned int veclen = vectorize ? inteval->veclen : 1;
58
59 const unsigned int Nc = INT_NCART(Lc);
60 const unsigned int NcV = Nc * veclen;
61
62 int ax, ay, az;
63 FOR_CART(ax, ay, az, La)
64
65 int a[3];
66 a[0] = ax;
67 a[1] = ay;
68 a[2] = az;
69
70 enum XYZ { x = 0, y = 1, z = 2 };
71 // Build along x, if possible
72 XYZ xyz = z;
73 if (ay != 0) xyz = y;
74 if (ax != 0) xyz = x;
75 --a[xyz];
76
77 // redirect
78 const LIBINT2_REALTYPE* pfac0;
79 switch (xyz) {
80 case x:
81 pfac0 = InBra ?
82#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_0_0_x)
83 inteval->TwoPRepITR_pfac0_0_0_x
84#else
85 0
86#endif
87 :
88#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_0_1_x)
89 inteval->TwoPRepITR_pfac0_0_1_x;
90#else
91 0
92#endif
93 ;
94 break;
95 case y:
96 pfac0 = InBra ?
97#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_0_0_y)
98 inteval->TwoPRepITR_pfac0_0_0_y
99#else
100 0
101#endif
102 :
103#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_0_1_y)
104 inteval->TwoPRepITR_pfac0_0_1_y;
105#else
106 0
107#endif
108 ;
109 break;
110 case z:
111 pfac0 = InBra ?
112#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_0_0_z)
113 inteval->TwoPRepITR_pfac0_0_0_z
114#else
115 0
116#endif
117 :
118#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_0_1_z)
119 inteval->TwoPRepITR_pfac0_0_1_z;
120#else
121 0
122#endif
123 ;
124 break;
125 }
126
127 const unsigned int iam1 = INT_CARTINDEX(La - 1, a[0], a[1]);
128 const unsigned int am10c0_offset = iam1 * NcV;
129 const LIBINT2_REALTYPE* src0_ptr = src0 + am10c0_offset;
130
131 // if a-2_xyz exists, include (a-2_xyz 0 | c 0)
132 if (a[xyz] > 0) {
133 --a[xyz];
134 const unsigned int iam2 = INT_CARTINDEX(La - 2, a[0], a[1]);
135 const unsigned int am20c0_offset = iam2 * NcV;
136 ++a[xyz];
137 const LIBINT2_REALTYPE* src2_ptr = src2 + am20c0_offset;
138 const LIBINT2_REALTYPE axyz = (LIBINT2_REALTYPE)a[xyz];
139
140 unsigned int cv = 0;
141 for (unsigned int c = 0; c < Nc; ++c) {
142 for (unsigned int v = 0; v < veclen; ++v, ++cv) {
143 target[cv] =
144 pfac0[v] * src0_ptr[cv] + axyz * inteval->oo2z[v] * src2_ptr[cv];
145 }
146 }
147#if LIBINT2_FLOP_COUNT
148 inteval->nflops[0] += 4 * NcV;
149#endif
150
151 } else {
152 unsigned int cv = 0;
153 for (unsigned int c = 0; c < Nc; ++c) {
154 for (unsigned int v = 0; v < veclen; ++v, ++cv) {
155 target[cv] = pfac0[v] * src0_ptr[cv];
156 }
157 }
158#if LIBINT2_FLOP_COUNT
159 inteval->nflops[0] += 1 * NcV;
160#endif
161 }
162
163 {
164 const unsigned int Ncp1 = INT_NCART(Lc + 1);
165 const unsigned int Ncp1V = Ncp1 * veclen;
166 const unsigned int am10cp10_offset = iam1 * Ncp1V;
167 const LIBINT2_REALTYPE* src1_ptr = src1 + am10cp10_offset;
168
169 // loop over c shell and include (a-1_xyz 0 | c+1_xyz 0) to (a 0 | c 0)
170 int cx, cy, cz;
171 int cv = 0;
172 FOR_CART(cx, cy, cz, Lc)
173
174 int c[3];
175 c[0] = cx;
176 c[1] = cy;
177 c[2] = cz;
178 ++c[xyz];
179
180 const unsigned int cp1 = INT_CARTINDEX(Lc + 1, c[0], c[1]);
181 const unsigned int cp1_offset = cp1 * veclen;
182 const LIBINT2_REALTYPE* sptr = src1_ptr + cp1_offset;
183 const LIBINT2_REALTYPE cxyz = (LIBINT2_REALTYPE)c[xyz];
184 for (unsigned int v = 0; v < veclen; ++v, ++cv) {
185 target[cv] -= inteval->eoz[v] * sptr[v];
186 }
187#if LIBINT2_FLOP_COUNT
188 inteval->nflops[0] += 2 * veclen;
189#endif
190
191 END_FOR_CART
192 }
193
194 {
195 const unsigned int Ncm1 = INT_NCART(Lc - 1);
196 const unsigned int Ncm1V = Ncm1 * veclen;
197 const unsigned int am10cm10_offset = iam1 * Ncm1V;
198 const LIBINT2_REALTYPE* src3_ptr = src3 + am10cm10_offset;
199
200 // loop over c-1 shell and include (a-1_xyz 0 | c-1_xyz 0) to (a 0 | c 0)
201 int cx, cy, cz;
202 FOR_CART(cx, cy, cz, Lc - 1)
203
204 int c[3];
205 c[0] = cx;
206 c[1] = cy;
207 c[2] = cz;
208 ++c[xyz];
209
210 const unsigned int cc = INT_CARTINDEX(Lc, c[0], c[1]);
211 const unsigned int cc_offset = cc * veclen;
212 LIBINT2_REALTYPE* tptr = target + cc_offset;
213 const LIBINT2_REALTYPE cxyz = (LIBINT2_REALTYPE)c[xyz];
214 for (unsigned int v = 0; v < veclen; ++v) {
215 tptr[v] += cxyz * inteval->oo2z[v] * src3_ptr[v];
216 }
217#if LIBINT2_FLOP_COUNT
218 inteval->nflops[0] += 3 * veclen;
219#endif
220 src3_ptr += veclen;
221
222 END_FOR_CART
223 }
224
225 target += NcV;
226
227 END_FOR_CART
228 }
229};
230
231#if 0
238 template <int La, int Lc, bool InBra, bool vectorize> struct ITR_xs_xs<1,La,Lc,InBra,vectorize> {
239
240 static void compute(const Libint_t* inteval,
241 LIBINT2_REALTYPE* target,
242 const LIBINT2_REALTYPE* src0,
243 const LIBINT2_REALTYPE* src1,
244 const LIBINT2_REALTYPE* src2,
245 const LIBINT2_REALTYPE* src3) {
246
247 // works for (ps|ds) and higher
248 if (La < 1 || Lc < 2)
249 abort();
250
251 const unsigned int veclen = vectorize ? inteval->veclen : 1;
252
253 const unsigned int Na = INT_NCART(La);
254 const unsigned int NaV = Na * veclen;
255
256 int cx, cy, cz;
257 FOR_CART(cx, cy, cz, Lc)
258
259 int c[3]; c[0] = cx; c[1] = cy; c[2] = cz;
260
261 enum XYZ {x=0, y=1, z=2};
262 // Build along x, if possible
263 XYZ xyz = z;
264 if (cy != 0) xyz = y;
265 if (cx != 0) xyz = x;
266 --c[xyz];
267
268 // redirect
269 const LIBINT2_REALTYPE *pfac0;
270 switch(xyz) {
271 case x:
272 pfac0 = InBra ?
273#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_1_0_x)
274 inteval->TwoPRepITR_pfac0_1_0_x
275#else
276 0
277#endif
278 :
279#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_0_1_x)
280 inteval->TwoPRepITR_pfac0_0_1_x;
281#else
282 0
283#endif
284 ;
285 break;
286 case y:
287 pfac0 = InBra ?
288#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_1_0_y)
289 inteval->TwoPRepITR_pfac0_1_0_y
290#else
291 0
292#endif
293 :
294#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_1_1_y)
295 inteval->TwoPRepITR_pfac0_1_1_y;
296#else
297 0
298#endif
299 ;
300 break;
301 case z:
302 pfac0 = InBra ?
303#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_1_0_z)
304 inteval->TwoPRepITR_pfac0_1_0_z
305#else
306 0
307#endif
308 :
309#if LIBINT2_DEFINED(eri, TwoPRepITR_pfac0_1_1_z)
310 inteval->TwoPRepITR_pfac0_1_1_z;
311#else
312 0
313#endif
314 ;
315 break;
316 }
317
318 const unsigned int icm1 = INT_CARTINDEX(Lc-1,c[0],c[1]);
319 const unsigned int a0cm10_offset = icm1 * NaV;
320 const LIBINT2_REALTYPE* src0_ptr = src0 + a0cm10_offset;
321
322 // if c-2_xyz exists, include (a 0 | c-2_xyz 0)
323 if (c[xyz] > 0) {
324 --c[xyz];
325 const unsigned int icm2 = INT_CARTINDEX(Lc-2,c[0],c[1]);
326 const unsigned int a0cm20_offset = icm2 * NaV;
327 ++c[xyz];
328 const LIBINT2_REALTYPE* src2_ptr = src2 + am20c0_offset;
329 const LIBINT2_REALTYPE axyz = (LIBINT2_REALTYPE)c[xyz];
330
331 unsigned int cv = 0;
332 for(unsigned int c = 0; c < Nc; ++c) {
333 for(unsigned int v=0; v<veclen; ++v, ++cv) {
334 target[cv] = pfac0[v] * src0_ptr[cv] + axyz * inteval->oo2z[v] * src2_ptr[cv];
335 }
336 }
337#if LIBINT2_FLOP_COUNT
338 inteval->nflops[0] += 4 * NcV;
339#endif
340
341 }
342 else {
343 unsigned int cv = 0;
344 for(unsigned int c = 0; c < Nc; ++c) {
345 for(unsigned int v=0; v<veclen; ++v, ++cv) {
346 target[cv] = pfac0[v] * src0_ptr[cv];
347 }
348 }
349#if LIBINT2_FLOP_COUNT
350 inteval->nflops[0] += 1 * NcV;
351#endif
352 }
353
354 {
355 const unsigned int Ncp1 = INT_NCART(Lc+1);
356 const unsigned int Ncp1V = Ncp1 * veclen;
357 const unsigned int am10cp10_offset = iam1 * Ncp1V;
358 const LIBINT2_REALTYPE* src1_ptr = src1 + am10cp10_offset;
359
360 // loop over c shell and include (c-1_xyz 0 | c+1_xyz 0) to (c 0 | c 0)
361 int cx, cy, cz;
362 int cv = 0;
363 FOR_CART(cx, cy, cz, Lc)
364
365 int c[3]; c[0] = cx; c[1] = cy; c[2] = cz;
366 ++c[xyz];
367
368 const unsigned int cp1 = INT_CARTINDEX(Lc+1,c[0],c[1]);
369 const unsigned int cp1_offset = cp1 * veclen;
370 const LIBINT2_REALTYPE* sptr = src1_ptr + cp1_offset;
371 const LIBINT2_REALTYPE cxyz = (LIBINT2_REALTYPE)c[xyz];
372 for(unsigned int v=0; v<veclen; ++v, ++cv) {
373 target[cv] -= inteval->eoz[v] * sptr[v];
374 }
375#if LIBINT2_FLOP_COUNT
376 inteval->nflops[0] += 2 * veclen;
377#endif
378
379 END_FOR_CART
380 }
381
382
383 {
384 const unsigned int Ncm1 = INT_NCART(Lc-1);
385 const unsigned int Ncm1V = Ncm1 * veclen;
386 const unsigned int am10cm10_offset = iam1 * Ncm1V;
387 const LIBINT2_REALTYPE* src3_ptr = src3 + am10cm10_offset;
388
389 // loop over c-1 shell and include (c-1_xyz 0 | c-1_xyz 0) to (c 0 | c 0)
390 int cx, cy, cz;
391 FOR_CART(cx, cy, cz, Lc-1)
392
393 int c[3]; c[0] = cx; c[1] = cy; c[2] = cz;
394 ++c[xyz];
395
396 const unsigned int cc = INT_CARTINDEX(Lc,c[0],c[1]);
397 const unsigned int cc_offset = cc * veclen;
398 LIBINT2_REALTYPE* tptr = target + cc_offset;
399 const LIBINT2_REALTYPE cxyz = (LIBINT2_REALTYPE)c[xyz];
400 for(unsigned int v=0; v<veclen; ++v) {
401 tptr[v] += cxyz * inteval->oo2z[v] * src3_ptr[v];
402 }
403#if LIBINT2_FLOP_COUNT
404 inteval->nflops[0] += 3 * veclen;
405#endif
406 src3_ptr += veclen;
407
408 END_FOR_CART
409 }
410
411 target += NcV;
412
413 END_FOR_CART
414
415 }
416
417 };
418#endif
419
420}; // namespace libint2
421
422#endif // header guard
Defaults definitions for various parameters assumed by Libint.
Definition algebra.cc:24
Definition ITR_xs_xs.h:33