Commit 52719ada authored by Jens Henrik Goebbert's avatar Jens Henrik Goebbert
Browse files

rename to skip

parent 18bb289b
%% Cell type:markdown id: tags:
# 5.9. Distributing Python code across multiple cores with IPython
%% Cell type:markdown id: tags:
No configuration files are necessary to use ipcontroller/engine in an SSH environment without a shared filesystem.
You simply need to make sure that the controller is listening on an interface visible to the engines, and move the connection file from the controller to the engines.
%% Cell type:markdown id: tags:
#### This notebook requires an ipcluster to be executed before start
%% Cell type:code id: tags:
``` python
%%script bash --bg
ipcluster start -n 4
```
%% Cell type:code id: tags:
``` python
!sleep 5
```
%% Cell type:code id: tags:
``` python
from ipyparallel import Client
rc = Client()
```
%% Cell type:code id: tags:
``` python
rc.ids
```
%% Output
[0, 1, 2, 3]
%% Cell type:code id: tags:
``` python
%%px
import os
print(f"Process {os.getpid():d}.")
```
%% Output
[stdout:0] Process 25268.
[stdout:1] Process 25265.
[stdout:2] Process 25269.
[stdout:3] Process 25270.
%% Cell type:code id: tags:
``` python
%%px -t 1,2
# The os module has already been imported in
# the previous cell.
print(f"Process {os.getpid():d}.")
```
%% Output
[stdout:1] Process 25265.
[stdout:2] Process 25269.
%% Cell type:code id: tags:
``` python
%%px -a
import time
time.sleep(5)
```
%% Output
<AsyncResult: execute>
%% Cell type:code id: tags:
``` python
print(_.elapsed, _.ready())
```
%% Output
4.558227 False
%% Cell type:code id: tags:
``` python
%pxresult
```
%% Cell type:code id: tags:
``` python
print(_.elapsed, _.ready())
```
%% Output
5.041382 True
%% Cell type:code id: tags:
``` python
v = rc[:]
res = v.map(lambda x: x * x, range(10))
```
%% Cell type:code id: tags:
``` python
print(res.get())
```
%% Output
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
%% Cell type:markdown id: tags:
```
with view.temp_flags(after=[arB, arC]):
arA = view.apply_async(f)
```
%% Cell type:markdown id: tags:
## Cleanup
%% Cell type:code id: tags:
``` python
!ipcluster stop
```
%% Cell type:code id: tags:
``` python
%killbgscripts
```
%% Output
All background processes were killed.