help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LSODE speed up question


From: Tatsuro MATSUOKA
Subject: Re: LSODE speed up question
Date: Sun, 27 Apr 2008 07:53:29 +0900 (JST)

Hello

--- Tatsuro MATSUOKA <address@hidden> wrote:
> I tried the non-stiff solver, it is way way slower than the stiff solver. 
> Probably, because the
> problem is stiff. I think I will now try to provide Jacobian to LSODE and see 
> if there is any
> performance enhancement.  I haven't worked with Maxima, however, I am 
> thinking of giving the C++
> library ADOL-C to get Jacobian of the system. 

Sorry my writing was not proper.  Even for non-stiff cases, there are many 
cases the BDF method is
faster than Adams method.
I think that the BDF method suite to your method but it is not a measure stiff 
or not.

Perhaps you know, roughly speaking how the solutions of ODE are not varied 
slowly.  Stiff solutions
are sometimes like randam noise or they have very slowly charning parts and 
very quickily changing
part.  
Here is the example stiff ODE script in Octave manunal. (slightly modified by 
me.) 

**********************************
clear;
## The `oregonator'.
##
## Reference:
##
##   Oscillations in chemical systems.  IV.  Limit cycle behavior in a
##   model of a real chemical reaction. Richard J. Field and Richard
##   M. Noyes, The Journal of Chemical Physics, Volume 60 Number 5,
##   March 1974.function dx = oregonator_m (x, t)

function dx = oregonator_m (x, t)

  dx = zeros (3, 1);

  dx(1) = 77.27*(x(2) - x(1)*x(2) + x(1) - 8.375e-06*x(1)^2);
  dx(2) = (x(3) - x(1)*x(2) - x(2)) / 77.27;
  dx(3) = 0.161*(x(1) - x(3));

end

% The test of `oregonator'.
x0 = [ 4; 1.1; 4 ];
t=0:0.5:500;
ts=cputime();
y = lsode ('oregonator_m', x0, t);
cputime()-ts
plot (t',y(:,1),"",t',y(:,2),"",t',y(:,3));
*******************************************************

> 
> So, in the whole conversation I don't think I have mentioned the actual time 
> it takes me to
> solve the
> system, it takes around 6500 seconds to solve the system of ~300 reactions 
> for 500 time steps.
> Do you
> think this is reasonable or, is this too much and maybe I should look for 
> other causes of
> inefficiency
> in my code. 

I cannot assert anything becauses I do not see your code, I do not know your 
machine spec, how to
build your liboctave concerning optimization option. 

If your liboctave are not build with fully optimized to your compueter, to 
optimize it is also
effective for the calclation being fast.  


Regards

Tatsuro

> 
> On Sat, Apr 26, 2008 at 7:11 AM, Tatsuro MATSUOKA <address@hidden> wrote:
> 
> Hello
> 
> Sorry I sent the reply without finishing again:
> 
> 
> --- Ayesha Kalra <address@hidden> wrote:
> 
> > Hi Tatsuro
> > I can not furnish the whole code but, here is the heart of the code which
> > solves the system of equations f
> >
> > /_/*****************************************************************
> >
> >  // initialize the solver by transfering the function f
> >
> >          ODEFunc odef (f);
> >
> >          // initialize the solver with XS and the initial time
> >
> >          // as well as the ODEFunc object ode
> >
> >
> >
> >          // LSODE options to be specified ***************************
> >
> >          LSODE_options ();                // should specify a stiff solver
> >
> >
> >          // *********************************************************
> >
> >
> >
> >          LSODE ls(XS, 0.0, odef);
> >
> >          // integrate
> >
> >          y = ls.do_integrate(t);
> >
> >
> >
> >          // append data
> >
> >          X_and_S.insert(t,0,0);
> >
> >          X_and_S.insert(y,0,1);
> >
> >
> >
> > /_/*****************************************************************
> 
> 
> The above is general code for LSODE in C++. (I have used a similar routine by 
> myself.)
> So the information is not so helpful for the discussion.
> 
> 
> > The function f is a ColumnVector of length ~300. t is a ColumnVector of
> > length 500. I got the idea to solve equations using LSODE in C++ from the
> > following link
> 
> 
> The step of t is not related to LSODE speed.
> LSODE automatically detemine the integration step
> if you do not specify it at lsode options.
> The vector t is used only for store integated data.
> Only t(size-1) valuse is used to determine integration range.
> 
> Please read help lsode_options.
> Those are to be set for the critical problem.
> 
> Tatsuro>Perhaps the function f is a key point.  Is your problem whether the 
> your problem stiff
> or not?
> Tatsuro>If it is not stiff, you can set lsode option to non-stiff.
> Tatsuro>At that case no Jacobian is used.
> 
> 
> >          LSODE_options ();                // should specify a stiff solver
> Sorry you specfied stiff.
> 
> In addition, f is a ColumnVector of length ~300.  The function should be 
> complex.
> 
> Olaf>A system of 300 ODEs seems a tough job to me ...
> 
> Indeed.
> f is a ColumnVector of length ~300 and stiff. Are ODEs nonlinear? Is there 
> part in linear
> description
> part to be possible.  If so such part can be speed upped by using sparse 
> matrices.
> However 300x300 matrix sparsing is effective or  not I do not know.
> 
> 
> 
> 
> octave:2> help lsode_options
>  -- Loadable Function:  lsode_options (OPT, VAL)
>     When called with two arguments, this function allows you set
>     options parameters for the function `lsode'.  Given one argument,
>     `lsode_options' returns the value of the corresponding option.  If
>     no arguments are supplied, the names of all the available options
>     and their current values are displayed.
> 
>     Options include
> 
>    `"absolute tolerance"'
>          Absolute tolerance.  May be either vector or scalar.  If a
>          vector, it must match the dimension of the state vector.
> 
>    `"relative tolerance"'
>          Relative tolerance parameter.  Unlike the absolute tolerance,
>          this parameter may only be a scalar.
> 
>          The local error test applied at each integration step is
> 
>                 abs (local error in x(i)) <= ...
>                     rtol * abs (y(i)) + atol(i)
> 
>    `"integration method"'
>          A string specifying the method of integration to use to solve
>          the ODE system.  Valid values are
> 
>         "adams"
>         "non-stiff"
>               No Jacobian used (even if it is available).
> 
>         "bdf"
> 
>         "stiff"
>               Use stiff backward differentiation formula (BDF) method.
>               If a function to compute the Jacobian is not supplied,
>               `lsode' will compute a finite difference approximation
>               of the Jacobian matrix.
> 
>    `"initial step size"'
>          The step size to be attempted on the first step (default is
>          determined automatically).
> 
>    `"maximum order"'
>          Restrict the maximum order of the solution method.  If using
>          the Adams method, this option must be between 1 and 12.
>          Otherwise, it must be between 1 and 5, inclusive.
> 
>    `"maximum step size"'
>          Setting the maximum stepsize will avoid passing over very
>          large regions  (default is not specified).
> 
>    `"minimum step size"'
>          The minimum absolute step size allowed (default is 0).
> 
>    `"step limit"'
>          Maximum number of steps allowed (default is 100000).
> 
> 
> ***************************************************
> For details, please visit the page of lsode developper.
> 
> https://computation.llnl.gov/casc/odepack/odepack_home.html
> 
> 
> Regards
> 
> Tatsuro
> 
> 
> 
> 
> > http://info.ee.surrey.ac.uk/Personal/M.Michel/index.php?page=4&site=4
> >
> > Your inputs are welcome.
> >
> > Ayesha
> >
> > On Fri, Apr 25, 2008 at 5:19 PM, Tatsuro MATSUOKA <address@hidden>
> > wrote:
> >
> > > If you would like to use Automatic Differentiation by Analytically,
> > > please use symbolic package in octave-forge.
> > > http://octave.sourceforge.net/packages.html
> > > and see
> > > http://wiki.octave.org/wiki.pl?CategorySymbolic
> > >
> > > If possible, please show the your C++ code.
> > > That will make more fruitful discussion possible
> > >
> > >
> > > Regards
> > >
> > > Tatsuro
> > > --- Ayesha Kalra <address@hidden> wrote:
> > >
> > > > Hi all,
> > > > I am using LSODE in a C++ program to solve a system of ~300 ODEs (500
> > > time
> > > > steps). I used LSODE in C++ so that I could get some performance
> > > enhancement
> > > > over using LSODE in Octave itself, however, there was no improvement in
> > > > performance (measured in time (in sec) taken to solve the system of
> > > > equations. It may be noted that in both cases, I am NOT supplying the
> > > > Jacobian to LSODE. Can anyone tell me what is the bottleneck step for
> > > LSODE,
> > > > if it is calculation of Jacobian of the system,  I will try to calculate
> > > it
> > > > explicitly using some kind of Automatic Differentiation library and then
> > > > supply it to LSODE (I am not sure, how to do this right now, any
> > > > ideas/suggestions are welcome).
> > > >
> > > > Or, is there anything else I need to look/change to speed up solution by
> > > > LSODE in C++.
> > > >
> > > > Thanks
> > > > Ayesha
> > > > > _______________________________________________
> > > > Help-octave mailing list
> > > > address@hidden
> > > > https://www.cae.wisc.edu/mailman/listinfo/help-octave
> > > >
> > >
> 
> 
> --------------------------------------
> GANBARE! NIPPON! Win your ticket to Olympic Games 2008.
> http://pr.mail.yahoo.co.jp/ganbare-nippon/
> 
> 
> 
> --- Tatsuro MATSUOKA <address@hidden> wrote:
> 
> > Hello
> > 
> > Sorry I sent the reply without finishing again:
> > 
> > --- Ayesha Kalra <address@hidden> wrote:
> > 
> > > Hi Tatsuro
> > > I can not furnish the whole code but, here is the heart of the code which
> > > solves the system of equations f
> > > 
> > > //*****************************************************************
> > > 
> > >  // initialize the solver by transfering the function f
> > > 
> > >          ODEFunc odef (f);
> > > 
> > >          // initialize the solver with XS and the initial time
> > > 
> > >          // as well as the ODEFunc object ode
> > > 
> > > 
> > > 
> > >          // LSODE options to be specified ***************************
> > > 
> > >          LSODE_options ();                // should specify a stiff solver
> > > 
> > > 
> > >          // *********************************************************
> > > 
> > > 
> > > 
> > >          LSODE ls(XS, 0.0, odef);
> > > 
> > >          // integrate
> > > 
> > >          y = ls.do_integrate(t);
> > > 
> > > 
> > > 
> > >          // append data
> > > 
> > >          X_and_S.insert(t,0,0);
> > > 
> > >          X_and_S.insert(y,0,1);
> > > 
> > > 
> > > 
> > > //*****************************************************************
> > 
> > 
> > The above is general code for LSODE in C++. (I have used a similar routine 
> > by myself.)
> > So the information is not so helpful for the discussion.
> > 
> > 
> > > The function f is a ColumnVector of length ~300. t is a ColumnVector of
> > > length 500. I got the idea to solve equations using LSODE in C++ from the
> > > following link
> > 
> > 
> > The step of t is not related to LSODE speed.  
> > LSODE automatically detemine the integration step 
> > if you do not specify it at lsode options.  
> > The vector t is used only for store integated data.
> > Only t(size-1) valuse is used to determine integration range.
> > 
> > Please read help lsode_options.
> > Those are to be set for the critical problem.
> > 
> > Tatsuro>Perhaps the function f is a key point.  Is your problem whether the 
> > your problem stiff
> > or not?
> > Tatsuro>If it is not stiff, you can set lsode option to non-stiff.  
> > Tatsuro>At that case no Jacobian is used.  
> > 
> > 
> > >          LSODE_options ();                // should specify a stiff solver
> > Sorry you specfied stiff.
> > 
> > In addition, f is a ColumnVector of length ~300.  The function should be 
> > complex.
> > Olaf>A system of 300 ODEs seems a tough job to me ...
> > 
> > Indeed. 
> > f is a ColumnVector of length ~300 and stiff. Are ODEs nonlinear? Is there 
> > part in linear
> > description
> > part to be possible.  If so such part can be speed upped by using sparse 
> > matrices.
> > However 300x300 matrix sparsing is effective or  not I do not know.
> >  
> > 
> > 
> > octave:2> help lsode_options
> >  -- Loadable Function:  lsode_options (OPT, VAL)
> >      When called with two arguments, this function allows you set
> >      options parameters for the function `lsode'.  Given one argument,
> >      `lsode_options' returns the value of the corresponding option.  If
> >      no arguments are supplied, the names of all the available options
> >      and their current values are displayed.
> > 
> >      Options include
> > 
> >     `"absolute tolerance"'
> >           Absolute tolerance.  May be either vector or scalar.  If a
> >           vector, it must match the dimension of the state vector.
> > 
> >     `"relative tolerance"'
> >           Relative tolerance parameter.  Unlike the absolute tolerance,
> >           this parameter may only be a scalar.
> > 
> >           The local error test applied at each integration step is
> > 
> >                  abs (local error in x(i)) <= ...
> >                      rtol * abs (y(i)) + atol(i)
> > 
> >     `"integration method"'
> >           A string specifying the method of integration to use to solve
> >           the ODE system.  Valid values are
> > 
> >          "adams"
> >          "non-stiff"
> >                No Jacobian used (even if it is available).
> > 
> >          "bdf"
> > 
> >          "stiff"
> >                Use stiff backward differentiation formula (BDF) method.
> >                If a function to compute the Jacobian is not supplied,
> >                `lsode' will compute a finite difference approximation
> >                of the Jacobian matrix.
> > 
> >     `"initial step size"'
> >           The step size to be attempted on the first step (default is
> >           determined automatically).
> > 
> >     `"maximum order"'
> >           Restrict the maximum order of the solution method.  If using
> >           the Adams method, this option must be between 1 and 12.
> >           Otherwise, it must be between 1 and 5, inclusive.
> > 
> >     `"maximum step size"'
> >           Setting the maximum stepsize will avoid passing over very
> >           large regions  (default is not specified).
> > 
> >     `"minimum step size"'
> >           The minimum absolute step size allowed (default is 0).
> > 
> >     `"step limit"'
> >           Maximum number of steps allowed (default is 100000). 
> > 
> > ***************************************************
> > For details, please visit the page of lsode developper.
> > 
> > https://computation.llnl.gov/casc/odepack/odepack_home.html
> > 
> > 
> > Regards
> > 
> > Tatsuro
> > 
> > 
> > 
> > > http://info.ee.surrey.ac.uk/Personal/M.Michel/index.php?page=4&site=4
> > > 
> > > Your inputs are welcome.
> > > 
> > > Ayesha
> > > 
> > > On Fri, Apr 25, 2008 at 5:19 PM, Tatsuro MATSUOKA <address@hidden>
> > > wrote:
> > > 
> > > > If you would like to use Automatic Differentiation by Analytically,
> > > > please use symbolic package in octave-forge.
> > > > http://octave.sourceforge.net/packages.html
> > > > and see
> > > > http://wiki.octave.org/wiki.pl?CategorySymbolic
> > > >
> > > > If possible, please show the your C++ code.
> > > > That will make more fruitful discussion possible
> > > >
> > > >
> > > > Regards
> > > >
> > > > Tatsuro
> > > > --- Ayesha Kalra <address@hidden> wrote:
> > > >
> > > > > Hi all,
> > > > > I am using LSODE in a C++ program to solve a system of ~300 ODEs (500
> > > > time
> > > > > steps). I used LSODE in C++ so that I could get some performance
> > > > enhancement
> > > > > over using LSODE in Octave itself, however, there was no improvement 
> > > > > in
> > > > > performance (measured in time (in sec) taken to solve the system of
> > > > > equations. It may be noted that in both cases, I am NOT supplying the
> > > > > Jacobian to LSODE. Can anyone tell me what is the bottleneck step for
> > > > LSODE,
> > > > > if it is calculation of Jacobian of the system,  I will try to 
> > > > > calculate
> > > > it
> > > > > explicitly using some kind of Automatic Differentiation library and 
> > > > > then
> > > > > supply it to LSODE (I am not sure, how to do this right now, any
> > > > > ideas/suggestions are welcome).
> > > > >
> > > > > Or, is there anything else I need to look/change to speed up solution 
> > > > > by
> > > > > LSODE in C++.
> > > > >
> > > > > Thanks
> > > > > Ayesha
> > > > > > _______________________________________________
> > > > > Help-octave mailing list
> > > > > address@hidden
> > > > > https://www.cae.wisc.edu/mailman/listinfo/help-octave
> > > > >
> > > >
> > 
> > 
> > --------------------------------------
> > GANBARE! NIPPON! Win your ticket to Olympic Games 2008.
> > http://pr.mail.yahoo.co.jp/ganbare-nippon/
> > 
> 
> 
> --------------------------------------
> GANBARE! NIPPON! Win your ticket to Olympic Games 2008.
> http://pr.mail.yahoo.co.jp/ganbare-nippon/
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
> 


--------------------------------------
GANBARE! NIPPON! Win your ticket to Olympic Games 2008.
http://pr.mail.yahoo.co.jp/ganbare-nippon/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]