does vectorization improve performance?

2012-09-06
2012-09-07
  • Tim Handley

    Tim Handley - 2012-09-06

    For example, is this:

    for(j in 1:N)
    { z[j] <- m*x[j] }
    

    any faster than this:

    z[] <- m*x[]
    
     
    Last edit: Martyn Plummer 2012-09-06
  • Martyn Plummer

    Martyn Plummer - 2012-09-07

    A simple question with three answers

    1. Yes. Evaluation of z is more efficient because the loop is pushed down to a lower level of the program.
    2. But not as much as you might think. The vectorization code is the same for all scalar functions that have scalar arguments. Scalar * vector multiplication is a special case, in that it could be turned into a primitive operation in JAGS by calling BLAS. This would be much more efficient but JAGS does not currently do this.
    3. Overall performance might be worse. With Gibbs sampling, you might not want to update all elements of z at the same time, but vectorization forces this. If all the stochastic parents of z are block updated then it is not a problem.
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks