Opened 9 years ago

Closed 9 years ago

#80 closed enhancement (fixed)

configure for profiling

Reported by: Gassmann Owned by: somebody
Priority: minor Component: Wiki documentation
Version: 0.5 Keywords:
Cc:

Description

I am trying to configure a project (OS) for profiling (on Linux Ubuntu). What flags to I need to add to make this work?

Change History (3)

comment:1 Changed 9 years ago by stefan

Hi,

I have no experience with profiling, but now tried with Ipopt 3.8.

I first tried (in my config.site file) only

ADD_CFLAGS=-pg
ADD_CXXFLAGS=-pg
LDFLAGS=-pg

This did not work, because the compiler complained that --fomit-frame-pointer and -pg are not compatible.

So let's also overwrite the OPT_CFLAGS, OPT_FFLAGS, and OPT_CXXFLAGS:

LDFLAGS=-pg

OPT_FFLAGS="-O3"

OPT_CFLAGS="-O3 -pipe -DNDEBUG"
ADD_CFLAGS=-pg

OPT_CXXFLAGS="-O3 -pipe -DNDEBUG"
ADD_CXXFLAGS=-pg

This compiled and linked for me.

Compiling in Ipopt/example/ScalableProblems and running one of the examples created a gmon.out file.

Doing gprof ./solve_problem gives

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
100.00      0.01     0.01                             MittelmannBndryCntrlDiriBase::eval_g(int, double const*, bool, int, double*)
  0.00      0.01     0.00    10404     0.00     0.00  MittelmannBndryCntrlDiri1::y_d_cont(double, double) const
  0.00      0.01     0.00       40     0.00     0.00  RegisteredTNLPs::RegisterTNLP(Ipopt::SmartPtr<RegisteredTNLP> const&, std::string)
  0.00      0.01     0.00       40     0.00     0.00  std::_Rb_tree<std::string, std::pair<std::string const, Ipopt::SmartPtr<RegisteredTNLP> >, std::_Select1st<std::pair<std::string const, Ipopt::SmartPtr<RegisteredTNLP> > >, std::less<std::string>, std::allocator<std::pair<std::string const, Ipopt::SmartPtr<RegisteredTNLP> > > >::_M_insert_(std::_Rb_tree_node_base const*, std::_Rb_tree_node_base const*, std::pair<std::string const, Ipopt::SmartPtr<RegisteredTNLP> > const&)
  0.00      0.01     0.00       40     0.00     0.00  std::_Rb_tree<std::string, std::pair<std::string const, Ipopt::SmartPtr<RegisteredTNLP> >, std::_Select1st<std::pair<std::string const, Ipopt::SmartPtr<RegisteredTNLP> > >, std::less<std::string>, std::allocator<std::pair<std::string const, Ipopt::SmartPtr<RegisteredTNLP> > > >::_M_insert_unique_(std::_Rb_tree_const_iterator<std::pair<std::string const, Ipopt::SmartPtr<RegisteredTNLP> > >, std::pair<std::string const, Ipopt::SmartPtr<RegisteredTNLP> > const&)
  0.00      0.01     0.00       33     0.00     0.00  RegisteredTNLPs::RegisteredTNLPs(Ipopt::SmartPtr<RegisteredTNLP> const&, std::string)
  0.00      0.01     0.00        8     0.00     0.00  Ipopt::SmartPtr<RegisteredTNLP>::ReleasePointer_()

And I think this output says that most of the time is spend in the evaluation of the gradient.

I do not get as much output from gprof as I expected. E.g., all function calls mentioned seem to be from the examples code, but nothing from the Ipopt library itself.

Maybe a static build (--disable-shared) will do better?

Also I saw that in the SCIP makefiles we have a -g in the compiler flags. This may yield more information in the gprof output about where a function is located in the code and so on.

Using also -lc_p instead of -lc as mentioned at http://www.cs.utah.edu/dept/old/texinfo/as/gprof.html#SEC2 I have not tried. They say This is not absolutely necessary, but doing this gives you number-of-calls information for standard library functions such as read and open. Maybe adding -lc_p to LDFLAGS would suffice.

Stefan

comment:2 Changed 9 years ago by stefan

Hi,

when I do a static build and run the same example, then I indeed get more information:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 90.30     14.80    14.80                             ma27od_
  3.78     15.42     0.62                             ma27rd_
  3.54     16.00     0.58                             ma27qd_
  0.43     16.07     0.07                             ma27nd_
  0.43     16.14     0.07                             mc19ad_
  0.31     16.19     0.05      188     0.27     0.27  Ipopt::GenTMatrix::TransMultVectorImpl(double, Ipopt::Vector const&, double, Ipopt::Vector&) const
  0.18     16.22     0.03       18     1.67     2.19  Ipopt::TNLPAdapter::Eval_jac_c(Ipopt::Vector const&, Ipopt::Matrix&)
  0.18     16.25     0.03                             ma27hd_
  0.12     16.27     0.02      548     0.04     0.04  Ipopt::ExpansionMatrix::MultVectorImpl(double, Ipopt::Vector const&, double, Ipopt::Vector&) const
  0.12     16.29     0.02      154     0.13     0.13  Ipopt::GenTMatrix::MultVectorImpl(double, Ipopt::Vector const&, double, Ipopt::Vector&) const
  0.12     16.31     0.02       12     1.67     1.67  Ipopt::Mc19TSymScalingMethod::ComputeSymTScalingFactors(int, int, int const*, int const*, double const*, double*)
  0.06     16.32     0.01     1433     0.01     0.01  Ipopt::DenseVector::AddTwoVectorsImpl(double, Ipopt::Vector const&, double, Ipopt::Vector const&, double)
  0.06     16.33     0.01      898     0.01     0.01  Ipopt::DenseVector::ElementWiseMultiplyImpl(Ipopt::Vector const&)
  0.06     16.34     0.01      424     0.02     0.02  Ipopt::ExpansionMatrix::AddMSinvZImpl(double, Ipopt::Vector const&, Ipopt::Vector const&, Ipopt::Vector&) const
  0.06     16.35     0.01      179     0.06     0.06  Ipopt::TripletHelper::FillValues(int, Ipopt::Matrix const&, double*)
  0.06     16.36     0.01       19     0.53     0.53  MittelmannBndryCntrlDiriBase::eval_jac_g(int, double const*, bool, int, int, int*, int*, double*)
  0.06     16.37     0.01       18     0.56     0.56  MittelmannBndryCntrlDiriBase::eval_grad_f(int, double const*, bool, double*)
  0.06     16.38     0.01       18     0.56     2.22  Ipopt::TSymLinearSolver::GiveMatrixToSolver(bool, Ipopt::SymMatrix const&)
  0.06     16.39     0.01        1    10.00    10.53  Ipopt::TNLPAdapter::GetSpaces(Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::SmartPtr<Ipopt::MatrixSpace const>&, Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::SmartPtr<Ipopt::MatrixSpace const>&, Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::SmartPtr<Ipopt::MatrixSpace const>&, Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::SmartPtr<Ipopt::MatrixSpace const>&, Ipopt::SmartPtr<Ipopt::MatrixSpace const>&, Ipopt::SmartPtr<Ipopt::MatrixSpace const>&, Ipopt::SmartPtr<Ipopt::SymMatrixSpace const>&)
  0.00     16.39     0.00    45602     0.00     0.00  Ipopt::SmartPtr<Ipopt::Vector const>::ReleasePointer_()
  0.00     16.39     0.00    20113     0.00     0.00  Ipopt::SmartPtr<Ipopt::Vector>::ReleasePointer_()
  0.00     16.39     0.00    12965     0.00     0.00  Ipopt::SmartPtr<Ipopt::IteratesVector const>::ReleasePointer_()
  0.00     16.39     0.00    12353     0.00     0.00  Ipopt::SmartPtr<Ipopt::VectorSpace const>::ReleasePointer_()
  0.00     16.39     0.00    10404     0.00     0.00  MittelmannBndryCntrlDiri1::y_d_cont(double, double) const

This is more like what one expects. I.e., most of the time is spend in the linear solver.

Stefan

comment:3 Changed 9 years ago by stefan

  • Resolution set to fixed
  • Status changed from new to closed

Hi,

last one...

On http://www.redhat.com/archives/enigma-list/2001-December/msg00109.html it sounds like adding -static makes g++ call the linker in a way that it automatically uses the profiling version of libc, i.e., -lc_p instead of -lc.

Unfortunately, adding -static to the LDFLAGS does not work for me, because libtool seems to remove it:

/bin/sh ../../libtool --tag=CXX --mode=link g++  -O2 -g -pipe -DNDEBUG -pg   -pg -static -o hs071_cpp  hs071_main.o hs071_nlp.o ../src/Interfaces/libipopt.la -lpthread -llapack -lblas -lm  -ldl  -L/usr/lib64/gcc/x86_64-suse-linux/4.4 -L/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.4/../../.. -lgfortranbegin -lgfortran -lm -lgcc_eh -ldl
g++ -O2 -g -pipe -DNDEBUG -pg -pg -o hs071_cpp hs071_main.o hs071_nlp.o  ../src/Interfaces/.libs/libipopt.a -lpthread -llapack -lblas -L/usr/lib64/gcc/x86_64-suse-linux/4.4 -L/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.4/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.4/../../.. -lgfortranbegin -lgfortran -lm -lgcc_eh -ldl

However, if I add -static to the examples Makefile by hand and run the same example again, then I also get profiling information from system libraries:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 89.28     14.83    14.83                             ma27od_
  3.79     15.46     0.63                             ma27rd_
  3.25     16.00     0.54                             ma27qd_
  0.60     16.10     0.10                             ma27nd_
  0.42     16.17     0.07                             logf
  0.36     16.23     0.06                             ma27hd_
  0.36     16.29     0.06                             mc19ad_
  0.24     16.33     0.04      188     0.21     0.21  Ipopt::GenTMatrix::TransMultVectorImpl(double, Ipopt::Vector const&, double, Ipopt::Vector&) const
  0.24     16.37     0.04                             dcopy_
  0.18     16.40     0.03      312     0.10     0.10  Ipopt::ExpansionMatrix::SinvBlrmZMTdBrImpl(double, Ipopt::Vector const&, Ipopt::Vector const&, Ipopt::Vector const&, Ipopt::Vector const&, Ipopt::Vector&) const
  0.18     16.43     0.03                             daxpy_
  0.18     16.46     0.03                             idamax_
  0.12     16.48     0.02      424     0.05     0.05  Ipopt::ExpansionMatrix::AddMSinvZImpl(double, Ipopt::Vector const&, Ipopt::Vector const&, Ipopt::Vector&) const
  0.12     16.50     0.02      154     0.13     0.13  Ipopt::GenTMatrix::MultVectorImpl(double, Ipopt::Vector const&, double, Ipopt::Vector&) const
  0.12     16.52     0.02       12     1.67     1.67  Ipopt::Mc19TSymScalingMethod::ComputeSymTScalingFactors(int, int, int const*, int const*, double const*, double*)
  0.12     16.54     0.02                             dnrm2_
  0.06     16.55     0.01       79     0.13     0.51  Ipopt::TSymLinearSolver::MultiSolve(Ipopt::SymMatrix const&, std::vector<Ipopt::SmartPtr<Ipopt::Vector const>, std::allocator<Ipopt::SmartPtr<Ipopt::Vector const> > >&,
  0.06     16.56     0.01       18     0.56     0.56  MittelmannBndryCntrlDiriBase::eval_grad_f(int, double const*, bool, double*)
  0.06     16.57     0.01       18     0.56     0.56  Ipopt::TNLPAdapter::Eval_jac_c(Ipopt::Vector const&, Ipopt::Matrix&)
  0.06     16.58     0.01       18     0.56     1.67  Ipopt::TSymLinearSolver::GiveMatrixToSolver(bool, Ipopt::SymMatrix const&)
  0.06     16.59     0.01        1    10.00    10.00  Ipopt::TNLPAdapter::GetSpaces(Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::SmartPtr<Ipopt::VectorSpace const>&, Ipopt::
  0.06     16.60     0.01                             log
  0.06     16.61     0.01                             munmap
  0.00     16.61     0.00    45602     0.00     0.00  Ipopt::SmartPtr<Ipopt::Vector const>::ReleasePointer_()
  0.00     16.61     0.00    20113     0.00     0.00  Ipopt::SmartPtr<Ipopt::Vector>::ReleasePointer_()
  0.00     16.61     0.00    12965     0.00     0.00  Ipopt::SmartPtr<Ipopt::IteratesVector const>::ReleasePointer_()
  0.00     16.61     0.00    12353     0.00     0.00  Ipopt::SmartPtr<Ipopt::VectorSpace const>::ReleasePointer_()
  0.00     16.61     0.00    10404     0.00     0.00  MittelmannBndryCntrlDiri1::y_d_cont(double, double) const
Note: See TracTickets for help on using tickets.