QMol_DFT_profiler - fmauger1/QMol-grid GitHub Wiki

QMol_DFT_profiler

Memory and execution-time profiler for DFT models.

Description

Use QMol_DFT_profiler to estimate the memory footprint and execution time of a DFT model or component.

Use

Run the memory and execution-time profiling with either

QMol_DFT_profiler(QM);
QMol_DFT_profiler(QM,'all');
  • QM is any of a (TD)DFT model, external-functional, Hartree-functional, or exchange-correlation-functional objects.
  • The requirements and side effects as for both memory-only and execution-time-only modes detailed next.
  • Note that for TDDFT object only the memory footprint, and not the execution time, is estimated.

Run only the memory profiling component with

QMol_DFT_profiler(QM,'memory');
  • DFT model case: If QM is a DFT model object (QMol_DFT_spinRes or QMol_DFT_spinPol), it should define a proper discretization domain (explicitly or implicitly), and external, Hartree, and exchange-correlation functionals; However, it does not need to be initialized before running the memory profiling. The memory profiling uses the object's getMemoryProfile method and has its side effects: all the DFT-model properties are left unchanged while run-time properties may be altered. Notably, if the object was not initialized (isInitialized = false), getMemoryProfile resets the object.
  • DFT component case: If QM is an external, Hartree, or exchange-correlation functional object, it must be initialized (with a DFT component -- see the respective documentation pages for details).
  • TDDFT propagator case: if QM is a TDDFT propagator object, it should define a full DFT model, which is initialized before performing the memory profiling.
  • In all cases, not all the listed components may be used in actual simulations and the memory estimate tries to be conservative. On the other hand, it only includes the discretization of member components on the domain grid and ignores other (small) properties.

Run only the execution-time profiling component with

QMol_DFT_profiler(QM,'time');
  • DFT model case: If QM is a DFT model object (QMol_DFT_spinRes or QMol_DFT_spinPol), it should define a proper discretization domain (explicitly or implicitly), and external, Hartree, and exchange-correlation functionals; However, it does not need to be initialized before running the memory profiling. The execution-time profiling initializes the object and returns it initialized.
  • DFT component case: If QM is an external, Hartree, or exchange-correlation functional object, it must be initialized (with a DFT component -- see the respective documentation pages for details). The execution-time profiling initialized the parent DFT component (QM.DFT.initialize).
  • TDDFT propagator case: no execution time profiling is available for TDDFT propagators. Run an actual TDDFT propagation (over a short time interval) to get an estimate.

The execution-time profiling is performed by running each listed operation a certain number of times and returns the average elapsed time to do so. The default number of iterations is defined internally based on the dimension of the model. Overwrite this default values and specify the number of iterations nbIter with

QMol_DFT_profiler(QM,'all',nbIter);     % Both memory and time profiling
QMol_DFT_profiler(QM,'time',nbIter);    % Execution-time profiling only

Examples

Spin-polarized DFT model

Create a spin-polarized DFT model with

% Domain
x   =   -200:.1:150;

% Molecular model
A1  =   QMol_Va_softCoulomb('name','atom 1','charge',3,'position',-3);
A2  =   QMol_Va_softCoulomb('name','atom 2','charge',3,'position',0);
A3  =   QMol_Va_softCoulomb('name','atom 3','charge',3,'position',2);

% DFT model
Vext=   QMol_DFT_Vext('atom',{A1,A2});
Vh  =   QMol_DFT_Vh_conv;
Vxc =  {QMol_DFT_Vx_LDA_exp,QMol_DFT_Vx_XX_conv};

DFT =   QMol_DFT_spinPol(                           ...
            'xspan',                        x,      ...
            'occupation',                   {[1 1 1 1 1],[1 1 1 1]},...
            'externalPotential',            Vext,   ...
            'HartreePotential',             Vh,     ...
            'exchangeCorrelationPotential', Vxc);

Run a full (memory + execution-time) profiling

QMol_DFT_profiler(DFT);

yielding

=== Memory footprint =====================================================
  Components                                                    -- Size --
  * Domain discretization                                        
    > domain                                                       27.4 KB
    > gradient                                                     54.7 KB
    > Laplacian                                                    27.4 KB
    > Laplacian (velocity gauge)                                   54.7 KB
  * Kohn-Sham orbitals                                           
    > spin up                                                     273.5 KB
    > spin down                                                   218.8 KB
  * One-body density                                             
    > density                                                      54.7 KB
    > gradient                                                     54.7 KB
  * Kohn-Sham potential                                            54.7 KB
  * Kohn-Sham potential gradient                                   54.7 KB
  * External functional                                          
    > potential                                                    27.4 KB
    > potential gradient                                           27.4 KB
  * Hartree functional                                             54.7 KB
  * Exchange functional (LDA exponential)                        
  * Exact-exchange functional (conv.)                            
    > interaction potential                                        54.7 KB
    > spin up kernel                                              273.5 KB
    > spin down kernel                                            218.8 KB
                                                                ----------
                                                        TOTAL =     1.5 MB

=== Execution time =======================================================
  Operator components                                           -- Time --
  * Hamiltonian (spin up)                        5 x 2.50e-03 = 1.25e-02 s
  * Hamiltonian (spin down)                      4 x 2.08e-03 = 8.31e-03 s
                                                                ----------
                                                        TOTAL = 2.08e-02 s

  * Kinetic                                      9 x 2.22e-04 = 2.00e-03 s
  * Potential (spin up)                          5 x 2.07e-03 = 1.04e-02 s
  * Potential (spin down)                        4 x 1.68e-03 = 6.72e-03 s
                                                                ----------
                                                        TOTAL = 1.91e-02 s

  * External potential                           9 x 2.02e-05 = 1.82e-04 s
  * Hartree potential                            9 x 2.11e-05 = 1.90e-04 s
  * Exch.-corr. potential #1 (spin up)           5 x 1.94e-05 = 9.72e-05 s
  * Exch.-corr. potential #1 (spin down)         4 x 1.98e-05 = 7.90e-05 s
  * Exch.-corr. potential #2 (spin up)           5 x 2.50e-03 = 1.25e-02 s
  * Exch.-corr. potential #2 (spin down)         4 x 2.43e-03 = 9.71e-03 s

  Building potential components                                 -- Time --
  * One-body density                                            3.15e-04 s
  * External functional                                         1.94e-05 s
  * Hartree functional                                          3.66e-04 s
  * Exchange-correlation functional #1                          6.59e-05 s
  * Exchange-correlation functional #2                          4.12e-05 s

  (average times over 500 iterations)

##########################################################################

As one may expect, the exact-exchange potential (second exchange-correlation functional) is much slower to compute than the other operators.

Test suite

Run the test suite for the class in normal or summary mode respectively with

QMol_test.test('DFT_profiler');
QMol_test.test('-summary','DFT_profiler');

For developers

QMol_DFT_profiler hard-codes the size of double-precision floats, which seem to be fixed to 8-bits per MATLAB documentation. If this comes to change, the values need be updated in the getMemoryFootprint method.

Other class methods

The QMol_DFT_profiler class also defines the following static methods restricted to QMol-grid classes (Access=?QMol_suite)

getMemoryFootprint

Get the memory footprint of an array with N elements with

m = QMol_DFT_profiler.getMemoryFootprint(N,'real');   % Real-valued array
m = QMol_DFT_profiler.getMemoryFootprint(N,'imag');   % Complex array
  • The output m is in bytes

showMemoryFootprint

Print out the estimated memory footprint of a component with

QMol_DFT_profiler.showMemoryFootprint(msg,mem,lvl)
  • msg is a character array with the description of the component being displayed (see example above).
  • mem is the estimated memory footprint for the component, in bytes. The value will automatically be converted to KB, MB, GB, or TB as needed. If mem is 0, NaN, or Inf, no memory values is printed out (just the message, see example above).
  • lvl = 1 or lvl = 2, specifies the indentation level for the component (see example above). If no level is specified, default lvl = 1 is used.

Notes

The results displayed in this documentation page were generated using version 01.21 of the QMol-grid package.

  • QMol_DFT_profiler was introduced in version 01.10