Skip to content

Commit

Permalink
Release v4.1.3
Browse files Browse the repository at this point in the history
Fix memory address int32 overflow for heavily contracted basis
  • Loading branch information
sunqm committed Apr 13, 2021
1 parent faaba0b commit 38fa7cd
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.5)
project (qcint C)
set(qcint_VERSION_MAJOR "4")
set(qcint_VERSION_MINOR "1")
set(qcint_VERSION_PATCH "2")
set(qcint_VERSION_PATCH "3")
set(qcint_VERSION_TWEAK "0")
set(qcint_VERSION "${qcint_VERSION_MAJOR}.${qcint_VERSION_MINOR}.${qcint_VERSION_PATCH}")
set(qcint_SOVERSION "${qcint_VERSION_MAJOR}")
Expand Down
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Version 4.1.3 (2021-04-13):
* Fix memory address int32 overflow for heavily contracted basis
Version 4.1.2 (2021-04-10):
* Fix a bug due to significant digits of float128 in the core Fmt integrals
* Fix compiling error for stg, coulomb_erf integral code
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ qcint (quick libcint)

An optimized libcint branch for X86 platform

version 4.1.2
version 4.1.3

2021-04-10
2021-04-13


What is qcint
Expand Down
8 changes: 4 additions & 4 deletions src/cart2sph.c
Original file line number Diff line number Diff line change
Expand Up @@ -7343,8 +7343,8 @@ void c2s_dset0(double *out, int *dims, int *counts)
int ni = dims[0];
int nj = dims[1];
int nk = dims[2];
int nij = ni * nj;
int nijk = nij * nk;
size_t nij = ni * nj;
size_t nijk = nij * nk;
int i, j, k, l;
if (dims == counts) {
for (i = 0; i < nijk * counts[3]; i++) {
Expand Down Expand Up @@ -7373,8 +7373,8 @@ void c2s_zset0(double complex *out, int *dims, int *counts)
int ni = dims[0];
int nj = dims[1];
int nk = dims[2];
int nij = ni * nj;
int nijk = nij * nk;
size_t nij = ni * nj;
size_t nijk = nij * nk;
int i, j, k, l;
if (dims == counts) {
for (i = 0; i < nijk * counts[3]; i++) {
Expand Down
94 changes: 58 additions & 36 deletions src/cint2e.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
*/

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <math.h>
#include "cint_bas.h"
#include "misc.h"
Expand Down Expand Up @@ -218,7 +219,7 @@ int CINT2e_loop_nopt(double *out, CINTEnvVars *envs, double *cache)
double *rk = envs->rk;
double *rl = envs->rl;
int n_comp = envs->ncomp_e1 * envs->ncomp_e2 * envs->ncomp_tensor;
int nf = envs->nf;
size_t nf = envs->nf;
double fac1i, fac1j, fac1k, fac1l;
int ip, jp, kp, lp, i, it, im;
int empty[4] = {1, 1, 1, 1};
Expand Down Expand Up @@ -251,18 +252,18 @@ int CINT2e_loop_nopt(double *out, CINTEnvVars *envs, double *cache)
* CINTcommon_fac_sp(envs->i_l) * CINTcommon_fac_sp(envs->j_l)
* CINTcommon_fac_sp(envs->k_l) * CINTcommon_fac_sp(envs->l_l);

int ngp[4];
size_t ngp[4];
ngp[0] = nf * n_comp;
ngp[1] = ngp[0] * i_ctr;
ngp[2] = ngp[1] * j_ctr;
ngp[3] = ngp[2] * k_ctr;
// (irys,i,j,k,l,coord,0:1); +1 for nabla-r12
int leng = envs->g_size * 3 * ((1<<envs->gbits)+1) * SIMDD;
int len0 = ngp[0] * SIMDD;
int leni = ALIGN_UP(ngp[1], SIMDD);
int lenj = ALIGN_UP(ngp[2], SIMDD);
int lenk = ALIGN_UP(ngp[3], SIMDD);
int lenl = ALIGN_UP(ngp[3] * l_ctr, SIMDD);
size_t len0 = ngp[0] * SIMDD;
size_t leni = ALIGN_UP(ngp[1], SIMDD);
size_t lenj = ALIGN_UP(ngp[2], SIMDD);
size_t lenk = ALIGN_UP(ngp[3], SIMDD);
size_t lenl = ALIGN_UP(ngp[3] * l_ctr, SIMDD);

double *gout, *g, *g1;
double *gctr[4];
Expand Down Expand Up @@ -402,7 +403,7 @@ int CINT2e_loop(double *out, CINTEnvVars *envs, CINTOpt *opt, double *cache)
}

int n_comp = envs->ncomp_e1 * envs->ncomp_e2 * envs->ncomp_tensor;
int nf = envs->nf;
size_t nf = envs->nf;
double fac1i, fac1j, fac1k, fac1l;
int ip, jp, kp, lp, i, it, im;
int empty[4] = {1, 1, 1, 1};
Expand All @@ -420,18 +421,18 @@ int CINT2e_loop(double *out, CINTEnvVars *envs, CINTOpt *opt, double *cache)
CINTg4c_index_xyz(idx, envs);
}

int ngp[4];
size_t ngp[4];
ngp[0] = nf * n_comp;
ngp[1] = ngp[0] * i_ctr;
ngp[2] = ngp[1] * j_ctr;
ngp[3] = ngp[2] * k_ctr;
// (irys,i,j,k,l,coord,0:1); +1 for nabla-r12
int leng = envs->g_size * 3 * ((1<<envs->gbits)+1) * SIMDD;
int len0 = ngp[0] * SIMDD;
int leni = ALIGN_UP(ngp[1], SIMDD);
int lenj = ALIGN_UP(ngp[2], SIMDD);
int lenk = ALIGN_UP(ngp[3], SIMDD);
int lenl = ALIGN_UP(ngp[3] * l_ctr, SIMDD);
size_t len0 = ngp[0] * SIMDD;
size_t leni = ALIGN_UP(ngp[1], SIMDD);
size_t lenj = ALIGN_UP(ngp[2], SIMDD);
size_t lenk = ALIGN_UP(ngp[3], SIMDD);
size_t lenl = ALIGN_UP(ngp[3] * l_ctr, SIMDD);
double *gout, *g, *g1;
double *gctr[4];
double *bufctr[4];
Expand Down Expand Up @@ -521,32 +522,39 @@ k_contracted: ;
int j_prim = bas(NPRIM_OF, shls[1]); \
int k_prim = bas(NPRIM_OF, shls[2]); \
int l_prim = bas(NPRIM_OF, shls[3]); \
int ps = ((i_prim*j_prim + k_prim*l_prim) * 5 \
size_t ps = ((i_prim*j_prim + k_prim*l_prim) * 5 \
+ i_prim * x_ctr[0] \
+ j_prim * x_ctr[1] \
+ k_prim * x_ctr[2] \
+ l_prim * x_ctr[3] \
+(i_prim+j_prim+k_prim+l_prim)*2 + envs->nf*3);
+(i_prim+j_prim+k_prim+l_prim)*2 + nf*3);

int CINT2e_cart_drv(double *out, int *dims, CINTEnvVars *envs, CINTOpt *opt,
double *cache)
{
int *x_ctr = envs->x_ctr;
int nc = envs->nf * x_ctr[0] * x_ctr[1] * x_ctr[2] * x_ctr[3];
size_t nf = envs->nf;
size_t nc = nf * x_ctr[0] * x_ctr[1] * x_ctr[2] * x_ctr[3];
int n_comp = envs->ncomp_e1 * envs->ncomp_e2 * envs->ncomp_tensor;
if (out == NULL) {
PAIRDATA_NON0IDX_SIZE(pdata_size);
int leng = envs->g_size*3*((1<<envs->gbits)+1)*SIMDD;
int len0 = envs->nf*n_comp * SIMDD;
int cache_size = leng + len0 + nc*n_comp*2 + SIMDD*4 + pdata_size;
size_t len0 = nf*n_comp * SIMDD;
size_t cache_size = leng + len0 + nc*n_comp*2 + SIMDD*4 + pdata_size;
if (cache_size >= INT32_MAX) {
fprintf(stderr, "CINT2e_cart_drv cache_size overflow: "
"cache_size %ld > %d, nf %ld, nc %ld, n_comp %d\n",
cache_size, INT32_MAX, nf, nc, n_comp);
cache_size = 0;
}
return cache_size;
}
double *stack = NULL;
if (cache == NULL) {
PAIRDATA_NON0IDX_SIZE(pdata_size);
int leng = envs->g_size*3*((1<<envs->gbits)+1)*SIMDD;
int len0 = envs->nf*n_comp * SIMDD;
int cache_size = leng + len0 + nc*n_comp*2 + SIMDD*4 + pdata_size;
size_t len0 = nf*n_comp * SIMDD;
size_t cache_size = leng + len0 + nc*n_comp*2 + SIMDD*4 + pdata_size;
stack = _mm_malloc(sizeof(double)*cache_size, sizeof(double)*SIMDD);
cache = stack;
}
Expand Down Expand Up @@ -587,23 +595,30 @@ int CINT2e_spheric_drv(double *out, int *dims, CINTEnvVars *envs, CINTOpt *opt,
double *cache)
{
int *x_ctr = envs->x_ctr;
int nc = envs->nf * x_ctr[0] * x_ctr[1] * x_ctr[2] * x_ctr[3];
size_t nf = envs->nf;
size_t nc = nf * x_ctr[0] * x_ctr[1] * x_ctr[2] * x_ctr[3];
int n_comp = envs->ncomp_e1 * envs->ncomp_e2 * envs->ncomp_tensor;
if (out == NULL) {
PAIRDATA_NON0IDX_SIZE(pdata_size);
int leng = envs->g_size*3*((1<<envs->gbits)+1)*SIMDD;
int len0 = envs->nf*n_comp * SIMDD;
int cache_size = MAX(leng+len0+nc*n_comp*2 + pdata_size,
nc*n_comp+envs->nf*4) + SIMDD*4;
size_t len0 = nf*n_comp * SIMDD;
size_t cache_size = MAX(leng+len0+nc*n_comp*2 + pdata_size,
nc*n_comp+nf*4) + SIMDD*4;
if (cache_size >= INT32_MAX) {
fprintf(stderr, "CINT2e_spinor_drv cache_size overflow: "
"cache_size %ld > %d, nf %ld, nc %ld, n_comp %d\n",
cache_size, INT32_MAX, nf, nc, n_comp);
cache_size = 0;
}
return cache_size;
}
double *stack = NULL;
if (cache == NULL) {
PAIRDATA_NON0IDX_SIZE(pdata_size);
int leng = envs->g_size*3*((1<<envs->gbits)+1)*SIMDD;
int len0 = envs->nf*n_comp * SIMDD;
int cache_size = MAX(leng+len0+nc*n_comp*2 + pdata_size,
nc*n_comp+envs->nf*4) + SIMDD*4;
size_t len0 = nf*n_comp * SIMDD;
size_t cache_size = MAX(leng+len0+nc*n_comp*2 + pdata_size,
nc*n_comp+nf*4) + SIMDD*4;
stack = _mm_malloc(sizeof(double)*cache_size, sizeof(double)*SIMDD);
cache = stack;
}
Expand Down Expand Up @@ -651,27 +666,34 @@ int CINT2e_spinor_drv(double complex *out, int *dims, CINTEnvVars *envs, CINTOpt
counts[2] = CINTcgto_spinor(shls[2], bas);
counts[3] = CINTcgto_spinor(shls[3], bas);
int *x_ctr = envs->x_ctr;
int nc = envs->nf * x_ctr[0] * x_ctr[1] * x_ctr[2] * x_ctr[3];
size_t nf = envs->nf;
size_t nc = nf * x_ctr[0] * x_ctr[1] * x_ctr[2] * x_ctr[3];
int n_comp = envs->ncomp_e1 * envs->ncomp_e2 * envs->ncomp_tensor;
int n1 = counts[0] * envs->nfk * x_ctr[2]
* envs->nfl * x_ctr[3] * counts[1];
if (out == NULL) {
PAIRDATA_NON0IDX_SIZE(pdata_size);
int leng = envs->g_size*3*((1<<envs->gbits)+1)*SIMDD;
int len0 = envs->nf*n_comp * SIMDD;
int cache_size = MAX(leng+len0+nc*n_comp*2 + pdata_size,
size_t len0 = nf*n_comp * SIMDD;
size_t cache_size = MAX(leng+len0+nc*n_comp*2 + pdata_size,
nc*n_comp + n1*envs->ncomp_e2*OF_CMPLX
+ envs->nf*32*OF_CMPLX) + SIMDD*4;
+ nf*32*OF_CMPLX) + SIMDD*4;
if (cache_size >= INT32_MAX) {
fprintf(stderr, "CINT2e_spheric_drv cache_size overflow: "
"cache_size %ld > %d, nf %ld, nc %ld, n_comp %d\n",
cache_size, INT32_MAX, nf, nc, n_comp);
cache_size = 0;
}
return cache_size;
}
double *stack = NULL;
if (cache == NULL) {
PAIRDATA_NON0IDX_SIZE(pdata_size);
int leng = envs->g_size*3*((1<<envs->gbits)+1)*SIMDD;
int len0 = envs->nf*n_comp * SIMDD;
int cache_size = MAX(leng+len0+nc*n_comp*2 + pdata_size,
size_t len0 = nf*n_comp * SIMDD;
size_t cache_size = MAX(leng+len0+nc*n_comp*2 + pdata_size,
nc*n_comp + n1*envs->ncomp_e2*OF_CMPLX
+ envs->nf*32*OF_CMPLX) + SIMDD*4;
+ nf*32*OF_CMPLX) + SIMDD*4;
stack = _mm_malloc(sizeof(double)*cache_size, sizeof(double)*SIMDD);
cache = stack;
}
Expand Down
14 changes: 8 additions & 6 deletions src/g1e.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,10 +609,11 @@ MM_STORE(fz+n*SIMDD, MM_FMA(r2, MM_LOAD(gz+n*SIMDD), MM_LOAD(p1z+n*SIMDD)));
}


void CINTprim_to_ctr_0(double *RESTRICT gc, double *RESTRICT gp, double *RESTRICT coeff, int nf,
void CINTprim_to_ctr_0(double *RESTRICT gc, double *RESTRICT gp, double *RESTRICT coeff, size_t nf,
int nprim, int nctr, int non0ctr, int *sortedidx)
{
int n, i;
int i;
size_t n;
double c0, c1, c2, c3;
double *RESTRICT p0;
double *RESTRICT p1;
Expand Down Expand Up @@ -740,10 +741,11 @@ void CINTprim_to_ctr_0(double *RESTRICT gc, double *RESTRICT gp, double *RESTRIC
}
}

void CINTprim_to_ctr_1(double *RESTRICT gc, double *RESTRICT gp, double *RESTRICT coeff, int nf,
void CINTprim_to_ctr_1(double *RESTRICT gc, double *RESTRICT gp, double *RESTRICT coeff, size_t nf,
int nprim, int nctr, int non0ctr, int *sortedidx)
{
int n, i;
int i;
size_t n;
double c0, c1, c2, c3;
double *RESTRICT p0;
double *RESTRICT p1;
Expand Down Expand Up @@ -877,7 +879,7 @@ double CINTcommon_fac_sp(int l)
}


void CINTiprim_to_ctr_0(double *RESTRICT gc, double *RESTRICT gp, double *RESTRICT coeff, int nf,
void CINTiprim_to_ctr_0(double *RESTRICT gc, double *RESTRICT gp, double *RESTRICT coeff, size_t nf,
int nprim, int nctr, int non0ctr, int *sortedidx)
{
int i;
Expand Down Expand Up @@ -927,7 +929,7 @@ void CINTiprim_to_ctr_0(double *RESTRICT gc, double *RESTRICT gp, double *RESTRI
}
}

void CINTiprim_to_ctr_1(double *RESTRICT gc, double *RESTRICT gp, double *RESTRICT coeff, int nf,
void CINTiprim_to_ctr_1(double *RESTRICT gc, double *RESTRICT gp, double *RESTRICT coeff, size_t nf,
int nprim, int nctr, int non0ctr, int *sortedidx)
{
int i;
Expand Down
8 changes: 4 additions & 4 deletions src/g1e.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ void CINTx1k_1e(double *f, double *g, double *rk,

void CINTprim_to_ctr(double *gc, int nf, double *gp,
int inc, int nprim, int nctr, double *pcoeff);
void CINTprim_to_ctr_0(double *gc, double *gp, double *coeff, int nf,
void CINTprim_to_ctr_0(double *gc, double *gp, double *coeff, size_t nf,
int nprim, int nctr, int non0ctr, int *sortedidx);
void CINTprim_to_ctr_1(double *gc, double *gp, double *coeff, int nf,
void CINTprim_to_ctr_1(double *gc, double *gp, double *coeff, size_t nf,
int nprim, int nctr, int non0ctr, int *sortedidx);
void CINTiprim_to_ctr_0(double *gc, double *gp, double *coeff, int nf,
void CINTiprim_to_ctr_0(double *gc, double *gp, double *coeff, size_t nf,
int nprim, int nctr, int non0ctr, int *sortedidx);
void CINTiprim_to_ctr_1(double *gc, double *gp, double *coeff, int nf,
void CINTiprim_to_ctr_1(double *gc, double *gp, double *coeff, size_t nf,
int nprim, int nctr, int non0ctr, int *sortedidx);
void CINTsort_gout(double *sout, double *gout, int nf, int count);

Expand Down

0 comments on commit 38fa7cd

Please sign in to comment.