source: ThirdParty/mpqc_open/src/lib/chemistry/qc/mbptr12/r12ia_memgrp.cc

Candidate_v1.6.1
Last change on this file was 860145, checked in by Frederik Heber <heber@…>, 8 years ago

Merge commit '0b990dfaa8c6007a996d030163a25f7f5fc8a7e7' as 'ThirdParty/mpqc_open'

  • Property mode set to 100644
File size: 6.1 KB
Line 
1//
2// r12ia_memgrp.cc
3//
4// Copyright (C) 2002 Edward Valeev
5//
6// Author: Edward Valeev <edward.valeev@chemistry.gatech.edu>
7// Maintainer: EV
8//
9// This file is part of the SC Toolkit.
10//
11// The SC Toolkit is free software; you can redistribute it and/or modify
12// it under the terms of the GNU Library General Public License as published by
13// the Free Software Foundation; either version 2, or (at your option)
14// any later version.
15//
16// The SC Toolkit is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU Library General Public License for more details.
20//
21// You should have received a copy of the GNU Library General Public License
22// along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24//
25// The U.S. Government is granted a limited license as per AL 91-7.
26//
27
28#ifdef __GNUC__
29#pragma implementation
30#endif
31
32#include <stdexcept>
33#include <stdlib.h>
34#include <util/misc/formio.h>
35#include <util/misc/exenv.h>
36#include <chemistry/qc/mbptr12/r12ia_memgrp.h>
37
38using namespace std;
39using namespace sc;
40
41///////////////////////////////////////////////////////////////
42
43static ClassDesc R12IntsAcc_MemoryGrp_cd(
44 typeid(R12IntsAcc_MemoryGrp),"R12IntsAcc_MemoryGrp",1,"public R12IntsAcc",
45 0, 0, create<R12IntsAcc_MemoryGrp>);
46
47R12IntsAcc_MemoryGrp::R12IntsAcc_MemoryGrp(Ref<MemoryGrp>& mem, int num_te_types, int ni, int nj, int nx, int ny) :
48 R12IntsAcc(num_te_types, ni, nj, nx, ny), blksize_memgrp_(blksize_)
49{
50 mem_ = mem;
51
52 init();
53}
54
55R12IntsAcc_MemoryGrp::R12IntsAcc_MemoryGrp(StateIn& si) : R12IntsAcc(si)
56{
57 mem_ = MemoryGrp::get_default_memorygrp();
58 blksize_memgrp_ = blksize_;
59
60 init();
61}
62
63R12IntsAcc_MemoryGrp::~R12IntsAcc_MemoryGrp()
64{
65 for(int i=0;i<ni_;i++)
66 for(int j=0;j<nj_;j++)
67 if (!is_local(i,j)) {
68 int ij = ij_index(i,j);
69 for(int oper_type=0; oper_type<num_te_types(); oper_type++)
70 if (pairblk_[ij].ints_[oper_type] != NULL) {
71 ExEnv::outn() << indent << mem_->me() << ": i = " << i << " j = " << j << " oper_type = " << oper_type << endl;
72 throw std::runtime_error("Logic error: R12IntsAcc_MemoryGrp::~ : some nonlocal blocks have not been released!");
73 }
74 }
75 delete[] pairblk_;
76}
77
78void
79R12IntsAcc_MemoryGrp::save_data_state(StateOut& so)
80{
81 R12IntsAcc::save_data_state(so);
82}
83
84void
85R12IntsAcc_MemoryGrp::init()
86{
87 nproc_ = mem_->n();
88
89 // Now do some extra work to figure layout of data in MemoryGrp
90 // Compute global offsets to each processor's data
91 int i,j,ij;
92 pairblk_ = new struct PairBlkInfo[ni_*nj_];
93 for(i=0,ij=0;i<ni_;i++)
94 for(j=0;j<nj_;j++,ij++) {
95 pairblk_[ij].ints_[eri] = NULL;
96 pairblk_[ij].ints_[r12] = NULL;
97 pairblk_[ij].ints_[r12t1] = NULL;
98 pairblk_[ij].ints_[r12t2] = NULL;
99 pairblk_[ij].refcount_[eri] = 0;
100 pairblk_[ij].refcount_[r12] = 0;
101 pairblk_[ij].refcount_[r12t1] = 0;
102 pairblk_[ij].refcount_[r12t2] = 0;
103 int local_ij_index = ij_index(i,j)/nproc_;
104 pairblk_[ij].offset_ = (distsize_t)local_ij_index*blksize_memgrp_*num_te_types() +
105 mem_->offset(ij_proc(i,j));
106 }
107}
108
109void
110R12IntsAcc_MemoryGrp::store_memorygrp(Ref<MemoryGrp>& mem, int ni, const size_t blksize)
111{
112 if (committed_) {
113 ExEnv::out0() << "R12IntsAcc_MemoryGrp::store_memorygrp(mem,ni) called after all data has been committed" << endl;
114 abort();
115 }
116 // mem must be the same as mem_
117 else if (mem_ != mem) {
118 ExEnv::out0() << "R12IntsAcc_MemoryGrp::store_memorygrp(mem,ni) called with invalid argument:" << endl <<
119 "mem != R12IntsAcc_MemoryGrp::mem_" << endl;
120 abort();
121 }
122 else if (ni != ni_) {
123 ExEnv::out0() << "R12IntsAcc_MemoryGrp::store_memorygrp(mem,ni) called with invalid argument:" << endl <<
124 "ni != R12IntsAcc_MemoryGrp::ni_" << endl;
125 abort();
126 }
127 else {
128 if (blksize != 0 && blksize != blksize_memgrp_) {
129 blksize_memgrp_ = blksize;
130 init();
131 }
132
133 for (int i=0; i<ni_; i++)
134 for (int j=0; j<nj_; j++)
135 if (is_local(i,j)) {
136 int local_ij_index = ij_index(i,j)/nproc_;
137 double *integral_ij_offset = (double *) ((size_t)mem_->localdata() +
138 blksize_memgrp_*num_te_types()*local_ij_index);
139 store_pair_block(i,j,integral_ij_offset);
140 }
141 }
142
143 inc_next_orbital(ni);
144}
145
146void
147R12IntsAcc_MemoryGrp::store_pair_block(int i, int j, double *ints)
148{
149 // For now store blocks local to this node ONLY
150 if (is_local(i,j)) {
151 int ij = ij_index(i,j);
152 pairblk_[ij].ints_[eri] = ints;
153 pairblk_[ij].ints_[r12] = (double*) ((size_t)ints + blksize_memgrp_);
154 pairblk_[ij].ints_[r12t1] = (double*) ((size_t)ints + 2*blksize_memgrp_);
155 pairblk_[ij].ints_[r12t2] = (double*) ((size_t)ints + 3*blksize_memgrp_);;
156 }
157}
158
159void
160R12IntsAcc_MemoryGrp::deactivate()
161{
162 R12IntsAcc::deactivate();
163 mem_->sync();
164 mem_->set_localsize(0);
165 // so that this accumator cannot be activated again
166 committed_ = false;
167}
168
169double *
170R12IntsAcc_MemoryGrp::retrieve_pair_block(int i, int j, tbint_type oper_type)
171{
172 int ij = ij_index(i,j);
173 struct PairBlkInfo *pb = &pairblk_[ij];
174 if (!is_local(i,j) && pb->ints_[oper_type] == 0) {
175 pb->ints_[oper_type] = (double *) mem_->obtain_readonly(pb->offset_ + (distsize_t)oper_type*blksize_memgrp_, blksize_);
176 }
177 pb->refcount_[oper_type] += 1;
178 return pb->ints_[oper_type];
179}
180
181void
182R12IntsAcc_MemoryGrp::release_pair_block(int i, int j, tbint_type oper_type)
183{
184 int ij = ij_index(i,j);
185 struct PairBlkInfo *pb = &pairblk_[ij];
186 if (pb->refcount_[oper_type] <= 0) {
187 ExEnv::outn() << indent << mem_->me() << ":refcount=0: i = " << i << " j = " << j << " tbint_type = " << oper_type << endl;
188 throw std::runtime_error("Logic error: R12IntsAcc_MemoryGrp::release_pair_block: refcount is already zero!");
189 }
190 if (!is_local(i,j) && pb->ints_[oper_type] != NULL && pb->refcount_[oper_type] == 1) {
191 mem_->release_readonly(pb->ints_[oper_type],pb->offset_+ oper_type*blksize_memgrp_,blksize_);
192 pb->ints_[oper_type] = NULL;
193 }
194 pb->refcount_[oper_type] -= 1;
195}
196
197// Local Variables:
198// mode: c++
199// c-file-style: "CLJ"
200// End:
Note: See TracBrowser for help on using the repository browser.