Skip to content

Commit a55cd49

Browse files
committed
Support OPTIMIZED evaluation with pair masks on.
Use OPTIMIZED evaluation when last and current structures can be compared SIDEBYSIDE, i.e., atom indices are not changing. This closes #6.
1 parent 410ef16 commit a55cd49

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

src/diffpy/srreal/PQEvaluator.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ void PQEvaluatorBasic::updateValue(
105105
// split outer loop for many atoms. The CPUs should have similar load.
106106
bool chop_outer = (mncpu <= ((cntsites - 1) * CPU_LOAD_VARIANCE + 1));
107107
bool chop_inner = !chop_outer;
108-
bool hasmask = pq.hasMask();
108+
const bool hasmask = pq.hasMask();
109109
if (!this->isParallel()) chop_outer = chop_inner = false;
110-
bool usefullsum = this->getFlag(USEFULLSUM);
110+
const bool usefullsum = this->getFlag(USEFULLSUM);
111111
for (int i0 = 0; i0 < cntsites; ++i0)
112112
{
113113
if (chop_outer && (n++ % mncpu)) continue;
@@ -182,7 +182,7 @@ void PQEvaluatorOptimized::updateValue(
182182
mtypeused = OPTIMIZED;
183183
// revert to normal calculation if there is no structure or
184184
// if PairQuantity uses mask
185-
if (pq.ticker() >= mvalue_ticker || !mlast_structure || pq.hasPairMask())
185+
if (pq.ticker() >= mvalue_ticker || !mlast_structure)
186186
{
187187
return this->updateValueCompletely(pq, stru);
188188
}
@@ -192,7 +192,7 @@ void PQEvaluatorOptimized::updateValue(
192192
{
193193
return this->updateValueCompletely(pq, stru);
194194
}
195-
if (this->getFlag(FIXEDSITEINDEX) &&
195+
if ((this->getFlag(FIXEDSITEINDEX) || pq.hasPairMask()) &&
196196
sd.diffmethod != StructureDifference::Method::SIDEBYSIDE)
197197
{
198198
return this->updateValueCompletely(pq, stru);
@@ -219,7 +219,7 @@ void PQEvaluatorOptimized::updateValue(
219219
anchors.end() : (anchors.begin() + sd.pop0.size());
220220
SiteIndices::const_iterator ii0;
221221
bool needsreselection = usefullsum;
222-
const bool hastypemask = pq.hasTypeMask();
222+
const bool hasmask = pq.hasMask();
223223
for (ii0 = anchors.begin(); ii0 != last_anchor; ++ii0)
224224
{
225225
if (n++ % mncpu) continue;
@@ -237,8 +237,7 @@ void PQEvaluatorOptimized::updateValue(
237237
for (bnds0->rewind(); !bnds0->finished(); bnds0->next())
238238
{
239239
int i1 = bnds0->site1();
240-
assert(hastypemask || pq.getPairMask(i0, i1));
241-
if (hastypemask && !pq.getPairMask(i0, i1)) continue;
240+
if (hasmask && !pq.getPairMask(i0, i1)) continue;
242241
const int summationscale = (usefullsum || i0 == i1) ? -1 : -2;
243242
pq.addPairContribution(*bnds0, summationscale);
244243
}
@@ -288,8 +287,7 @@ void PQEvaluatorOptimized::updateValue(
288287
for (bnds1->rewind(); !bnds1->finished(); bnds1->next())
289288
{
290289
int i1 = bnds1->site1();
291-
assert(hastypemask || pq.getPairMask(i0, i1));
292-
if (hastypemask && !pq.getPairMask(i0, i1)) continue;
290+
if (hasmask && !pq.getPairMask(i0, i1)) continue;
293291
const int summationscale = (usefullsum || i0 == i1) ? +1 : +2;
294292
pq.addPairContribution(*bnds1, summationscale);
295293
}

src/tests/TestPQEvaluator.hpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,41 @@ class TestPQEvaluator : public CxxTest::TestSuite
175175
}
176176

177177

178+
void test_PDF_pair_mask()
179+
{
180+
mpdfcb.setPairMask(0, 3, false);
181+
mpdfco.setPairMask(0, 3, false);
182+
TS_ASSERT_EQUALS(mzeros, this->pdfcdiff(mstru10));
183+
TS_ASSERT_EQUALS(BASIC, mpdfco.getEvaluatorTypeUsed());
184+
QuantityType gb0 = mpdfcb.getPDF();
185+
// check structure with one changed atom
186+
TS_ASSERT(allclose(mzeros, this->pdfcdiff(mstru10d1)));
187+
TS_ASSERT_EQUALS(OPTIMIZED, mpdfco.getEvaluatorTypeUsed());
188+
QuantityType gb1 = mpdfcb.getPDF();
189+
TS_ASSERT(!allclose(gb0, gb1));
190+
// check structure with one removed atom
191+
TS_ASSERT(allclose(mzeros, this->pdfcdiff(mstru9)));
192+
TS_ASSERT_EQUALS(OPTIMIZED, mpdfco.getEvaluatorTypeUsed());
193+
QuantityType gb2 = mpdfcb.getPDF();
194+
TS_ASSERT(!allclose(gb1, gb2));
195+
// check full evaluation for structure with reversed atoms
196+
mpdfco.eval(mstru10);
197+
TS_ASSERT_EQUALS(mzeros, this->pdfcdiff(mstru10r));
198+
TS_ASSERT_EQUALS(BASIC, mpdfco.getEvaluatorTypeUsed());
199+
QuantityType gb3 = mpdfcb.getPDF();
200+
TS_ASSERT(allclose(gb0, gb3));
201+
// check effect of pair mask updates
202+
mpdfco.eval(mstru10r);
203+
TS_ASSERT_EQUALS(OPTIMIZED, mpdfco.getEvaluatorTypeUsed());
204+
mpdfco.setPairMask(0, 3, false);
205+
mpdfco.eval(mstru10r);
206+
TS_ASSERT_EQUALS(OPTIMIZED, mpdfco.getEvaluatorTypeUsed());
207+
mpdfco.setPairMask(0, 3, true);
208+
mpdfco.eval(mstru10r);
209+
TS_ASSERT_EQUALS(BASIC, mpdfco.getEvaluatorTypeUsed());
210+
}
211+
212+
178213
void test_optimized_unsupported()
179214
{
180215
OverlapCalculator olc;

0 commit comments

Comments
 (0)