1
subroutine mp2_nonsep_uhf( rtdb, geom,
5
$ noa, nva, nva_lo, nva_hi, num_va, num_oa,
6
$ nob, nvb, nvb_lo, nvb_hi, num_vb, num_ob,
7
$ sym_lo_oa, sym_hi_oa, sym_lo_va, sym_hi_va,
8
$ sym_lo_ob, sym_hi_ob, sym_lo_vb, sym_hi_vb,
11
$ c_a, c_b, ! Better left in a GA to conserve memory
12
$ nva_lo_local, nva_hi_local,
13
$ tunita, tunitb, grad,
16
* $Id: mp2_back_transform.F 21424 2011-11-07 19:21:05Z edo $
20
#include "mafdecls.fh"
28
integer basis, rtdb, geom
30
integer nbf ! No. of basis functions
31
integer nir ! No. of irreducible representations
32
integer noa, nob ! No. of occupied orbitals
33
integer nva, nva_lo, nva_hi ! Number and ranges of virtual orbitals
34
integer nvb, nvb_lo, nvb_hi
35
integer num_va(0:nir-1), num_vb(0:nir-1) ! No. of vir of each symmetry
36
integer num_oa(0:nir-1), num_ob(0:nir-1) ! No. of occ of each symmetry
37
integer sym_lo_oa(0:nir-1), sym_hi_oa(0:nir-1),
38
$ sym_lo_va(0:nir-1), sym_hi_va(0:nir-1) ! Ranges of each symmetry
39
integer sym_lo_ob(0:nir-1), sym_hi_ob(0:nir-1),
40
$ sym_lo_vb(0:nir-1), sym_hi_vb(0:nir-1)
41
integer oseg_lo, oseg_hi ! Range of occupied for this pass
42
integer irs_a(nbf), irs_b(nbf) ! Orbital symmetries
43
double precision c_a(nbf,*), c_b(nbf,*) ! MO coefficients
44
integer nva_lo_local, nva_hi_local ! Range of virtuals on this node
45
integer tunita, tunitb ! Unit no.s for pure and mixed spin T
46
double precision grad(3,*)
48
c Allocate memory for back transformation routine
51
integer nshpair, nshpairlocal, nbfpair, nbfpairlocal
52
integer l_shpairs, k_shpairs, l_shpairslocal, k_shpairslocal
53
integer l_shdim, k_shdim, l_shlo, k_shlo
54
integer l_t, k_t, l_tmp, k_tmp, l_iauv, k_iauv, l_map, k_map
56
integer l_act, k_act, l_actsh, k_actsh
58
integer junk, ninseg, ierr, i, j, ish, ishlo, ishhi, shmax, tdim
59
integer nsh, natoms, nactive, nblock
61
integer k_scr, l_scr, k_lab, l_lab, k_eri, l_eri, leneri, lenscr
62
integer k_bftosh, l_bftosh, k_bftoce, l_bftoce, k_pdm, l_pdm
63
integer eaftype,eaf_size_in_mb,inntsize
64
double precision p_file_size
66
character*(nw_max_path_len) fname
68
double precision tol2e
69
inntsize=MA_sizeof(MT_INT,1,MT_BYTE)
71
if (.not. rtdb_get(rtdb, 'mp2:backtol', mt_dbl, 1, tol2e))
74
if (.not. bas_numcont(basis, nsh)) call errquit
75
$ ('mp2: backt bad basis handle ', basis, BASIS_ERR)
76
ninseg = oseg_hi - oseg_lo + 1
78
c Make mapping of shell pairs to processors
80
call int_init(rtdb,1,basis) ! intd_init overwrite mem estimates
81
call schwarz_init(geom,basis)
84
call mp2_backt_info(basis, tol2e, oskel,
85
$ .false., nshpair, nshpairlocal,
86
$ nbfpair, nbfpairlocal, shmax, junk, junk, junk, junk, junk)
87
if (.not. ma_push_get(mt_int, nshpair*2, 'mp2: shpairs',
88
$ l_shpairs, k_shpairs)) call errquit
89
$ ('mp2: insufficient memory : shpairs ', 2*nshpair, MA_ERR)
90
if (.not. ma_push_get(mt_int, nshpairlocal*2, 'mp2:shpairslocal',
91
$ l_shpairslocal, k_shpairslocal)) call errquit
92
$ ('mp2: insufficient memory : shpairs ', 2*nshpairlocal,
94
if (.not. ma_push_get(mt_int, ga_nnodes(), 'mp2:map',
95
$ l_map, k_map)) call errquit
96
$ ('mp2: insufficient memory : map ', ga_nnodes(), MA_ERR)
97
if (.not. ma_push_get(mt_int, nsh, 'mp2:shlo',
98
$ l_shlo, k_shlo)) call errquit
99
$ ('mp2: insufficient memory : shlo ', nsh, MA_ERR)
100
if (.not. ma_push_get(mt_int, nsh, 'mp2:shdim',
101
$ l_shdim, k_shdim)) call errquit
102
$ ('mp2: insufficient memory : shdim ', nsh, MA_ERR)
103
call mp2_backt_info(basis, tol2e, oskel,
104
$ .true., nshpair, nshpairlocal,
105
$ nbfpair, nbfpairlocal, shmax,
106
$ int_mb(k_shdim), int_mb(k_shlo),
107
$ int_mb(k_shpairs), int_mb(k_shpairslocal), int_mb(k_map))
109
c Allocate remaining memory and open file to hold the
110
c 3-parts transformed density matrix.
112
tdim = max(nbf*nbf, nbf*shmax*shmax)
114
if (.not. ma_push_get(mt_dbl, tdim, 'mp2: backt t',
115
$ l_t, k_t)) call errquit
116
$ ('mp2: insufficient memory : t ', tdim, MA_ERR)
117
if (.not. ma_push_get(mt_dbl, tdim, 'mp2: backt tmp',
118
$ l_tmp, k_tmp)) call errquit
119
$ ('mp2: insufficient memory : tmp ', tdim, MA_ERR)
120
if (.not. ma_push_get(mt_dbl, nbf*nbf, 'mp2: backt iauv',
121
$ l_iauv, k_iauv)) call errquit
122
$ ('mp2: insufficient memory : iauv ', nbf*nbf, MA_ERR)
124
c Right now we have an N**3 array in GA. This is easily
125
c replaced with an N*B array with B=P*S*S (P procs, S=max shell size)
126
c by blocking the transformation.
128
c For small problems some nodes may not have data in which case
129
c map(proc) will be set to a value larger then nbfpair (which is the
130
c actual maximum dimension) ... discard these before creating
134
do i = 1, ga_nnodes()
135
if (int_mb(k_map+i-1) .le. nbfpair) nblock = nblock + 1
138
if (.not. ga_create_irreg(mt_dbl, nva, nbfpair,
139
$ 'mp2: backt', 1, 1, int_mb(k_map), nblock, g_buf))
140
$ call errquit('mp2: backt: ga_create failed', nva*nbfpair,
143
call util_file_name('2pdm', .true., .true., fname)
145
if (.not. rtdb_get(rtdb, 'mp2:eaf_size_in_mb',
146
$ MT_INT, 1, eaf_size_in_mb)) eaf_size_in_mb = 0
147
if(eaf_size_in_mb.ne.0) then
148
eaftype=1000000+eaf_size_in_mb*1024*1024
150
eaftype=1000000+inntsize*p_file_size*11/10
152
if(ga_nodeid().eq.0) then
153
write(6,*)' EAF nonsep ',
154
A eaf_size_in_mb, eaftype
160
if (eaf_open(fname,eaftype,twopdmunit) .ne. 0)
161
$ call errquit('mp2: backt: failed to open file',0, DISK_ERR)
163
c Now do the back transformation
166
call pstat_on(ps_backt)
167
call mp2_back_transform_uhf(
170
$ nva, nva_lo, nva_hi, num_va, num_oa,
171
$ nvb, nvb_lo, nvb_hi, num_vb, num_ob,
172
$ sym_lo_oa, sym_hi_oa, sym_lo_va, sym_hi_va,
173
$ sym_lo_ob, sym_hi_ob, sym_lo_vb, sym_hi_vb,
177
$ nva_lo_local, nva_hi_local,
178
$ tunita, tunitb, twopdmunit,
179
$ nshpair, nbfpair, int_mb(k_shpairs),
180
$ nshpairlocal, nbfpairlocal, int_mb(k_shpairslocal),
181
$ int_mb(k_shdim), int_mb(k_shlo),
182
$ dbl_mb(k_t), dbl_mb(k_iauv), dbl_mb(k_tmp),
183
$ int_mb(k_map), g_buf)
184
call pstat_off(ps_backt)
187
c Free up some memory and then contract with gradient integrals.
189
if (.not. ga_destroy(g_buf)) call errquit
190
$ ('mp2: backt: ga destroy failed', 0, GA_ERR)
191
if (.not. ma_chop_stack(l_t)) call errquit
192
$ ('mp2:backt: first chop stack failed', 0, MA_ERR)
194
tdim = shmax*shmax*nbf*ninseg
195
if (.not. ma_push_get(mt_dbl, tdim, 'mp2:back tt',
196
$ l_t, k_t)) call errquit
197
$ ('mp2: backt: failed ma for nonsep test', tdim, MA_ERR)
198
tdim = shmax*shmax*nbf
199
if (.not. ma_push_get(mt_dbl, tdim*ninseg, 'mp2:back tbuf',
200
$ l_tmp, k_tmp)) call errquit
201
$ ('mp2: backt: failed ma for nonsep test', tdim, MA_ERR)
202
if (.not. ma_push_get(mt_dbl, ninseg*nbf, 'mp2:back c_t',
203
$ l_c_t, k_c_t)) call errquit
204
$ ('mp2: backt: failed ma for nonsep test', ninseg*nbf, MA_ERR)
205
do i = oseg_lo, oseg_hi
206
call dcopy(nbf, c_a(1,i), 1, dbl_mb(k_c_t+i-oseg_lo), ninseg)
209
c Determine list of active centers
211
if (.not. geom_ncent(geom, natoms)) call errquit
212
$ ('mp2_backt: geom ?',0, GEOM_ERR)
213
if (.not. ma_push_get(mt_log, natoms, 'mp2:back act',
214
$ l_act, k_act)) call errquit('mp2:back ma ', natoms, MA_ERR)
215
call grad_active_atoms(rtdb, natoms, log_mb(k_act), nactive)
217
c Turn this into a list of active shells
219
if (.not. ma_push_get(mt_log, nsh, 'mp2:back actsh',
220
$ l_actsh, k_actsh)) call errquit('mp2:back ma ', nsh, MA_ERR)
222
if (.not. bas_ce2cnr(basis, i, ishlo, ishhi))
223
$ call errquit('mp2:backt basis?',0, BASIS_ERR)
225
log_mb(k_actsh+ish-1) = log_mb(k_act+i-1)
229
call intd_init(rtdb, 1, basis)
230
call intb_mem_2e4c(leneri, lenscr) ! blocking algorithm
232
leneri = max(leneri,15**4) ! 1 G quartet = 39 D quartets ... SEE MP2_MEMORY
233
if (.not. ma_push_get(mt_dbl,12*leneri,'deriv buffer',
234
$ l_eri,k_eri)) call errquit
235
$ ('mp2:backt could not allocate buffer',12*leneri, MA_ERR)
236
if (.not. ma_push_get(mt_dbl,shmax**4,'pdm buffer',
237
$ l_pdm,k_pdm)) call errquit
238
$ ('mp2:backt could not allocate pdm',shmax*4, MA_ERR)
239
if (.not. ma_push_get(mt_int,4*leneri,'deriv labels',l_lab,k_lab))
240
$ call errquit('mp2:backt could not allocate labels',leneri,
242
if (.not. ma_push_get(mt_dbl,lenscr,'deriv scratch',
244
$ call errquit('mp2:backt could not allocate scr',lenscr,
246
if (.not. ma_push_get(mt_int,nbf,'shmap',l_bftosh,k_bftosh))
247
$ call errquit('mp2:backt could not allocate bftosh',nbf,
249
if (.not. ma_push_get(mt_int,nbf,'cemap',l_bftoce,k_bftoce))
250
$ call errquit('mp2:backt could not allocate bftoce',nbf,
254
call pstat_on(ps_nonsep)
255
call mp2_nonsep(rtdb, basis,
259
$ nshpairlocal, int_mb(k_shpairslocal),
260
$ int_mb(k_shdim), int_mb(k_shlo),
261
$ dbl_mb(k_t), dbl_mb(k_tmp), grad,
263
$ log_mb(k_actsh), leneri, dbl_mb(k_eri), int_mb(k_lab),
264
$ lenscr, dbl_mb(k_scr), int_mb(k_bftosh), int_mb(k_bftoce),
266
call pstat_off(ps_nonsep)
268
call intd_terminate()
270
c Zero out gradients on inactive atoms
273
if (.not. log_mb(k_act+i-1)) then
284
if (.not. ma_chop_stack(l_shpairs)) call errquit
285
$ ('mp2: backt: failed chopping stack',0, MA_ERR)
287
if (util_print('iostats', print_high) .and.
288
$ ga_nodeid().eq.0) call eaf_print_stats(twopdmunit)
289
if (eaf_close(twopdmunit) .ne. 0)
290
$ call errquit('mp2: backt: closing 2pdm',ierr, DISK_ERR)
291
call util_file_unlink(fname)
294
subroutine mp2_back_transform_uhf(
297
$ nva, nva_lo, nva_hi, num_va, num_oa,
298
$ nvb, nvb_lo, nvb_hi, num_vb, num_ob,
299
$ sym_lo_oa, sym_hi_oa, sym_lo_va, sym_hi_va,
300
$ sym_lo_ob, sym_hi_ob, sym_lo_vb, sym_hi_vb,
304
$ nva_lo_local, nva_hi_local,
305
$ tunita, tunitb, twopdmunit,
306
$ nshpair, nbfpair, shpairs,
307
$ nshpairlocal, nbfpairlocal, shpairslocal,
312
#include "errquit.fh"
314
#include "mafdecls.fh"
317
integer nbf ! No. of basis functions
318
integer nir ! No. of irreducible representations
319
integer nva, nva_lo, nva_hi ! Number and ranges of virtual orbitals
320
integer nvb, nvb_lo, nvb_hi
321
integer num_va(0:nir-1), num_vb(0:nir-1) ! No. of vir of each symmetry
322
integer num_oa(0:nir-1), num_ob(0:nir-1) ! No. of occ of each symmetry
323
integer sym_lo_oa(0:nir-1), sym_hi_oa(0:nir-1),
324
$ sym_lo_va(0:nir-1), sym_hi_va(0:nir-1) ! Ranges of each symmetry
325
integer sym_lo_ob(0:nir-1), sym_hi_ob(0:nir-1),
326
$ sym_lo_vb(0:nir-1), sym_hi_vb(0:nir-1)
327
integer oseg_lo, oseg_hi ! Range of occupied for this pass
328
integer irs_a(nbf), irs_b(nbf) ! Orbital symmetries
329
double precision c_a(nbf,*), c_b(nbf,*) ! MO coefficients
330
integer nva_lo_local, nva_hi_local ! Range of virtuals on this node
331
integer tunita, tunitb ! Unit no.s for pure and mixed spin T
332
integer nshpair ! total no. of non-zero shell pairs
333
integer nshpairlocal ! no. of pairs assigned to this processor
334
integer nbfpair ! dimension of bf pairs
335
integer nbfpairlocal ! dimension of local bf pairs
336
integer shpairs(2,nshpair) ! (u>=v) shell pair indices
337
integer shpairslocal(2,*) ! local shell pair indices
338
integer shdim(*) ! no. of bf in shell
339
integer shlo(*) ! first bf in shell
340
double precision t(*) ! Scratch max(nbf*nbf,nbf*S*S)
341
double precision tmp(*) ! Scratch max(nbf*nbf,nbf*S*S)
342
double precision ia_uv(nbf,nbf) ! Scratch
343
integer twopdmunit ! Unit no. for part transformed two-PDM
344
integer map(0:*) ! First index of g_buf on each node
345
integer g_buf ! Global array handle for transpose buffer
347
* double precision tsum
349
double precision zero, one, scale
350
double precision tunitptra, tunitptrb ! Pointers into files
351
double precision twopdmunitptr
352
integer count, tcount, ind, ptr
353
integer symi, symj, syma, symb, symia
354
integer i, a, u, v, ush, vsh, udim, vdim, ishpair
366
call ga_fill_patch(g_buf,1,nva,1,nbfpair,99.0d0) ! For debug
368
do a=nva_lo_local,nva_hi_local
370
symia=ieor(syma,symi)
371
call dfill((nbf*nbf),zero,ia_uv,1) ! Will add pure and mixed in
373
call mp2_read_tijab(nva_lo, nva_hi, irs_a, symia,
374
$ num_oa, sym_hi_oa, sym_lo_oa, tunita, tunitptra, t)
378
symj=ieor(symia,symb)
379
if(num_va(symb).gt.0.and.num_oa(symj).gt.0) then
380
call dgemm('n','t', ! t(j,b)Cbv -> t(j,v)
381
$ num_oa(symj), nbf, num_va(symb),
382
$ one, t(tcount), num_oa(symj),
383
$ c_a(1,sym_lo_va(symb)), nbf,
384
$ zero, tmp, num_oa(symj))
385
call dgemm('n','n', ! Cuj t(j,v) -> t(u,v)
386
$ nbf, nbf, num_oa(symj),
387
$ one, c_a(1,sym_lo_oa(symj)), nbf,
390
tcount=tcount+num_oa(symj)*num_va(symb)
394
call mp2_read_tijab(nvb_lo, nvb_hi, irs_b, symia,
395
$ num_ob, sym_hi_ob, sym_lo_ob, tunitb, tunitptrb, t)
399
symj=ieor(symia,symb)
400
if(num_vb(symb).gt.0.and.num_ob(symj).gt.0) then
401
call dgemm('n','t', ! t(j,b)Cbv -> t(j,v)
402
$ num_ob(symj), nbf, num_vb(symb),
403
$ one, t(tcount), num_ob(symj),
404
$ c_b(1,sym_lo_vb(symb)), nbf,
405
$ zero, tmp, num_ob(symj))
406
call dgemm('n','n', ! Cuj t(j,v) -> t(u,v)
407
$ nbf, nbf, num_ob(symj),
408
$ one, c_b(1,sym_lo_ob(symj)), nbf,
411
tcount=tcount+num_ob(symj)*num_vb(symb)
415
c Pack down into sparse, symmetry unique list and symmetrize over uv
416
c Note we put in the whole square of diagonal shell blocks and divide
420
do ishpair = 1, nshpair
421
ush = shpairs(1,ishpair)
422
vsh = shpairs(2,ishpair)
424
if (ush.eq.vsh) scale = 0.5d0
425
do u = shlo(ush), shlo(ush)+shdim(ush)-1
426
do v = shlo(vsh), shlo(vsh)+shdim(vsh)-1
428
tmp(ind) = (ia_uv(u,v)+ia_uv(v,u))*scale
432
if (ind .ne. nbfpair) call errquit('mp2bt: ind?', ind,
435
c shpairs(1:2,1:nshpair) (u>=v) shell pair indices
436
c shdim(1:nsh) dimension of this sh (s=1,p=2,...)
437
c shlo(1:nsh) first basis function in shell
438
c nbfpair total no. of non-zero bf pairs
439
c nshpair total no. of non-zero shell pairs
440
c nshpairlocal no. of shellpairs assigned to this processor
441
c nbfpairlocal no. of bfpairs assigned to this processor
442
c shpairslocal(1:2,1:nshpairlocal) (u>=v) local shell pair indices
444
call ga_put(g_buf, a-nva_lo+1, a-nva_lo+1,
445
$ 1, nbfpair, tmp, 1)
450
c Now have locally (a,1:nbfpairlocal). Loop thru local shell pairs
451
c transform the a index and write to disk.
453
ind = map(ga_nodeid())
455
do ishpair = 1, nshpairlocal
456
ush = shpairslocal(1,ishpair)
457
vsh = shpairslocal(2,ishpair)
461
call ga_get(g_buf,1,nva,ind,ind+udim*vdim-1,tmp,nva)
462
ind = ind + udim*vdim
463
call dgemm('n','n', ! C(s,a)*F(a,uv) -> F(s,uv)
464
$ nbf, udim*vdim, nva,
465
$ one, c_a(1,nva_lo), nbf,
469
c On disk is D(1:nbf,1:vdim(v),1:udim(u),oseg_lo:oseg_hi,1:nshpairlocal)
470
c with indices D(s,vf,uf,i,ishpair)
472
c Note - this presumes that the routine reading the data back in will
473
c be using an algorithm with o*n*s*s memory requirement (n=#bf, s=#bf
474
c in shell, o=occupied).
476
count = nbf*udim*vdim ! Amount of data to write
477
twopdmunitptr = 8.0d0*(ptr + (i-oseg_lo)*count)
479
if (eaf_write(twopdmunit, twopdmunitptr, t, count*8).ne.0)
480
$ call errquit('mp2_bt: write of two pdm?', 0,
483
ptr = ptr + count*(oseg_hi-oseg_lo+1)
491
subroutine mp2_backt_info(
495
$ nshpair, nshpairlocal,
496
$ nbfpair, nbfpairlocal, shmax,
497
$ shdim, shlo, shpairs, shpairslocal, map)
499
#include "errquit.fh"
501
#include "schwarz.fh"
505
integer basis ! [input] basis set handle
506
double precision tol2e ! [input] screening threshold
507
logical oskel ! [input] if true use skeleton symm
508
logical omakearrays ! [input] if true then make the arrays
509
integer nshpair ! [output] no. of non-zero shell pairs
510
integer nshpairlocal ! [output] no. of local shell pairs
511
integer shmax ! [output] Max AO shell dimension
512
integer nbfpair ! [output] sum of all non-zero pair dims
513
integer nbfpairlocal ! [output] sum of local non-zero pair dims
514
integer shdim(*) ! [output] dimension of each shell
515
integer shlo(*) ! [output] first bf in each shell
516
integer shpairs(2,*) ! [output] 1->u, 2->v u>=v shells in pair
517
integer shpairslocal(2,*) ! [output] ditto but only for local pairs
518
integer map(0:*) ! [output] Map for g_create_irreg for g_buf
520
c Form a list of interacting shell pairs (u>=v) and assign them
521
c to processors. Ideally do this so as to optimize the efficiency
522
c of derivative integral evaluation and to provide good load balance
523
c for the back transformation. Right now we just do round-robin.
525
c If (omakearrays) then
526
c actually make the arrays
528
c just return the scalar results
531
c The Schwarz package must be initialized before entry
533
integer u, v, nbf, nsh, lo, hi, udim, vdim, me, nproc, owner
534
integer count, tmp, ishpair, first, last, iproc, uvdim
536
double precision q2, sss
538
integer npairblock ! Crude attempt to load balance the pairs
539
parameter (npairblock = 7)
540
integer pairblock(npairblock), ipairb, npairmin, npairmax
541
integer logmin, logmax
543
data pairblock /1,3,6,9,18,36,1000000/ ! Selected from s*s,s*p,p*p ...
545
if (.not. bas_numbf(basis, nbf))
546
$ call errquit('mp2_backt_info: bad basis handle', 0,
548
if (.not. bas_numcont(basis, nsh))
549
$ call errquit('mp2_backt_info: bad basis handle', 0,
556
if (omakearrays) then
558
c First compute offset to first shell pair on each processor
561
call ifill(nproc, 0, map, 1)
563
do logmin = -1,-13,-4 ! NOTE THAT SCREENING IS IMPLIED IN THIS LOOP
565
do ipairb = 1, npairblock ! Loop thru types of pairs
566
npairmax = pairblock(ipairb)
568
if (.not. bas_cn2bfr(basis, u, lo, hi))
569
$ call errquit('mp2_backt_info: bas range', u,
573
if (.not. bas_cn2bfr(basis, v, lo, hi))
574
$ call errquit('mp2_backt_info:bas range',v,
578
sss = schwarz_shell(u,v)*schwarz_max() + 1d-100
579
if (uvdim.gt.npairmin .and. uvdim.le.npairmax .and.
580
$ log10(sss).lt.logmax .and.
581
$ log10(sss).ge.logmin) then
583
odoit = sss .gt. tol2e*0.1d0
584
if (odoit .and. oskel)
585
$ odoit = sym_shell_pair(basis,u,v,q2)
587
owner = mod(nshpair,nproc)
588
map(owner) = map(owner) + 1
589
nshpair = nshpair + 1
607
c Make list of all shell pairs ordered by their assigned processor,
608
c the list of local shell pairs, and also count the other information.
615
do logmin = -1,-13,-4 ! NOTE THAT SCREENING IS IMPLIED IN THIS LOOP
617
do ipairb = 1, npairblock ! Loop thru types of pairs
618
npairmax = pairblock(ipairb)
620
if (.not. bas_cn2bfr(basis, u, lo, hi))
621
$ call errquit('mp2_backt_info: bas range', u,
623
shmax = max(shmax,hi-lo+1)
624
if (omakearrays) then
625
shdim(u) = hi - lo + 1
630
if (.not. bas_cn2bfr(basis, v, lo, hi))
631
$ call errquit('mp2_backt_info: bas range', v,
635
sss = schwarz_shell(u,v)*schwarz_max() + 1d-100
636
if (uvdim.gt.npairmin .and. uvdim.le.npairmax .and.
637
$ log10(sss).lt.logmax .and.
638
$ log10(sss).ge.logmin) then
640
odoit = sss.gt.tol2e*0.1d0
641
if (odoit .and. oskel)
642
$ odoit = sym_shell_pair(basis,u,v,q2)
644
owner = mod(nshpair,nproc)
645
if (owner.eq.me) then
646
nshpairlocal = nshpairlocal + 1
647
nbfpairlocal = nbfpairlocal + udim*vdim
648
if (omakearrays) then
649
shpairslocal(1,nshpairlocal) = u
650
shpairslocal(2,nshpairlocal) = v
653
nshpair = nshpair + 1
654
nbfpair = nbfpair + udim*vdim
655
if (omakearrays) then
656
shpairs(1,map(owner)) = u
657
shpairs(2,map(owner)) = v
658
map(owner) = map(owner) + 1
669
c Now replace map with the map creating the global array for transposing
671
if (omakearrays) then
674
do iproc = 0, nproc-1
675
last = map(iproc) - 1
677
do ishpair = first, last
678
u = shpairs(1,ishpair)
679
v = shpairs(2,ishpair)
680
count = count + shdim(u)*shdim(v)
686
if (util_print('mp2_backt', print_debug)) then
687
write(6,*) me, ' nshpair ', nshpair
688
write(6,*) me, ' nshpairlocal ', nshpairlocal
689
write(6,*) me, ' nbfpair ', nbfpair
690
write(6,*) me, ' nbfpairlocal ', nbfpairlocal
691
if (omakearrays) then
693
write(6,*) me, ' u shlo shdim ', u, shlo(u), shdim(u)
695
do u = 1, nshpairlocal
696
write(6,*) me, ' pair shpairslocal ', u,
697
$ shpairslocal(1,u), shpairslocal(2,u)
700
write(6,*) me, ' proc map ', u, map(u)
706
subroutine mp2_nonsep(
712
$ nshpairlocal, shpairslocal, shdim, shlo,
714
$ tol2e, oskel, oactive, leneri, eri, labels, lenscr,
715
$ scratch, shmap, cemap, pdm)
717
#include "errquit.fh"
718
#include "schwarz.fh"
719
#include "mafdecls.fh"
729
integer rtdb ! [input]
730
integer basis ! [input]
731
integer twopdmunit ! [input]
732
integer nsh, nbf, ninseg ! [input]
733
double precision c_t(ninseg,nbf) ! [input] Transposed MOs in segment
734
integer nshpairlocal, shpairslocal(2,*), shdim(nsh), shlo(nsh) ! [input]
735
double precision t(*) ! [scratch] ninseg*nbf*S*S
736
double precision tbuf(*) ! [scratch] nbf*S*S
737
double precision grad(3,*) ! [input/output]
738
double precision tol2e ! [input]
739
logical oskel ! [input]
740
logical oactive(*) ! [input] oactive(ish)=true if shell is active
741
integer leneri, lenscr ! [input]
742
integer labels(leneri,4), nq, nint ! [scratch]
743
double precision eri(3,4,leneri), scratch(lenscr) ! [scratch]
744
integer shmap(*), cemap(*) ! [scratch]
745
double precision pdm(*) ! [scratch]
747
double precision fileptr, energy, scale, psum, q4, block_eff
748
integer i, count, ishpair
749
integer ush, vsh, xsh, ysh, u, v, x, y
750
integer udim, vdim, xdim, ydim, xlo, ylo
751
integer ush_cur, vsh_cur, xsh_cur, ysh_cur
752
integer ush_prev, vsh_prev, xsh_prev, ysh_prev
753
integer xcent, ycent, ucent, vcent, ijkl, xsh_start, ysh_start
757
parameter (maxq=10000)
758
integer sh_list(maxq,4)
759
double precision q4_list(maxq)
761
logical intbd_init4c, intbd_2e4c
762
external intbd_init4c, intbd_2e4c
765
$ ulo_cur, uhi_cur, vlo_cur, vhi_cur, xlo_cur, xhi_cur,
766
$ ylo_cur, yhi_cur, udim_cur, vdim_cur, xdim_cur, ydim_cur
767
logical status, odebug, odoit, sym_shell_quartet, oenergy
768
external sym_shell_quartet
770
odebug = util_print('mp2_backt', print_debug)
771
oenergy = util_print('backtenergy', print_debug)
775
status = bas_geom ( basis, geom )
776
status = geom_ncent ( geom, nat )
779
if (.not. bas_bf2ce(basis,u,ucent))
780
$ call errquit('mp2g: bad something?',0, BASIS_ERR)
781
if (.not. bas_bf2cn(basis,u,ush))
782
$ call errquit('mp2g: bad something?',0, BASIS_ERR)
788
write(6,*) ' Transposed occupied MOS in segment '
789
call output(c_t, 1, ninseg, 1, nbf, ninseg, nbf, 1)
793
do ishpair = 1, nshpairlocal
794
ush = shpairslocal(1,ishpair)
795
vsh = shpairslocal(2,ishpair)
798
count = nbf*udim*vdim
800
c Part transformed density is stored as
801
c t(1:nbf,1:vdim,1:udim,1:ninseg,1:nshpairlocal) ->
804
c Read this in and transpose to in core structure t(i,x,v,u)
806
if (eaf_read(twopdmunit, fileptr, tbuf, ninseg*count*8).ne.0)
807
$ call errquit('mp2: ao test: failed reading density', 0,
810
call dcopy(count, tbuf(count*(i-1)+1), 1, t(i), ninseg)
812
fileptr = fileptr + ninseg*count*8.0d0
814
xsh_start = 1 ! For braindead multipassing
818
do xsh = xsh_start, nsh
819
do ysh = ysh_start, xsh
820
odoit = schwarz_shell(xsh,ysh)*schwarz_shell(ush,vsh)
823
$ (oactive(ush).or.oactive(vsh).or.
824
$ oactive(xsh).or.oactive(ysh))
826
if (odoit .and. oskel) odoit =
827
$ sym_shell_quartet(basis, ush, vsh, xsh, ysh, q4)
833
if (xsh .eq. ysh) scale = scale*0.5d0
839
call mp2_make_two_particle_density(psum,
840
$ udim, vdim, xdim, ydim, xlo, ylo,
842
$ scale, c_t, t, pdm)
844
c use density to screen evaluation of gradient integrals
846
call int_2e4c(basis, ush, vsh, basis, xsh, ysh,
847
$ lenscr, scratch, leneri, eri)
849
$ ddot(udim*vdim*xdim*ydim,eri,1,pdm,1)
852
if (schwarz_shell(xsh,ysh)*schwarz_shell(ush,vsh)*psum
861
if (nq .eq. maxq) goto 666 ! UGLY
862
endif ! schwarz and density
873
if (.not. intbd_init4c(
874
$ basis, sh_list(1,1), sh_list(1,2),
875
$ basis, sh_list(1,3), sh_list(1,4),
876
$ nq, q4_list, .true., lenscr, scratch, leneri,
877
$ block_eff)) call errquit('mp2:backt: txs init?',nq,
880
1000 omore = intbd_2e4c(
881
$ basis, sh_list(1,1), sh_list(1,2),
882
$ basis, sh_list(1,3), sh_list(1,4),
883
$ nq, q4_list, .true., tol2e, .false.,
884
$ labels(1,1),labels(1,2),
885
$ labels(1,3), labels(1,4),
886
$ eri, leneri, nint, lenscr, scratch)
888
if (nint .gt. leneri) call errquit('mp2_nonsep: nint', nint,
905
if ( ush_cur.ne.ush_prev .or.
906
$ vsh_cur.ne.vsh_prev .or.
907
$ xsh_cur.ne.xsh_prev .or.
908
$ ysh_cur.ne.ysh_prev ) then
915
ulo_cur = shlo(ush_cur)
916
vlo_cur = shlo(vsh_cur)
917
xlo_cur = shlo(xsh_cur)
918
ylo_cur = shlo(ysh_cur)
920
udim_cur = shdim(ush_cur)
921
vdim_cur = shdim(vsh_cur)
922
xdim_cur = shdim(xsh_cur)
923
ydim_cur = shdim(ysh_cur)
925
uhi_cur = ulo_cur + udim_cur - 1
926
vhi_cur = vlo_cur + vdim_cur - 1
927
xhi_cur = xlo_cur + xdim_cur - 1
928
yhi_cur = ylo_cur + ydim_cur - 1
935
call mp2_make_two_particle_density( psum,
936
$ udim_cur, vdim_cur, xdim_cur, ydim_cur,
939
$ 1.0d0, c_t, t, pdm)
942
call make_mp2grad(ucent,vcent,xcent,ycent, u,v,x,y,
943
$ ulo_cur, uhi_cur, vlo_cur, vhi_cur,
944
$ xlo_cur, xhi_cur, ylo_cur, yhi_cur,
945
$ pdm, eri(1,1,ijkl), grad )
949
if (omore) goto 1000 ! Texas split the request
951
if (xsh_start .le. nsh) goto 333
956
call ga_dgop(1,energy,1,'+')
957
if (ga_nodeid().eq.0)
958
+ write(LuOut,*) ' The energy from the two PDM is ', energy
962
subroutine mp2_make_two_particle_density(
963
$ psum, udim, vdim, xdim, ydim, xlo, ylo, ninseg, nbf,
964
$ scale, c_t, t, density)
967
double precision psum ! [output] Norm of density
968
integer udim, vdim, xdim, ydim ! [input] Shell dimensions
969
integer xlo, ylo ! [input] Start of shells
970
integer ninseg ! [input] No. of i in the batch
971
integer nbf ! [input]
972
double precision scale ! [input] Q4 and other factors
973
double precision c_t(ninseg,nbf) ! [input] Transposed MO vectors in batch
974
double precision t(ninseg,nbf,vdim,udim) ! [input] Partially transformed amplitudes
975
double precision density(ydim,xdim,vdim,udim) ! [output]
977
integer u, v, x, y, i
987
p = p + t(i,x+xlo-1,v,u)*c_t(i,y+ylo-1)
988
$ + t(i,y+ylo-1,v,u)*c_t(i,x+xlo-1)
1001
subroutine make_mp2grad(ucent,vcent,xcent,ycent, u,v,x,y,
1002
$ ulo, uhi, vlo, vhi, xlo, xhi, ylo, yhi,
1003
$ density, eri, grad )
1005
integer ucent,vcent,xcent,ycent, u,v,x,y
1006
integer ulo, uhi, vlo, vhi, xlo, xhi, ylo, yhi
1008
double precision density(ylo:yhi,xlo:xhi,vlo:vhi,ulo:uhi)
1009
double precision eri(3,4) , grad(3,*)
1017
grad(icart,ucent)=grad(icart,ucent)+
1018
$ density(y,x,v,u)*eri(icart,4)
1019
grad(icart,vcent)=grad(icart,vcent)+
1020
$ density(y,x,v,u)*eri(icart,3)
1021
grad(icart,xcent)=grad(icart,xcent)+
1022
$ density(y,x,v,u)*eri(icart,2)
1023
grad(icart,ycent)=grad(icart,ycent)+
1024
$ density(y,x,v,u)*eri(icart,1)
1028
c--------------------------------------------------