You are here

RFC: Managing thread-level parallelism

5 posts / 0 new
Last post
mspiegel's picture
Offline
Joined: 07/31/2009 - 15:24
RFC: Managing thread-level parallelism

Starting in OpenMx 1.2, we will have support for multicore execution of the FIML objective function, and for the numerical calculation of the Hessian that is used to compute standard error estimates. A mechanism is needed to specify the number of threads to be assigned to the computations.

We currently have an option available under ?mxOption() that is named "Number of Cores". I'd like to rename the option to "Number of Threads" if there are no objections. And I'd like to propose the following behavior for the value (N) that is stored in this option.

  • If N < 0, then throw an error.
  • If N > 0, then use N threads.
  • If N = 0 and we are not executing a dependent model, then call the function omxDetectCores() to determine the number of threads. omxDetectCores() is backport of the function detectCores() introduced in R 2.14.0.
  • If N = 0 and we are executing an independent model, then use 1 thread.
  • The default value for "Number of Threads" is 0.

As you see, some trickery is used to make sure that processors are allocated correctly when independent submodels are executed. The default is to allocate 1 thread per independent submodel, unless the user explicitly provides a positive integer for the "Number of Threads" option.

JWiley's picture
Offline
Joined: 03/25/2011 - 07:53
Very cool! What mechanism is

Very cool! What mechanism is being used to execute on multicores? Also one small consideration, would it make sense to use N = NULL for the default rather than defaulting to using 0 threads?

mspiegel's picture
Offline
Joined: 07/31/2009 - 15:24
We're using OpenMP for the

We're using OpenMP for the backend C code for this granularity of parallelism. It would be awkward to store N = NULL as the default, as the options are stored in a list data type. Although it's technically possibility to store the value NULL in a list, it becomes difficult to insert and remove the NULL value.

JWiley's picture
Offline
Joined: 03/25/2011 - 07:53
Thanks for the info! Makes

Thanks for the info! Makes sense that you do not want to use NULL values in a list....this is definitely less intuitive to write/read:

dat <- list(A = 1:5, B = matrix(1:4, 2), N = 2L)
dat["N"] <- list(NULL)

tbates's picture
Offline
Joined: 07/31/2009 - 14:25
no objection here

sounds fine to me.