[ADMB Users] vector vs loop and admb speed

dave fournier davef at otter-rsch.com
Thu Jan 31 12:15:46 PST 2013


Without going through all this there is one extra overhead in vectorized 
code which can be
avoided sometimes.  Consider something like

      A=B+C

where A,B, and C are matrix types.  The way this gets calculated is that 
the function + calculates the sum of the
two matrices and stores this in a matrix, say tmp. the the = function 
assigns  tmp to A. Since usually = is a deep copy
there is some overhead for this.  The overhead is probably a lot more 
for  df1b2matrix than for dvar_matrix as
the former class does not have nearly the level of optimizations in it.

However there were some possibilities for opimization built into df1b2 
stuff.  See the assignment operator in *vc5.cpp


df1b2vector& df1b2vector::operator = (const df1b2vector& _x)
{
   if (allocated())
   {
     ADUNCONST(df1b2vector,x)
     check_shape(*this,x,"df1b2vector& df1b2vector::operator =");
     int mmin=x.indexmin();
     int mmax=x.indexmax();
     for (int i=mmin;i<=mmax;i++)
     {
       (*this)(i)=x(i);
     }
   }
   else
   {
     copy(_x);
   }
   return *this;
}

what this does is to use a shallow copy for a df1b2vector if it is 
unallocated.  I don;t think this was done for df1b2matrices
but it could be.  In the meantime it may be possible to declare a 
df1b2matrix as an array of unallocated df1b2vectors
which would be a partial optimization.   The constructor

df1b2matrix::df1b2matrix(int nrl,int nrh)
{
   if (nrl>nrh)
   {
     allocate();
   }
   else
   {
     allocate(nrl,nrh);
   }
}

in *vc5.cpp should do the job.

Otherwise,  we should go through the assignment operators for df1b2 
types to investigate the opportunities for
optimization.








More information about the Users mailing list