This is a generic parallel lapply that work across all major platforms.

par_lapply(
  lst,
  fun,
  cores = NULL,
  parallel = TRUE,
  win_init = expression({     requireNamespace("ctmm", quietly = TRUE) })
)

Arguments

lst

Input list.

fun

Function to be applied on lst. Note only single parameter function is accepted, otherwise it's difficult to determine how to assign input parameters to each list item and worker. You need to convert multiple parameter function into a function take single list parameter, and assign parameters in that list accordingly. align_lists() is a helper function to align multiple lists.

cores

the core count to be used for cluster. Could be a positive integer or

  • Default NULL value will indicate to use a heuristic value based on detected cores, which is roughly min(input_size, physical_cores_count * n), n being 2 for windows, 4 for Mac/Linux. See parallel::detectCores() for more information on physical/logical cores in different platforms.

  • A negative value like -2 will use all available cores - 2, so that 2 cores are reserved for user's other tasks.

parallel

Use regular lapply() when FALSE. You may notice more console messages in this mode because the console messages in parallel mode are lost by default as they happened in other threads.

win_init

Expression to be initialized in Windows. Since all parameters should be included in the input list already, this usually means library calls, like {library(ctmm)} for ctmm related operations, which has been taken care of with the default value. Note requireNamespace() is used because that's more appropriate inside a package.

Value

List of applied results

Details

In Windows parallel::parLapplyLB() is used, which is a socket cluster and need to initialize each session manually with win_init if needed. In Linux/Mac parallel::mclapply() is used, where each worker will inherit the current environment through forking, so no additional setup is required.