$$ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Self-defined math definitions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Math symbol commands \newcommand{\intd}{\,{\rm d}} % Symbol 'd' used in integration, such as 'dx' \newcommand{\diff}{{\rm d}} % Symbol 'd' used in differentiation \newcommand{\Diff}{{\rm D}} % Symbol 'D' used in differentiation \newcommand{\pdiff}{\partial} % Partial derivative \newcommand{DD}[2]{\frac{\diff}{\diff #2}\left( #1 \right)} \newcommand{Dd}[2]{\frac{\diff #1}{\diff #2}} \newcommand{PD}[2]{\frac{\pdiff}{\pdiff #2}\left( #1 \right)} \newcommand{Pd}[2]{\frac{\pdiff #1}{\pdiff #2}} \newcommand{\rme}{{\rm e}} % Exponential e \newcommand{\rmi}{{\rm i}} % Imaginary unit i \newcommand{\rmj}{{\rm j}} % Imaginary unit j \newcommand{\vect}[1]{\boldsymbol{#1}} % Vector typeset in bold and italic \newcommand{\phs}[1]{\dot{#1}} % Scalar phasor \newcommand{\phsvect}[1]{\boldsymbol{\dot{#1}}} % Vector phasor \newcommand{\normvect}{\vect{n}} % Normal vector: n \newcommand{\dform}[1]{\overset{\rightharpoonup}{\boldsymbol{#1}}} % Vector for differential form \newcommand{\cochain}[1]{\overset{\rightharpoonup}{#1}} % Vector for cochain \newcommand{\bigabs}[1]{\bigg\lvert#1\bigg\rvert} % Absolute value (single big vertical bar) \newcommand{\Abs}[1]{\big\lvert#1\big\rvert} % Absolute value (single big vertical bar) \newcommand{\abs}[1]{\lvert#1\rvert} % Absolute value (single vertical bar) \newcommand{\bignorm}[1]{\bigg\lVert#1\bigg\rVert} % Norm (double big vertical bar) \newcommand{\Norm}[1]{\big\lVert#1\big\rVert} % Norm (double big vertical bar) \newcommand{\norm}[1]{\lVert#1\rVert} % Norm (double vertical bar) \newcommand{\ouset}[3]{\overset{#3}{\underset{#2}{#1}}} % over and under set % Super/subscript for column index of a matrix, which is used in tensor analysis. \newcommand{\cscript}[1]{\;\; #1} % Star symbol used as prefix in front of a paragraph with no indent \newcommand{\prefstar}{\noindent$\ast$ } % Big vertical line restricting the function. % Example: $u(x)\restrict_{\Omega_0}$ \newcommand{\restrict}{\big\vert} % Math operators which are typeset in Roman font \DeclareMathOperator{\sgn}{sgn} % Sign function \DeclareMathOperator{\erf}{erf} % Error function \DeclareMathOperator{\Bd}{Bd} % Boundary of a set, used in topology \DeclareMathOperator{\Int}{Int} % Interior of a set, used in topology \DeclareMathOperator{\rank}{rank} % Rank of a matrix \DeclareMathOperator{\divergence}{div} % Curl \DeclareMathOperator{\curl}{curl} % Curl \DeclareMathOperator{\grad}{grad} % Gradient \DeclareMathOperator{\tr}{tr} % Trace \DeclareMathOperator{\span}{span} % Span $$

止于至善

As regards numerical analysis and mathematical electromagnetism

Profile your program using GNU gprof

Profiling is an indispensable measure for analyzing and optimizing the performance of your program. A typical profiler like GNU gprof will complete this task by running your program after a special compilation.

There are 3 forms of the profiling analysis:

  • flat profile: how much time the program spent in each function and how many times the function was called.

  • call graph: for each function, which function called it and which other functions it called, and how many times.

  • annotated source: a listing of the program source code, which is labeled with the number of times each line of the program was executed.

Compiler options for generating the code which can be profiled by gprof:

  • -pg: enable profiling by gprof, which is always mandatory.

  • -g: enable annotated source profiling.

  • -a: enable basic-block counting, which is required by the annotated source profiling. However, this option does not appear in gcc or g++.

Options for gprof command

  • -p: generate flat profile.

  • -q: generate call graph.

  • -l: enable line-by-line profiling.

  • -s: summarize profile data from different files into gmon.sum.

Steps for using gprof:

  1. Compile the program for gprof:

    g++ -std=gnu++11 -g -O2 -o output input.cpp -gp
  2. Run the program: ./output1. After execution, the profiling data will be stored in the file gmon.out.

  3. Call gprof command with the generated gmon file as argument to generate profiling reports.

posted @ 2021-09-29 10:33  皮波迪博士  阅读(49)  评论(0编辑  收藏  举报