Skip to content

Commit b56dc26

Browse files
committed
123
123
1 parent 076d1a4 commit b56dc26

File tree

4 files changed

+78
-60
lines changed

4 files changed

+78
-60
lines changed

Python_Other_Topics/扩展与性能优化/mpi扩展(mpi4py)/mpi4py.ipynb

Lines changed: 0 additions & 60 deletions
This file was deleted.

Python_Other_Topics/扩展与性能优化/mpi扩展(mpi4py)/.ipynb_checkpoints/mpi4py-checkpoint.ipynb renamed to Python_Other_Topics/扩展与性能优化/多进程工具/mpi扩展(mpi4py)/.ipynb_checkpoints/mpi4py-checkpoint.ipynb

File renamed without changes.
File renamed without changes.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"mpi(Message Passing Interface的简称),也就是消息传递,是c,c++,以及fortran下的并行框架,而[mpi4py](http://mpi4py.readthedocs.org/en/stable/)是它的python接口,pypy也可以使用呦\n",
8+
"\n",
9+
"安装它先要安装openmpi,然后安装numpy和cython\n",
10+
"\n",
11+
"## MPI的工作方式:\n",
12+
"\n",
13+
"MPI就是启动一组MPI进程,每个进程都是执行同样的代码,然后每个进程都有一个ID,也就是rank来标记自己。假设一个CPU是你请的一个工人,共有10个工人。你有100块砖头要搬,然后很公平,让每个工人搬10块。这时候,你把任务写到一个任务卡里面,让10个工人都执行这个任务卡中的任务,也就是搬砖!这个任务卡中的“搬砖”就是你写的代码。然后10个CPU执行同一段代码。需要注意的是,代码里面的所有变量都是每个进程独有的,虽然名字相同。简单的理解就是工作室魔兽多开刷金..."
14+
]
15+
},
16+
{
17+
"cell_type": "markdown",
18+
"metadata": {},
19+
"source": [
20+
"> 例: helloworld"
21+
]
22+
},
23+
{
24+
"cell_type": "markdown",
25+
"metadata": {
26+
"collapsed": false
27+
},
28+
"source": [
29+
"h1.py\n",
30+
"\n",
31+
"```python\n",
32+
"from mpi4py import MPI\n",
33+
"comm = MPI.COMM_WORLD\n",
34+
"rank = comm.Get_rank()\n",
35+
"print(\"hello world\")\n",
36+
"print(\"my rank is:\",rank)\n",
37+
"```"
38+
]
39+
},
40+
{
41+
"cell_type": "markdown",
42+
"metadata": {},
43+
"source": [
44+
" mpirun –np 3 python h1.py"
45+
]
46+
},
47+
{
48+
"cell_type": "code",
49+
"execution_count": null,
50+
"metadata": {
51+
"collapsed": true
52+
},
53+
"outputs": [],
54+
"source": []
55+
}
56+
],
57+
"metadata": {
58+
"kernelspec": {
59+
"display_name": "Pypy",
60+
"language": "python",
61+
"name": "pypy"
62+
},
63+
"language_info": {
64+
"codemirror_mode": {
65+
"name": "ipython",
66+
"version": 2
67+
},
68+
"file_extension": ".py",
69+
"mimetype": "text/x-python",
70+
"name": "python",
71+
"nbconvert_exporter": "python",
72+
"pygments_lexer": "ipython2",
73+
"version": "2.7.10"
74+
}
75+
},
76+
"nbformat": 4,
77+
"nbformat_minor": 0
78+
}

0 commit comments

Comments
 (0)