[ADMB Users] vector vs loop and admb speed

H. Skaug hskaug at gmail.com
Thu Jan 31 18:55:36 PST 2013


Hi,

It appears to me that the copy constructor for df1b2matrix (see below)
makes a shallow copy (but I may be wronge), and if so the inefficiency
can be avoided.

However, I take your point that we should go through the code
and look for inefficiencies, and write documentation along the way.
If you are willing to take a skype sesson on this I am happy to participate.
If more a people with write access are willing to join the sessian
that would be even better. 3-4 people should work fine on skype.

Hans

 Copy constructor:
00695 df1b2matrix::df1b2matrix(const df1b2matrix & x)
00696 {
00697   index_min=x.index_min;
00698   index_max=x.index_max;
00699   v=x.v;
00700   shape=x.shape;
00701   if (shape) (shape->ncopies)++;
00702 }

On Thu, Jan 31, 2013 at 9:15 PM, dave fournier <davef at otter-rsch.com> wrote:
> 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.
>
>
>
>
>
> _______________________________________________
> Users mailing list
> Users at admb-project.org
> http://lists.admb-project.org/mailman/listinfo/users



More information about the Users mailing list