Improving performance with parallel processing

2,139 views
Skip to first unread message

greg

unread,
Apr 27, 2016, 10:05:45 PM4/27/16
to R-inla discussion group
Is it possible to improve performance by using multiple cores? How do I make that work in R for the inla function? Thanks!

INLA help

unread,
Apr 28, 2016, 12:34:15 AM4/28/16
to greg, R-inla discussion group
On Wed, 2016-04-27 at 19:05 -0700, greg wrote:
> Is it possible to improve performance by using multiple cores? How do
> I make that work in R for the inla function? Thanks!

inla does this automatically. the number of threads used depends on the
size of the model and the number of hyperparameters. you can limit the
maximum number of threads used, using

inla(...,  num.threads=N)

or 

inla.setOption( num.threads = N )


by default N = maximum number of cores the machine have

H

--
Håvard Rue
he...@r-inla.org


Finn Lindgren

unread,
Apr 28, 2016, 1:00:16 AM4/28/16
to greg, R-inla discussion group
Hi,

inla() uses multiple cores on shared memory systems by default.
You can control how many by setting the num.threads parameter (usually done only to limit the number of cores used, for large models that would use too much memory when running on all available cores).
It does not use clusters, since the implementation requires shared memory access via OpenMP only, and not MPI.

Finn

On 28 Apr 2016, at 03:05, greg <gregor.h...@gmail.com> wrote:

Is it possible to improve performance by using multiple cores? How do I make that work in R for the inla function? Thanks!

--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.
To post to this group, send email to r-inla-disc...@googlegroups.com.
Visit this group at https://groups.google.com/group/r-inla-discussion-group.
For more options, visit https://groups.google.com/d/optout.

greg

unread,
Apr 28, 2016, 9:37:35 AM4/28/16
to R-inla discussion group, gregor.h...@gmail.com
Thanks, that is very helpful. How can I determine the maximum number of cores used by INLA for a specific model? Is there a way to determine after running a model how many cores were used? I am asking because I have to request resources from a high performance computing cluster and I don't want to request 8 cores if INLA only uses 4.

My current specification has 3 hyperparameters with a iid random intercept and a spatial term, 18 fixed effects, N is 36,701.

Thanks!


On Thursday, April 28, 2016 at 12:00:16 AM UTC-5, Finn Lindgren wrote:
Hi,

inla() uses multiple cores on shared memory systems by default.
You can control how many by setting the num.threads parameter (usually done only to limit the number of cores used, for large models that would use too much memory when running on all available cores).
It does not use clusters, since the implementation requires shared memory access via OpenMP only, and not MPI.

Finn

Finn Lindgren

unread,
Apr 28, 2016, 9:55:03 AM4/28/16
to greg, R-inla discussion group
Hi,
You need to find out how many cores each node in the cluster has. Inla will use as many as it can find within a single node but cannot operate on more than one node, so you may need to specify that as well when requesting cluster resources.

Finn

greg

unread,
Apr 28, 2016, 10:27:13 AM4/28/16
to R-inla discussion group, gregor.h...@gmail.com
Thanks, works perfectly. In my test run with 1846 obs, 8 cores are 3.5 times faster compared to single core performance.


On Thursday, April 28, 2016 at 8:55:03 AM UTC-5, Finn Lindgren wrote:
Hi,

INLA help

unread,
Apr 29, 2016, 3:37:03 AM4/29/16
to greg, R-inla discussion group
On Wed, 2016-04-27 at 19:05 -0700, greg wrote:
> Is it possible to improve performance by using multiple cores? How do
> I make that work in R for the inla function? Thanks!

inla uses by default multiple cores. how many inla request for, depends
on the size of the model (and number of hyperparameters). you can limit
the maximum.number.of.cores that inla can use by

inla(..., num.threads=N)

setting N=1 gives the serial version. 

Best

marcel...@gmail.com

unread,
Oct 12, 2016, 2:46:33 AM10/12/16
to R-inla discussion group, he...@r-inla.org
Hi INLA team,

Like greg I also wish to parallelise my INLA code as it's running in a High Performance Computer. It's set up for shared memory allocation on Linux OS.
I allocate 16 CPU's for the job, but it's only using 4 CPU's. I've tried the command below 
 
inla(...,  num.threads=N) 

and it still only uses the 4 CPU's. 
While the command above is for the maximum number of cores to allocate, is there a minimum number of core allocation option?

thanks in advanced
-marcela

INLA help

unread,
Oct 12, 2016, 3:44:18 AM10/12/16
to marcel...@gmail.com, R-inla discussion group
Hi


the inla-program does use openmp automatically, but how it is done
depend on the number of hyperparameters and the size of the problem.
there are empircally strategies for how to do the paraellization
depending on these and by default, the default strategy is used. you
can set inla(...,num.threads=N)  to define the max number of threads to
use, but interally, it can set a smaller number if it thinks that it
will run faster. 

you can override the 'size' parmeter by

inla(..., control.compute = list(openmp.strategy="huge")

say, which use all paralleism that is available, and the different
options are describe here: (see ?control.compute)


openmp.strategy: The computational strategy to use: 'small', 'medium',
          'large', 'huge' and 'default'. The difference is how the
          parallelisation is done, and is tuned for 'small'-sized
          models, 'medium'-sized models, etc. The default option tries
          to make an educated guess, but this allows to overide this
          selection. Default is 'default'


for "small" then no paralellism is used, so its increasing with the
size. 


the only thing you can do it so test this and what is running better
for you. 

Best
H



On Tue, 2016-10-11 at 23:46 -0700, marcel...@gmail.com wrote:
> Hi INLA team,
>
> Like greg I also wish to parallelise my INLA code as it's running in
> a High Performance Computer. It's set up for shared memory allocation
> on Linux OS.
> I allocate 16 CPU's for the job, but it's only using 4 CPU's. I've
> tried the command below 
>  
> inla(...,  num.threads=N) 
>
> and it still only uses the 4 CPU's. 
> While the command above is for the maximum number of cores to
> allocate, is there a minimum number of core allocation option?
>
> thanks in advanced
> -marcela
>

Haakon Bakka

unread,
Oct 12, 2016, 9:46:53 AM10/12/16
to R-inla discussion group, marcel...@gmail.com
Hi Marcela,

You may know this, but in case you do not:

Setting good initial values can improve running time by 4 times as fast. To do this, you fit to a subset/submodel and use those values in control.mode.

Let me know if you want more details.
Haakon

--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion-group+unsub...@googlegroups.com.
To post to this group, send an email to r-inla-discussion-group@googlegroups.com.

marcel...@gmail.com

unread,
Oct 18, 2016, 7:02:22 PM10/18/16
to R-inla discussion group, marcel...@gmail.com
Thanks Hakkon and H! 

Setting the 
inla(..., control.compute = list(openmp.strategy="huge")

made a difference.

I have run INLA before with starting values initialised in the 
control.mode()
argument. I didn't know it would also speed things up!

cheers
-marcela

To post to this group, send an email to r-inla-disc...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages