void GTO2e_cart_or_sph(int (*intor)(), int (*cgto_in_shell)(), double *eri, int *atm, int natm, int *bas, int nbas, double *env) { int *ao_loc = malloc(sizeof(int)*(nbas+1)); int i, j, ij; int nao = 0; for (i = 0; i < nbas; i++) { ao_loc[i] = nao; nao += (*cgto_in_shell)(i, bas); } ao_loc[nbas] = nao; struct _VHFEnvs envs = {natm, nbas, atm, bas, env, nao, ao_loc}; CINTOpt *cintopt; cint2e_optimizer(&cintopt, atm, natm, bas, nbas, env); CVHFOpt *vhfopt; CVHFnr_optimizer(&vhfopt, atm, natm, bas, nbas, env); vhfopt->fprescreen = CVHFnr_schwarz_cond; #pragma omp parallel default(none) \ shared(intor, eri, nbas, envs, cintopt, vhfopt) \ private(ij, i, j) #pragma omp for nowait schedule(dynamic, 2) for (ij = 0; ij < nbas*(nbas+1)/2; ij++) { i = (int)(sqrt(2*ij+.25) - .5 + 1e-7); j = ij - (i*(i+1)/2); store_ij(intor, eri, i, j, cintopt, vhfopt, &envs); } free(ao_loc); CVHFdel_optimizer(&vhfopt); CINTdel_optimizer(&cintopt); }
void RInr_fill2c2e_sph(double *eri, int auxstart, int auxcount, int *atm, int natm, int *bas, int nbas, double *env) { const int nbasnaux = auxstart + auxcount; int *ao_loc = malloc(sizeof(int)*(nbasnaux+1)); CINTshells_spheric_offset(ao_loc, bas, nbasnaux); ao_loc[nbasnaux] = ao_loc[nbasnaux-1] + CINTcgto_spheric(nbasnaux-1, bas); const int naoaux = ao_loc[nbasnaux] - ao_loc[auxstart]; double *buf; int ish, jsh, di, dj; int i, j, i0, j0; int shls[2]; CINTOpt *cintopt = NULL; cint2c2e_sph_optimizer(&cintopt, atm, natm, bas, nbas, env); #pragma omp parallel default(none) \ shared(eri, auxstart, auxcount, atm, natm, bas, nbas, env, \ ao_loc, cintopt) \ private(ish, jsh, di, dj, i, j, i0, j0, shls, buf) #pragma omp for nowait schedule(dynamic) for (ish = auxstart; ish < nbasnaux; ish++) { for (jsh = auxstart; jsh <= ish; jsh++) { di = ao_loc[ish+1] - ao_loc[ish]; dj = ao_loc[jsh+1] - ao_loc[jsh]; shls[0] = ish; shls[1] = jsh; buf = (double *)malloc(sizeof(double) * di * dj); if (cint2c2e_sph(buf, shls, atm, natm, bas, nbas, env, cintopt)) { for (i0 = ao_loc[ish]-ao_loc[auxstart], i = 0; i < di; i++, i0++) { for (j0 = ao_loc[jsh]-ao_loc[auxstart], j = 0; j < dj; j++, j0++) { eri[i0*naoaux+j0] = buf[j*di+i]; } } } else { for (i0 = ao_loc[ish]-ao_loc[auxstart]; i0 < ao_loc[ish+1]-ao_loc[auxstart]; i0++) { for (j0 = ao_loc[jsh]-ao_loc[auxstart]; j0 < ao_loc[jsh+1]-ao_loc[auxstart]; j0++) { eri[i0*naoaux+j0] = 0; } } } free(buf); } } for (i = 0; i < naoaux; i++) { for (j = 0; j < i; j++) { eri[j*naoaux+i] = eri[i*naoaux+j]; } } free(ao_loc); CINTdel_optimizer(&cintopt); }
void run_all(int *atm, int natm, int *bas, int nbas, double *env) { int i, j, k, l, ij, kl; int di, dj, dk, dl; int kl_max; int shls[4]; double *buf; int *ishls = malloc(sizeof(int)*nbas*nbas); int *jshls = malloc(sizeof(int)*nbas*nbas); for (i = 0, ij = 0; i < nbas; i++) { for (j = 0; j <= i; j++, ij++) { ishls[ij] = i; jshls[ij] = j; } } int ncgto = CINTtot_cgto_spheric(bas, nbas); printf("\tshells = %d, total cGTO = %d, total pGTO = %d\n", nbas, ncgto, CINTtot_pgto_spheric(bas, nbas)); int pct; long count; double time0, time1 = 0; double tt, tot; tot = (double)ncgto*ncgto*ncgto*ncgto/8; time0 = omp_get_wtime(); printf("\tcint2e_sph with optimizer: total num ERI = %.2e\n", tot); CINTOpt *opt = NULL; cint2e_sph_optimizer(&opt, atm, natm, bas, nbas, env); pct = 0; count = 0; #pragma omp parallel default(none) \ shared(atm, natm, bas, nbas, env, ishls, jshls, opt, time0, pct, count, stdout) \ private(di, dj, dk, dl, i, j, k, l, ij, kl, kl_max, shls, buf, time1) #pragma omp for nowait schedule(dynamic, 2) for (ij = 0; ij < nbas*(nbas+1)/2; ij++) { i = ishls[ij]; j = jshls[ij]; di = CINTcgto_spheric(i, bas); dj = CINTcgto_spheric(j, bas); // when ksh==ish, there exists k<i, so it's possible kl>ij kl_max = (i+1)*(i+2)/2; for (kl = 0; kl < kl_max; kl++) { k = ishls[kl]; l = jshls[kl]; dk = CINTcgto_spheric(k, bas); dl = CINTcgto_spheric(l, bas); shls[0] = i; shls[1] = j; shls[2] = k; shls[3] = l; buf = malloc(sizeof(double) * di*dj*dk*dl); cint2e_sph(buf, shls, atm, natm, bas, nbas, env, opt); free(buf); } count += kl_max; if (100l*count/((long)nbas*nbas*(nbas+1)*(nbas+2)/8) > pct) { pct++; time1 = omp_get_wtime(); printf("\t%d%%, CPU time = %8.2f\r", pct, time1-time0); fflush(stdout); } } time1 = omp_get_wtime(); tt = time1-time0; printf("\t100%%, CPU time = %8.2f, %8.4f Mflops\n", tt, tot/1e6/tt); CINTdel_optimizer(&opt); free(ishls); free(jshls); }
int main() { int natm = 2; int nbas = 4; // ATM_SLOTS = 6; BAS_SLOTS = 8; int *atm = malloc(sizeof(int) * natm * ATM_SLOTS); int *bas = malloc(sizeof(int) * nbas * BAS_SLOTS); double *env = malloc(sizeof(double) * 10000); int i, n, off; off = PTR_ENV_START; // = 20 i = 0; atm[CHARGE_OF + ATM_SLOTS * i] = 1; atm[PTR_COORD + ATM_SLOTS * i] = off; env[off + 0] = 0; // x (Bohr) env[off + 1] = 0; // y (Bohr) env[off + 2] =-.8; // z (Bohr) i++; off += 3; atm[CHARGE_OF + ATM_SLOTS * i] = 1; atm[PTR_COORD + ATM_SLOTS * i] = off; env[off + 0] = 0; env[off + 1] = 0; env[off + 2] =.8; // (Bohr) i++; off += 3; n = 0; /* basis #0 with kappa > 0 => p_1/2 */ bas[ATOM_OF + BAS_SLOTS * n] = 0; bas[ANG_OF + BAS_SLOTS * n] = 0; bas[NPRIM_OF + BAS_SLOTS * n] = 3; bas[NCTR_OF + BAS_SLOTS * n] = 2; bas[KAPPA_OF + BAS_SLOTS * n] = 1; bas[PTR_EXP + BAS_SLOTS * n] = off; env[off + 0] = 6.; env[off + 1] = 2.; env[off + 2] = .8; off += 3; bas[PTR_COEFF+ BAS_SLOTS * n] = off; env[off + 0] = .7 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+0]); env[off + 1] = .6 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+1]); env[off + 2] = .5 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+2]); env[off + 3] = .4 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+0]); env[off + 4] = .3 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+1]); env[off + 5] = .2 * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]+2]); off += 6; n++; /* basis #1 with kappa = 0 => p_1/2, p_3/2 */ bas[ATOM_OF + BAS_SLOTS * n] = 0; bas[ANG_OF + BAS_SLOTS * n] = 1; bas[NPRIM_OF + BAS_SLOTS * n] = 1; bas[NCTR_OF + BAS_SLOTS * n] = 1; bas[KAPPA_OF + BAS_SLOTS * n] = 0; bas[PTR_EXP + BAS_SLOTS * n] = off; env[off + 0] = .9; off += 1; bas[PTR_COEFF+ BAS_SLOTS * n] = off; env[off + 0] = 1. * CINTgto_norm(bas[ANG_OF+BAS_SLOTS*n], env[bas[PTR_EXP+BAS_SLOTS*n]]); off += 1; n++; /* basis #2 == basis #0 */ bas[ATOM_OF + BAS_SLOTS * n] = 1; bas[ANG_OF + BAS_SLOTS * n] = bas[ANG_OF + BAS_SLOTS * 0]; bas[NPRIM_OF + BAS_SLOTS * n] = bas[NPRIM_OF + BAS_SLOTS * 0]; bas[NCTR_OF + BAS_SLOTS * n] = bas[NCTR_OF + BAS_SLOTS * 0]; bas[KAPPA_OF + BAS_SLOTS * n] = bas[KAPPA_OF + BAS_SLOTS * 0]; bas[PTR_EXP + BAS_SLOTS * n] = bas[PTR_EXP + BAS_SLOTS * 0]; bas[PTR_COEFF+ BAS_SLOTS * n] = bas[PTR_COEFF+ BAS_SLOTS * 0]; n++; /* basis #3 == basis #1 */ bas[ATOM_OF + BAS_SLOTS * n] = 1; bas[ANG_OF + BAS_SLOTS * n] = bas[ANG_OF + BAS_SLOTS * 1]; bas[NPRIM_OF + BAS_SLOTS * n] = bas[NPRIM_OF + BAS_SLOTS * 1]; bas[NCTR_OF + BAS_SLOTS * n] = bas[NCTR_OF + BAS_SLOTS * 1]; bas[KAPPA_OF + BAS_SLOTS * n] = bas[KAPPA_OF + BAS_SLOTS * 1]; bas[PTR_EXP + BAS_SLOTS * n] = bas[PTR_EXP + BAS_SLOTS * 1]; bas[PTR_COEFF+ BAS_SLOTS * n] = bas[PTR_COEFF+ BAS_SLOTS * 1]; n++; /* * call one-electron spinor integrals */ int j, k, l; int di, dj, dk, dl; int shls[4]; double complex *buf; i = 0; shls[0] = i; di = CINTcgto_spinor(i, bas); j = 1; shls[1] = j; dj = CINTcgto_spinor(j, bas); buf = malloc(sizeof(double complex) * di * dj); if (0 != cint1e_spnucsp(buf, shls, atm, natm, bas, nbas, env)) { printf("This integral is not 0.\n"); } else { printf("This integral is 0.\n"); } free(buf); /* * call two-electron spinor integrals */ i = 0; shls[0] = i; di = CINTcgto_spinor(i, bas); j = 1; shls[1] = j; dj = CINTcgto_spinor(j, bas); k = 2; shls[2] = k; dk = CINTcgto_spinor(k, bas); l = 2; shls[3] = l; dl = CINTcgto_spinor(l, bas); buf = malloc(sizeof(double complex) * di * dj * dk * dl); if (0 != cint2e_spsp1(buf, shls, atm, natm, bas, nbas, env, NULL)) { printf("This integral is not 0.\n"); } else { printf("This integral is 0.\n"); } free(buf); CINTOpt *opt = NULL; cint2e_spsp1_optimizer(&opt, atm, natm, bas, nbas, env); i = 0; shls[0] = i; di = CINTcgto_spinor(i, bas); j = 1; shls[1] = j; dj = CINTcgto_spinor(j, bas); k = 2; shls[2] = k; dk = CINTcgto_spinor(k, bas); l = 2; shls[3] = l; dl = CINTcgto_spinor(l, bas); buf = malloc(sizeof(double complex) * di * dj * dk * dl); if (0 != cint2e_spsp1(buf, shls, atm, natm, bas, nbas, env, opt)) { printf("This integral is not 0.\n"); } else { printf("This integral is 0.\n"); } free(buf); CINTdel_optimizer(&opt); free(atm); free(bas); free(env); }