*! version 0.2.0 26feb2021

Title

parallel_map -- Run Stata commands in parallel (wrapper of parallel package)

Syntax

Run many parallel instances of a command, in separate Stata instances:

parallel_map
,
values(numlist)
[maxprocesses(#)]
[options]
:
cmd

Parallel:
* values(numlist) each of these values will end up as the $task_id global in its own Stata process (so we will launch in total as many processes as values here)

maxprocesses(#) maximum number of Stata processes that will be open at the same time. Default: (total cores / cores per process)

cores_per_process(#) number of CPU cores that each process will take. Default is c(processors)

force to avoid slowing down total execution, we reduce maxproc if (maxprocesses X cores per process) exceeds the total number of cores available in the computer. force disables this

Execution options:
verbose show more information

nologtable supress table linking to log-files of all processes

programs(namelist) list of programs that will be exported to the worker processes

Internals:
id(#) identifier of the boss process. Used as part the temporary folder names. Default: a pseudo-random number based on runiform()

stata_path(string) path of the Stata binary to be used. Default is based on the parallel package

tmp_path(string) folder where temporary files will be stored (they are stored in a sub-folder of this). Default is c(tmpdir)

* values(numlist) is required.

Description

parallel_map is a wrapper of the parallel package,
with a slightly different syntax.

Examples

Compute three different random numbers (view them in the log):

. parallel_map, val(1/3) verbose: di runiform()

Run a program that accesses the three globals that we can use to load/save data from/to disk:

program define MyExample

di "$parallel_dir" // we can save load/stuff here and then delete it

di "The task ID we can use to save results is: $task_id"

di "Also useful: $padded_task_id"

end

parallel_map, val(1/3) verbose program(MyExample): MyExample