JuliaLang/julia — pull request #3494 by amitmurthy (2013-06-22 10:49:57+00:00)
Title: RFC : pfork - function executed in parallel use the fork() system call.

This has been very much done in the lets-try-if-this-works mode.

- It uses the UNIX ```fork()``` system call to execute a function in parallel.
- ```pfork(nforks::Integer, f::Function, args...)``` execute ```nforks``` and executes ```f``` in each child.
- The first parameter to ```f``` is the forked child index.
- ```pfork``` returns an array of size ```nforks```, where the nth element is the value returned by the nth forked child.

Overhead for forking, collecting empty responses and waiting for the exit of 8 children is around 130 milliseconds on my laptop.

```
julia> @time Base.pfork(8, x -> nothing)
elapsed time: 0.130722159 seconds
8-element Any Array:
...
```

@parallel and pfork return similar elapsed times for the random tosses example in the manual when run for 10^10 iterations.

# Pros
- Passing huge amounts of data to the function in the child process is a non-issue since it is a fork.
- In the event the parent process has a shared memory segment, the children have full visibility into the same and
can modify the segment in place. They don't have to bother with returning huge amounts of data either.

# Cons
- No fast implementation of fork() on Windows. So, this will likely be a UNIX only feature.
- Currently can only be executed when ```nprocs() == 1```, i.e., this model is incompatible with the worker model.

Is this useful and something that people would like to see in Base?
Else I'll just add it to PTools.jl for now.