Skip to content

Commit ca415ac

Browse files
author
Avirup Sircar
committed
Some minor optimizations
1 parent 2bfc09b commit ca415ac

File tree

13 files changed

+406
-148
lines changed

13 files changed

+406
-148
lines changed

analysis/classicalEnrichmentComparison/PSP/KSDFTClassicalUniformQuad/TestKohnShamDft.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ void getVLoc(
407407
d_atomTolocPSPSplineMap.push_back(
408408
utils::Spline(radialValuesSTL,
409409
potentialValuesLocSTL,
410+
false,
410411
utils::Spline::spline_type::cspline,
411412
false,
412413
utils::Spline::bd_type::first_deriv,

analysis/classicalEnrichmentComparison/PSP/KSDFTOrthoEFEUniformQuad/TestKohnShamDft.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,7 @@ void getVLoc(
402402
d_atomTolocPSPSplineMap.push_back(
403403
utils::Spline(radialValuesSTL,
404404
potentialValuesLocSTL,
405+
false,
405406
utils::Spline::spline_type::cspline,
406407
false,
407408
utils::Spline::bd_type::first_deriv,

analysis/classicalEnrichmentComparison/PSP/KSDFTOrthoEFEUniformQuad/TestKohnShamDftDeltaRho.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ void getVLoc(
287287
d_atomTolocPSPSplineMap.push_back(
288288
utils::Spline(radialValuesSTL,
289289
potentialValuesLocSTL,
290+
false,
290291
utils::Spline::spline_type::cspline,
291292
false,
292293
utils::Spline::bd_type::first_deriv,

analysis/classicalEnrichmentComparison/PSP/Si_BLPS_0.7_nodal.xml

Lines changed: 58 additions & 0 deletions
Large diffs are not rendered by default.

src/atoms/SphericalDataNumerical.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ namespace dftefe
297297
SphericalDataNumerical::initSpline()
298298
{
299299
d_spline = std::make_shared<const utils::Spline>(this->d_radialPoints,
300-
this->d_radialValues);
300+
this->d_radialValues,
301+
true);
301302
}
302303

303304
double

src/basis/FEBasisOperations.t.cpp

Lines changed: 51 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,24 @@ namespace dftefe
137137
sameQuadRuleInAllCells && (!variableDofsPerCell);
138138
linearAlgebra::blasLapack::Layout layout =
139139
linearAlgebra::blasLapack::Layout::ColMajor;
140-
size_type NifNjStartOffset = 0;
140+
size_type NifNjStartOffset = 0, quadCellsInBlockOffSet = 0;
141141

142142
/** --- Storages --------- **/
143143
size_type maxDofInCell =
144144
*std::max_element(numCellDofs.begin(), numCellDofs.end());
145145
size_type maxQuadInCell =
146146
*std::max_element(numCellQuad.begin(), numCellQuad.end());
147147

148-
StorageUnion fxJxW(1 /*numComponents of f*/ * maxQuadInCell *
149-
cellBlockSize,
148+
const size_type numCumulativeQuadCells =
149+
std::accumulate(numCellQuad.begin(), numCellQuad.end(), 0);
150+
151+
StorageUnion fxJxW(1 /*numComponents of f*/ *
152+
numCumulativeQuadCells,
150153
ValueTypeUnion());
154+
155+
// StorageUnion fxJxW(1 /*numComponents of f*/ * maxQuadInCell *
156+
// cellBlockSize,
157+
// ValueTypeUnion());
151158
StorageUnion fxJxWxNBlock(maxQuadInCell * cellBlockSize *
152159
maxDofInCell,
153160
ValueTypeUnion());
@@ -161,6 +168,22 @@ namespace dftefe
161168
ValueTypeBasisData());
162169
/** --- Storages --------- **/
163170

171+
if (f.getNumberComponents() == 1)
172+
{
173+
linearAlgebra::blasLapack::hadamardProduct(jxwStorage.size(),
174+
jxwStorage.data(),
175+
f.begin(),
176+
fxJxW.data(),
177+
linAlgOpContext);
178+
}
179+
else
180+
{
181+
utils::throwException(
182+
false,
183+
"quadValuesContainer f in BasisWeakFormKernelWithField"
184+
" can be only a scalar field in real space with 1 component.");
185+
}
186+
164187
for (size_type cellStartId = 0; cellStartId < numLocallyOwnedCells;
165188
cellStartId += cellBlockSize)
166189
{
@@ -182,12 +205,13 @@ namespace dftefe
182205
numCellsInBlockQuad.end(),
183206
0);
184207

185-
size_type numCumulativeQuadxDofsCellsInBlock = 0;
208+
// size_type numCumulativeQuadxDofsCellsInBlock = 0;
186209
size_type numCumulativeDofsxDofsCellsInBlock = 0;
187210
for (size_type iCell = 0; iCell < numCellsInBlock; iCell++)
188211
{
189-
numCumulativeQuadxDofsCellsInBlock +=
190-
numCellsInBlockQuad[iCell] * numCellsInBlockDofs[iCell];
212+
// numCumulativeQuadxDofsCellsInBlock +=
213+
// numCellsInBlockQuad[iCell] *
214+
// numCellsInBlockDofs[iCell];
191215
numCumulativeDofsxDofsCellsInBlock +=
192216
numCellsInBlockDofs[iCell] * numCellsInBlockDofs[iCell];
193217
}
@@ -216,25 +240,25 @@ namespace dftefe
216240
/** --- Storages --------- **/
217241

218242
/*--------- Compute fxJxW -----------------*/
219-
// TransposedKhatriRao product for inp and JxW
220-
size_type cumulativeA = 0, cumulativeB = 0, cumulativeC = 0;
221-
for (size_type iCell = 0; iCell < numCellsInBlock; iCell++)
222-
{
223-
linearAlgebra::blasLapack::khatriRaoProduct(
224-
layout,
225-
1,
226-
1,
227-
numCellsInBlockQuad[iCell],
228-
jxwStorage.data() +
229-
quadRuleContainer->getCellQuadStartId(cellStartId) +
230-
cumulativeA,
231-
f.begin(cellStartId) + cumulativeB,
232-
fxJxW.data() + cumulativeC,
233-
linAlgOpContext);
234-
cumulativeA += numCellsInBlockQuad[iCell];
235-
cumulativeB += numCellsInBlockQuad[iCell];
236-
cumulativeC += numCellsInBlockQuad[iCell];
237-
}
243+
// // TransposedKhatriRao product for inp and JxW
244+
// size_type cumulativeA = 0, cumulativeB = 0, cumulativeC = 0;
245+
// for (size_type iCell = 0; iCell < numCellsInBlock; iCell++)
246+
// {
247+
// linearAlgebra::blasLapack::khatriRaoProduct(
248+
// layout,
249+
// 1,
250+
// 1,
251+
// numCellsInBlockQuad[iCell],
252+
// jxwStorage.data() +
253+
// quadRuleContainer->getCellQuadStartId(cellStartId) +
254+
// cumulativeA,
255+
// f.begin(cellStartId) + cumulativeB,
256+
// fxJxW.data() + cumulativeC,
257+
// linAlgOpContext);
258+
// cumulativeA += numCellsInBlockQuad[iCell];
259+
// cumulativeB += numCellsInBlockQuad[iCell];
260+
// cumulativeC += numCellsInBlockQuad[iCell];
261+
// }
238262

239263
/*--------- Compute fxJxWxN -----------------*/
240264
linearAlgebra::blasLapack::ScalarOp scalarOpA =
@@ -296,7 +320,7 @@ namespace dftefe
296320
mSize.data(),
297321
nSize.data(),
298322
kSize.data(),
299-
fxJxW.data(),
323+
fxJxW.data() + quadCellsInBlockOffSet,
300324
basisDataInCellRange.data(),
301325
fxJxWxNBlock.data(),
302326
linAlgOpContext);
@@ -404,6 +428,7 @@ namespace dftefe
404428
linAlgOpContext);
405429

406430
NifNjStartOffset += numCumulativeDofsxDofsCellsInBlock;
431+
quadCellsInBlockOffSet += numCumulativeQuadCellsInBlock;
407432
}
408433
}
409434
else

src/ksdft/Defaults.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ namespace dftefe
4444
const double LinearEigenSolverDefaults::ILL_COND_TOL = 1e-14;
4545
const double LinearEigenSolverDefaults::LANCZOS_EXTREME_EIGENVAL_TOL = 1e-6;
4646
const double LinearEigenSolverDefaults::LANCZOS_BETA_TOL = 1e-14;
47-
const size_type LinearEigenSolverDefaults::LANCZOS_MAX_KRYLOV_SUBSPACE = 40;
47+
const size_type LinearEigenSolverDefaults::LANCZOS_MAX_KRYLOV_SUBSPACE = 20;
4848
/**
4949
* @brief Setting all the ChebyshevPolynomialDegreeDefaults
5050
*/

src/ksdft/KohnShamEigenSolver.t.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ namespace dftefe
160160
1,
161161
tol,
162162
ksdft::LinearEigenSolverDefaults::LANCZOS_BETA_TOL,
163-
*d_lanczosGuess);
163+
*d_lanczosGuess,
164+
false);
164165

165166
linearAlgebra::MultiVector<ValueType, memorySpace> eigenVectorsLanczos;
166167

src/ksdft/KohnShamOperatorContextFE.t.cpp

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,25 @@ namespace dftefe
483483

484484
size_type BStartOffset = 0;
485485
size_type cellLocalIdsOffset = 0;
486+
487+
size_type maxDofInCell =
488+
*std::max_element(numCellDofs.begin(), numCellDofs.end());
489+
490+
utils::MemoryStorage<ValueTypeOperand, memorySpace> xCellValues(
491+
cellBlockSize * numVecs * maxDofInCell,
492+
utils::Types<
493+
linearAlgebra::blasLapack::scalar_type<ValueTypeOperator,
494+
ValueTypeOperand>>::zero);
495+
496+
utils::MemoryStorage<linearAlgebra::blasLapack::
497+
scalar_type<ValueTypeOperator, ValueTypeOperand>,
498+
memorySpace>
499+
yCellValues(
500+
cellBlockSize * numVecs * maxDofInCell,
501+
utils::Types<
502+
linearAlgebra::blasLapack::scalar_type<ValueTypeOperator,
503+
ValueTypeOperand>>::zero);
504+
486505
for (size_type cellStartId = 0; cellStartId < numLocallyOwnedCells;
487506
cellStartId += cellBlockSize)
488507
{
@@ -504,11 +523,11 @@ namespace dftefe
504523
cellsInBlockNumDoFs.copyFrom(cellsInBlockNumDoFsSTL);
505524

506525
// allocate memory for cell-wise data for x
507-
utils::MemoryStorage<ValueTypeOperand, memorySpace> xCellValues(
508-
cellsInBlockNumCumulativeDoFs * numVecs,
509-
utils::Types<linearAlgebra::blasLapack::scalar_type<
510-
ValueTypeOperator,
511-
ValueTypeOperand>>::zero);
526+
// utils::MemoryStorage<ValueTypeOperand, memorySpace> xCellValues(
527+
// cellsInBlockNumCumulativeDoFs * numVecs,
528+
// utils::Types<linearAlgebra::blasLapack::scalar_type<
529+
// ValueTypeOperator,
530+
// ValueTypeOperand>>::zero);
512531

513532
// copy x to cell-wise data
514533
basis::FECellWiseDataOperations<ValueTypeOperand, memorySpace>::
@@ -557,14 +576,14 @@ namespace dftefe
557576
numVecs);
558577

559578
// allocate memory for cell-wise data for y
560-
utils::MemoryStorage<
561-
linearAlgebra::blasLapack::scalar_type<ValueTypeOperator,
562-
ValueTypeOperand>,
563-
memorySpace>
564-
yCellValues(cellsInBlockNumCumulativeDoFs * numVecs,
565-
utils::Types<linearAlgebra::blasLapack::scalar_type<
566-
ValueTypeOperator,
567-
ValueTypeOperand>>::zero);
579+
// utils::MemoryStorage<
580+
// linearAlgebra::blasLapack::scalar_type<ValueTypeOperator,
581+
// ValueTypeOperand>,
582+
// memorySpace>
583+
// yCellValues(cellsInBlockNumCumulativeDoFs * numVecs,
584+
// utils::Types<linearAlgebra::blasLapack::scalar_type<
585+
// ValueTypeOperator,
586+
// ValueTypeOperand>>::zero);
568587

569588
linearAlgebra::blasLapack::scalar_type<ValueTypeOperator,
570589
ValueTypeOperand>

src/linearAlgebra/LanczosExtremeEigenSolver.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ namespace dftefe
8383
const size_type numUpperExtermeEigenValues,
8484
std::vector<double> & tolerance,
8585
double lanczosBetaTolerance,
86-
const Vector<ValueTypeOperand, memorySpace> &initialGuess);
86+
const Vector<ValueTypeOperand, memorySpace> &initialGuess,
87+
bool isAdaptiveSolve = true);
8788

8889
LanczosExtremeEigenSolver(
8990
const size_type maxKrylovSubspaceSize,
@@ -93,7 +94,8 @@ namespace dftefe
9394
double lanczosBetaTolerance,
9495
std::shared_ptr<const utils::mpi::MPIPatternP2P<memorySpace>>
9596
mpiPatternP2P,
96-
std::shared_ptr<LinAlgOpContext<memorySpace>> linAlgOpContext);
97+
std::shared_ptr<LinAlgOpContext<memorySpace>> linAlgOpContext,
98+
bool isAdaptiveSolve = true);
9799

98100
/**
99101
*@brief Default Destructor
@@ -146,6 +148,7 @@ namespace dftefe
146148
std::vector<RealType> d_diagonal;
147149
std::vector<RealType> d_subDiagonal;
148150
bool d_isSolved;
151+
const bool d_isAdaptiveSolve;
149152

150153

151154
}; // end of class LanczosExtremeEigenSolver

0 commit comments

Comments
 (0)