close

Вход

Забыли?

вход по аккаунту

?

Методичка. - Введение в паралельные вычисления (2002).pdf

код для вставкиСкачать
Fhkdh\kdbc]hkm^Zjkl\_ggucmgb\_jkbl_lbfF<Ehfhghkh\Z
GZmqgh-bkke_^h\Zl_evkdbc\uqbkebl_evgucp_glj
<<?>?GB?<I:J:EE?EVGU?<UQBKE?GBY
f_lh^bq_kdh_ihkh[b_
:K:glhgh\
Fhkd\Z
>Zggh_ ihkh[b_ ij_^gZagZq_gh ^ey gZqZevgh]h hk\h_gby ijZdlbq_kdh]hdmjkZ
iZjZee_evguo\uqbke_gbcIj_^iheZ]Z_lkyqlhijb\h^bfhcbgnhjfZpbb^hklZlhqgh^eygZqZeZk_jv_aghcjZ[hlugZiZjZee_evguodhfivxl_jZo\i_j\mx
hq_j_^vdeZkl_jguokbkl_fZoIjbwlhfhkgh\ghcmihj^_eZ_lkygZhk\h_gb_
ijZdlbq_kdbogZ\udh\jZ[hlugZ\uqbkebl_evghfdeZkl_j_GB<PF=MDmjk
\dexqZ_l \ k_[y \\h^gu_ k\_^_gby h[ hi_jZpbhgghc kbkl_f_ UNIX Zjobl_dlmj_ kmi_jdhfivxl_jh\ b \uqbkebl_evguo deZkl_jh\ h[gZjm`_gbbbbkihevah\Zgbb iZjZee_ebafZ ijh]jZff l_ogheh]byo iZjZee_evgh]h ijh]jZffbjh\Zgbybfgh]b_ijZdlbq_kdb_k\_^_gbyg_h[oh^bfu_^eygZqZeZjZ[hluHgjZkkqblZghjb_glbjh\hqghgZ aZgylbc badhlhjuog_kdhevdhihke_^gbohl\h^ylkygZhleZ^dmbhilbfbaZpbxfh^_evghcaZ^ZqbF_lh^bq_kdh_ihkh[b_kh^_j`bl \_kv g_h[oh^bfuc fZl_jbZe ^ey gZqZeZ jZ[hlu gZ \uqbkebl_evguo
deZkl_jZobkha^Zgbyj_Zevguownn_dlb\guoiZjZee_evguoijh]jZff
2
AZgylb_<\_^_gb_Dhjhldhh[hi_jZpbhgghckbkl_f_81,;............................ 5
1. BklhqgbdbbgnhjfZpbb ............................................................................... 5
2. IeZgaZgylbcijZdlbq_kdb_aZ^ZgbyiheblbdZ^hklmiZ ......................... 5
3. Dhjhldhh[hi_jZpbhgghckbkl_f_81,; .................................................. 5
AZ^Zgby .................................................................................................................. 9
AZgylb_<uqbkebl_evgucdeZkl_jGB<PF=M ................................................ 10
1. :jobl_dlmjZdeZkl_jZ6&, ......................................................................... 10
2. <oh^gZdeZkl_j........................................................................................... 12
3. Dhfibeypby ................................................................................................. 12
4. Kbkl_fZhq_j_^_c........................................................................................ 13
4. Web-bgl_jn_ckaZimkdZaZ^ZqgZ\uqbkebl_evghfdeZkl_j_................. 15
5. AZ^Zgby........................................................................................................ 16
AZgylb_IZjZee_ebafb_]hbkihevah\Zgb_ ........................................................ 17
1. IZjZee_ebaf ................................................................................................ 17
2. Bkihevah\Zgb_iZjZee_ebafZ .................................................................... 20
3. Wnn_dlb\ghklvjZkiZjZee_eb\Zgby.......................................................... 26
4. H[km`^_gb_fh^_evghcaZ^Zqb ................................................................. 27
5. AZ^Zgby........................................................................................................ 28
AZgylb_L_ogheh]byMPI ...................................................................................... 29
2. <\_^_gb_ ...................................................................................................... 29
3. H[sb_nmgdpbb03, .................................................................................. 31
4. Ijb_fi_j_^ZqZkhh[s_gbcf_`^mhl^_evgufbijhp_kkZfb ............... 33
5. AZ^Zgby........................................................................................................ 46
AZgylb_L_ogheh]byMPIijh^he`_gb_............................................................ 47
1. Dhee_dlb\gu_\aZbfh^_ckl\byijhp_kkh\............................................... 47
2. KbgojhgbaZpbyijhp_kkh\ ......................................................................... 51
3. JZ[hlZk]jmiiZfbijhp_kkh\ .................................................................... 51
6. AZ^Zgby........................................................................................................ 52
AZgylb_L_ogheh]bbiZjZee_evgh]hijh]jZffbjh\Zgbyh[ahj..................... 53
1. Ki_pdhff_glZjbb ....................................................................................... 53
2. JZkrbj_gbykms_kl\mxsboyaudh\ijh]jZffbjh\Zgby........................ 54
3. Ki_pbZevgu_yaudbijh]jZffbjh\Zgby................................................... 55
4. ;b[ebhl_dbbbgl_jn_ckuih^^_j`b\Zxsb_\aZbfh^_ckl\b_
iZjZee_evguoijhp_kkh\ .................................................................................... 55
5. Linda ............................................................................................................. 56
6. IZjZee_evgu_ij_^f_lgu_[b[ebhl_db ................................................... 56
7. Ki_pbZebabjh\Zggu_iZd_lubijh]jZffgu_dhfie_dku ..................... 56
8. AZ^Zgby........................................................................................................ 57
AZgylb_L_ogheh]bbihkljh_gbykmi_jdhfivxl_jh\DeZkl_jgu_l_ogheh]bb
h[ahj......................................................................................................................... 57
1. Ijhba\h^bl_evghklviZjZee_evguodhfivxl_jh\.................................. 57
2. DeZkkbnbdZpbyiZjZee_evguodhfivxl_jh\........................................... 59
3. <uqbkebl_evgu_deZkl_ju ........................................................................ 60
4. Kibkhd723 ........................................................................................... 61
3
5.
6.
7.
8.
KjZ\g_gb_dhffmgbdZpbhgguol_ogheh]bcihkljh_gbydeZkl_jh\ ..... 62
Kbkl_fuojZg_gby^Zgguo......................................................................... 64
<ukhdhijhba\h^bl_evgu_\uqbke_gby\Jhkkbb .................................... 67
AZ^Zgby........................................................................................................ 68
4
AZgylb_ <\_^_gb_ Dhjhldh h[ hi_jZpbhgghc kbkl_f_
UNIX
1. BklhqgbdbbgnhjfZpbb
<dZq_kl\_hkgh\gh]hbklhqgbdZbgnhjfZpbbih^Zgghfmdmjkmj_dhf_g^m_lky
BgnhjfZpbhggh-ZgZeblbq_kdbc P_glj ih iZjZee_evguf \uqbke_gbyf \ k_lb
Bgl_jg_lhttp://parallel.ru. <qZklghklbfgh]b_\hijhkudZkZxsb_kybkihevah\Zgby\uqbkebl_evgh]hdeZkl_jZGB<PF=Mih^jh[ghhk\_s_gu\jZa^_e_
http://parallel.ru/cluster/>ey[he__ih^jh[gh]hbamq_gby\hijhkh\k\yaZgguo
k l_fZlbdhc iZjZee_evguo \uqbke_gbc j_dhf_g^m_lky dgb]Z <<<h_\h^bg
<e<<h_\h^bg³IZjZee_evgu_\uqbke_gby´;O<-I_l_j[mj]klj
>eyhi_jZlb\gh]hjZaj_r_gby\hijhkh\\hagbdZxsboijbbkihevah\ZgbbdeZkl_jh\GB<PF=Mh[jZsZcl_kvihwe_dljhgghcihql_\kem`[mih^^_j`dbih
Z^j_kmsupport@parallel.ru.
2. IeZgaZgylbcijZdlbq_kdb_aZ^ZgbyiheblbdZ^hklmiZ
I_j\u_aZgylbygZijZ\e_gugZlhqlh[u^Zlvg_h[oh^bfucfbgbfmfbgnhjfZpbb ^ey gZqZeZ ijZdlbq_kdhc jZ[hlu gZ \uqbkebl_evghf deZkl_j_ GZklhyl_evghj_dhf_g^m_lkygZqbgZlv\uihegylvijZdlbq_kdb_aZ^Zgbyki_j\h]h`_
aZgylbyI_j\h_baij_^eZ]Z_fuoihke_dZ`^h]haZgylbyaZ^Zgbcy\ey_lkyh[yaZl_evguf ^ey \uiheg_gby hklZevgu_ aZ^Zgby j_dhf_g^m_lky \uihegylv ih
\hafh`ghklb >ey \uiheg_gby g_dhlhjuo aZ^Zgbc fh]ml ihlj_[h\Zlvky g_kdhevdh [hevrbc h[t_f agZgbc q_f aZljZ]b\Z_fuc \ ^Zgghf ihkh[bb qlh
^he`ghkem`blvklbfmehfd[he__iheghfmhk\h_gbxl_fu
IjZdlbq_kdZy jZ[hlZ gZ \uqbkebl_evghf deZkl_j_ GB<P F=M jZaj_rZ_lky
lhevdhkdhfivxl_jh\\u^_e_ggh]h^eywlh]hdhfivxl_jgh]hdeZkkZblhevdh\
h]h\hj_ggh_ \j_fy^eyijh\_^_gbyaZgylbc>eyihemq_gby\hafh`ghklb^hklmiZ gZ deZkl_j k ^jm]bo dhfivxl_jh\ beb \ ^jm]h_ \j_fy g_h[oh^bfh h[jZsZlvky\kem`[mih^^_j`dbdeZkl_jZ\bg^b\b^mZevghfihjy^d_
3. Dhjhldhh[hi_jZpbhgghckbkl_f_81,;
UNIX – wlh fgh]haZ^ZqgZy fgh]hihevah\Zl_evkdZy kbkl_fZ h[eZ^ZxsZy rbjhdbfb \hafh`ghklyfb ?_ j_ZebaZpbb kms_kl\mxl ijZdlbq_kdb gZ \k_o jZkijhkljZg_gguo dhfivxl_jguo ieZlnhjfZo ;he__ lh]h ih^Z\eyxs__ [hevrbgkl\h iZjZee_evguo dhfivxl_jh\ jZ[hlZ_l ih^ mijZ\e_gb_f lhc beb bghc
jZagh\b^ghklb UNIX gZijbf_j kmi_jdhfivxl_ju Cray - ih^ mijZ\e_gb_f
UNICOS, Hewlett-Packard - ih^ mijZ\e_gb_f HP-UX, IBM - ih^ mijZ\e_gb_f
AIX b l^ < qZklghklb \uqbkebl_evguc deZkl_j GB<P F=M jZ[hlZ_l ih^
5
mijZ\e_gb_f LINUX h^gh]h ba gZb[he__ ba\_klguo k\h[h^gh jZkijhkljZgy_fuo^bZe_dlh\UNIX.
<jZfdZo^Zggh]hdmjkZg_lg_h[oh^bfhklbb\hafh`ghklbhibku\Zlv\k_ih^jh[ghklbbijbgpbiuhj]ZgbaZpbbhi_jZpbhgghckbkl_fuhklZgh\bfkygZlhf,
qlhlj_[m_lky^eyghjfZevghcjZ[hluihevah\Zl_ey\^Zgghckj_^_
<k_h[t_dlu\UNIX^_eylkygZ^\ZlbiZnZceubijhp_kku<k_^Zggu_ojZgylky \ nZceZo ^hklmi d i_jbn_jbcguf mkljhckl\Zf hkms_kl\ey_lky q_j_a
ki_pbZevgu_nZceu<ky`_nmgdpbhgZevghklvhi_jZpbhgghckbkl_fuhij_^_ey_lky\uiheg_gb_fjZaebqguoijhp_kkh\
<Z`g_crbf ihevah\Zl_evkdbf ijhp_kkhf y\ey_lky hkgh\ghc dhfZg^guc bgl_jij_lZlhj (login shell) Ijb \oh^_ ihevah\Zl_ey \ kbkl_fm hg kijZrb\Z_l
mq_lgh_bfyihevah\Zl_eyloginbiZjhevpasswordihevah\Zl_eyI_j\h_qlh
gm`gh k^_eZlv ihke_ \oh^Z \ kbkl_fm k bkihevah\Zgb_f klZg^Zjlgh]h bebgZagZq_ggh]h Z^fbgbkljZlhjhf iZjhey - wlh ihf_gylv iZjhev ijb ihfhsb dhfZg^u passwd H[sbf ih`_eZgb_f ijb \u[hj_ gh\h]h iZjhey y\ey_lky ke_
^mxs__ iZjhev ^he`_g ohjhrh aZihfbgZlvky b [ulv ljm^guf ^ey ih^[hjZ
>eyaZ\_jr_gbyk_ZgkZjZ[hlugm`ghgZ[jZlvdhfZg^mexit.
>eylh]hqlh[uihkfhlj_lv\kljh_ggmx\kbkl_fmkijZ\dmhdhfZg^Zogm`gh
bkihevah\Zlv dhfZg^m man < qZklghklb qlh[u ihkfhlj_lv hibkZgb_ b dexqb
kZfhcdhfZg^umangm`ghgZ[jZlvdhfZg^mman man.
DZ`^uc ihevah\Zl_ev kbkl_fu bf__l mgbdZevgh_ bfy k dhlhjuf Zkkhpbbjm_lky b^_glbnbdZlhj ihevah\Zl_ey UID Bf_ggh wlh bfy bkihevam_lky ijb
\oh^_ \ kbkl_fm login Ihevah\Zl_ev y\ey_lky qe_ghf h^ghc beb g_kdhevdbo
]jmii k dhlhjufb k\yaZgu b^_glbnbdZlhju ]jmii GID IjbgZ^e_`ghklv d
]jmii_ hij_^_ey_l ^hihegbl_evgu_ ijZ\Z dhlhjufb h[eZ^Zxl \k_ ihevah\Zl_eb ]jmiiu BgnhjfZpbyhihevah\Zl_eyob]jmiiZoh[uqghojZgblky\kbkl_fguonZceZo/etc/passwd, /etc/shadowb/etc/group.
< UNIX \k_ fgh`_kl\h nZceh\ hj]Zgbah\Zgh \ \b^_ ^j_\h\b^ghc kljmdlmju
gZau\Z_fhc nZceh\hc kbkl_fhc DZ`^uc nZce bf__l bfy hij_^_eyxs__ _]h
jZkiheh`_gb_\nZceh\hckbkl_f_K\yavf_`^mbf_gZfbnZceh\bkh[kl\_ggh
nZceZfb h[_ki_qb\Z_lky ijb ihfhsb dZlZeh]h\ Dhjg_f nZceh\hc kbkl_fu
y\ey_lky dhjg_\hc dZlZeh] bf_xsbc bfy ³/´ Bf_gZ \k_o hklZevguo nZceh\
kh^_j`Zlimlv–kibkhddZlZeh]h\dhlhju_gm`ghijhclbqlh[u^hklbqvnZc
eZ Ijb wlhf bf_gZ dZlZeh]h\ jZa^_eyxlky agZdhf “/´ GZijbf_j,
“/home/asa/myfile.txt”. Ijbi_j_f_s_gbbihnZceh\hckbkl_f_l_dmsbcdZlZeh]gZau\Z_lky³.´ZdZlZeh]gZ_^bgbpm[he__\ukhdh]hmjh\gy³..´Djhf_
lh]hkdZ`^ufihevah\Zl_e_fZkkhpbbjm_lky_]h^hfZrgbcdZlZeh]\dhlhjhf
ihmfheqZgbxojZgylky_]hnZceu
6
NZceubdZlZeh]b\81,;bf_xlgZ[hjZljb[mlh\kj_^bdhlhjuo\Z`ghhlf_lblv\eZ^_evpZb]jmiimKbobkihevah\Zgb_fhj]Zgbam_lky]b[dh_jZa]jZgb
q_gb_ ^hklmiZ d nZceZf b dZlZeh]Zf >ey ijhkfhljZ \k_o Zljb[mlh\ nZceZ
fh`gh bkihevah\ZlvdhfZg^m ls –lJ_amevlZl\uiheg_gbydhfZg^u^eydZ`
^h]hnZceZ[m^_lbf_lvijbf_jghke_^mxsbc\b^
1
2 3
4
5
6
7
8
-rwxr-xr--
1 asa group 3422 Feb 28 13:30 test
< i_j\hf klhe[p_ \u^Zqb ijb\h^blky kibkhd ijZ\ ^hklmiZ d nZcem I_j\uc
kbf\he h[hagZqZ_l lbi nZceZ \ ^Zgghf kemqZ_ ³-´ hagZqZ_l h[uqguc nZce
^jm]b_\hafh`gu_agZq_gby³d” –dZlZeh]³l” –kkuedZb^j^Ze__b^mlljb
]jmiiuihljbkbf\heZaZ^Zxsb_kh[kl\_gghijZ\Z^hklmiZi_j\Zy]jmiiZba
lj_o kbf\heh\ – ijZ\Z ^ey \eZ^_evpZ-ihevah\Zl_ey ke_^mxsZy ]jmiiZ – ^ey
\eZ^_evpZ-]jmiiubihke_^gyy]jmiiZ–ijZ\Z^ey\k_ohklZevguoihevah\Zl_e_c Ijb wlhf ³-´ hagZqZ_l hlkmlkl\b_ ijZ\Z ^hklmiZ ³r” – ijZ\h gZ ql_gb_
nZceZ³w” –ijZ\hgZaZibkv\nZcebeb_]hm^Ze_gb_³x” –ijZ\hgZ\uiheg_gb_nZceZ<gZr_fijbf_j_\eZ^_e_pnZceZasabf__lijZ\ZgZql_gb_aZibkvb\uiheg_gb_rwxqe_gu]jmiiu-\eZ^_evpZgroupbf_xlijZ\ZgZql_gb_b\uiheg_gb_nZceZ ghg_bf_xlijZ\ZgZaZibkv\nZcer-xZ\k_hklZevgu_ihevah\Zl_ebbf_xllhevdhijZ\hgZql_gb_nZceZr--Kms_kl\m_l
lZd`_ g_kdhevdh ^hihegbl_evguo Zljb[mlh\ Z ^ey ^jm]bo lbih\ nZceh\ gZijbf_j ^ey dZlZeh]h\ ijb\_^_ggu_ Zljb[mlu fh]ml bf_lv g_kdhevdh bgh_
agZq_gb_
Kf_gblvijZ\Z^hklmiZdnZcemfh`ghijbihfhsbdhfZg^u
chmod [u g o a][+ - =][r w x] file1…
Ijbwlhf³u´hagZqZ_lkf_gmijZ\Z^hklmiZ^eyihevah\Zl_ey³g” –^ey]jmiiu
“o” –^ey^jm]boihevah\Zl_e_c³a” –kjZam^ey\k_olj_odZl_]hjbc³+´hagZqZ_l^h[Z\e_gb_khhl\_lkl\mxs_]hijZ\Z³-” –m^Ze_gb_Z³=” –ijbk\h_gb_
GZijbf_j ^ey ^h[Z\e_gby qe_gZf ]jmiiu group ijZ\Z aZibkb \ nZce test
gm`gh\uihegblvdhfZg^mchmod g+w test.
<eZ^_evp_f-ihevah\Zl_e_f\gh\vkha^Zggh]hnZceZy\ey_lkyihevah\Zl_evdhlhjuc_]hkha^ZeZ\eZ^_evp_f-]jmiihc–bebi_j\bqgZy]jmiiZ^Zggh]hihevah\Zl_eybebgZke_^m_lky]jmiiZijbibkZggZyl_dms_fmdZlZeh]m>eykf_gu
\eZ^_evpZ-ihevah\Zl_eyb\eZ^_evpZ-]jmiiunZceZkms_kl\mxldhfZg^u chown
bchgrpkhhl\_lkl\_ggh
JZkkfhljbfhkgh\gu_hi_jZpbbdhlhju_fh`ghijhba\h^blvknZceZfbbdZlZeh]Zfb
• cd [dir] –i_j_oh^\dZlZeh] dir?kebdZlZeh]g_mdZaZglhi_j_oh^hkms_kl\ey_lky\^hfZrgbcdZlZeh]ihevah\Zl_ey
• cp file1 file2 –dhibjh\Zgb_nZceZ
7
•
•
•
•
•
•
mv file1 file2 –i_j_f_s_gb_baf_g_gb_bf_gbnZceZ
rm file1… –m^Ze_gb_nZceh\
rmdir dir1… –m^Ze_gb_dZlZeh]h\
mkdir dir1… –kha^Zgb_dZlZeh]Z
pwd –\u\_klbbfyl_dms_]hdZlZeh]Z
cat file, more file, less file –mlbebluijhkfhljZkh^_j`b-
fh]hnZceZ
• find dir –ihbkd\nZceh\hckbkl_f_gZqbgZykdZlZeh]Zdir.
• grep j_]B\ujZ`_gb_! file1… – ihbkd \ nZceZo \oh`^_gbc j_]m
eyjgh]h\ujZ`_gbyj_]B\ujZ`_gb_.
• …
<lhjhclbih[t_dlh\\UNIX –wlhijhp_kkuIh^ijhp_kkhfmijhs_gghfh`gh
ihgbfZlvijh]jZffm\klZ^bb__\uiheg_gbyH^gh\j_f_ggh\kbkl_f_\uihegy_lky ^hklZlhqgh [hevrh_ qbkeh ijhp_kkh\ qZklv ba dhlhjuo y\ey_lky kbkl_fgufb Z qZklv – ihevah\Zl_evkdbfb >ey lh]h qlh[u ijhkfhlj_lv kibkhd
\uihegyxsbokyijhp_kkh\gm`gh\hkihevah\ZlvkydhfZg^hc psDZ`^ucijhp_kkbf__lg_dhlhjucgZ[hjZljb[mlh\\qZklghklbmgbdZevgucb^_glbnbdZlhjijhp_kkZPIDdhlhjucbkihevam_lky^eymijZ\e_gby_]hjZ[hlhcgZijbf_j ihkj_^kl\hf ihkuedb kb]gZeh\ >ey lh]h qlh[u aZ\_jrblv \uiheg_gb_
ijhp_kkZgm`ghihkeZlv_fmkhhl\_lkl\mxsbckb]gZedhfZg^hc kill –9 PID.
Kibkhd ijhp_kkh\ aZgbfZxsbo gZb[hevr__ dhebq_kl\h ijhp_kkhjgh]h \j_f_gbbebkbkl_fguoj_kmjkh\fh`ghihkfhlj_lvbkihevamydhfZg^mtop.
DZ`^Zy aZims_ggZy ijh]jZffZ ihemqZ_l ljb hldjuluo ihlhdZ \\h^Z\u\h^Z:
klZg^Zjlguc\\h^klZg^Zjlguc\u\h^bklZg^Zjlguc\u\h^hrb[hdIhmfheqZgbx\k_wlbihlhdbZkkhpbbjh\Zgukl_jfbgZehfh^gZdhfh]ml[ulvi_j_gZijZ\e_gugZ^jm]h_mkljhckl\hgZijbf_j\nZce>eyi_j_gZijZ\e_gbyklZg^Zjlgh]h\\h^Zfh`ghbkihevah\Zlvkbf\he³<´^eyklZg^Zjlgh]h\u\h^Z– “>”
beb³>>´k^h[Z\e_gb_f^eyihlhdZhrb[hd– “2>´GZijbf_j:
program > file.log
A^_kv aZimkdZ_lky ijh]jZffZ program Z __ klZg^Zjlguc \u\h^ i_j_gZijZ\ey_lky\nZcefile.log.
Fh`ghaZimklblvkjZamg_kdhevdhijh]jZfflZdqlhklZg^Zjlguc\u\h^h^ghc
i_j_^Z_lkyg_ihkj_^kl\_gghgZklZg^Zjlguc\\h^^jm]hc>eywlh]hbkihevam_lkydhgkljmdpby³|´gZau\Z_fZydhg\_c_jhfdhfZg^
program1 | program2 | program3…
DhfZg^udhg\_c_jZ\uihegyxlkyZkbgojhggufbijhp_kkZfbk\yavf_`^mdhlhjufbhkms_kl\ey_lkyq_j_akhhl\_lkl\mxsb_ihlhdb\\h^Z-\u\h^Z
Fh`ghaZimklblvijh]jZffm\nhgh\hfj_`bf_<wlhfkemqZ_g_[m^_lh`b^ZlvkyaZ\_jr_gb___\uiheg_gbyZkjZamihy\blkykbkl_fgh_ijb]eZr_gb_b
8
fh`gh[m^_lijh^he`blvjZ[hlm\dhfZg^ghfbgl_jij_lZlhj_>eywlh]hkljh
dmdhfZg^ug_h[oh^bfhaZ\_jrblvkbf\hehf³&”:
program &
Kibkhd ihevah\Zl_e_c jZ[hlZxsbo \ ^Zgguc fhf_gl \ kbkl_f_ fh`gh ihkfhlj_lv ijb ihfhsb dhfZg^u who G_dhlhju_ k\_^_gby h kbkl_f_ \u^Zxlky
ihdhfZg^_uname.
>eyj_^Zdlbjh\ZgbynZceh\\jZaguokbkl_fZofh]ml[ulvij_^mkfhlj_gujZaebqgu_ gZ[hju kj_^kl\ QZs_ \k_]h bf_xlky j_^Zdlhju vi, joe b ^jm]b_
fh`gh lZd`_ ihevah\Zlvky \kljh_gguf j_^Zdlhjhf nZceh\h]h f_g_^`_jZ
Midnight Commander (mc >jm]bf \hafh`guf \ZjbZglhf y\ey_lky m^Ze_ggh_
j_^Zdlbjh\Zgb_nZceh\kihke_^mxs_cboi_j_kuedhcgZp_e_\hcdhfivxl_j
DhfibeylhjkyaudZKbh[uqgh\uau\Z_lkydhfZg^hccc (CC^eyKbdhfibeylhjkyaudZNhjljZg– f77 (f90^eyNhjljZgZ
>ey m^Ze_ggh]h ^hklmiZ gZ ^jm]hc dhfivxl_j fh`gh ihevah\Zlvky dhfZg^hc
telnetbebssh^eyaZsbs_ggh]h^hklmiZZ^eydhibjh\ZgbynZceh\–dhfZg^hcftp^eyaZsbs_ggh]hsftpbebscp).
AZ^Zgby
• KhklZ\blv ijh]jZffm j_r_gby kbkl_f ebg_cguo Ze]_[jZbq_kdbo
mjZ\g_gbckd\Z^jZlghcg_\ujh`^_gghcfZljbp_cihjy^dZ nf_lh^hf=ZmkkZex[hc\ZjbZglf_lh^Zkbkihevah\Zgb_fyaudZKbbeb
NhjljZg
• < q_f kms_kl\_ggu_ hlebqby HK 81,; b :LQGRZV" DZd <u ^mfZ_l_ ihq_fm \uqbkebl_evgu_ deZkl_ju dZd ijZ\beh jZ[hlZxl
ih^mijZ\e_gb_f81,;Zi_jkhgZevgu_dhfivxl_ju–ih^mijZ\e_gb_f:LQGRZV"
• Fh`_lebh^bgnZcegZoh^blkykjZam\^\mo^bj_dlhjbyo\nZceh\hckbkl_f_81,;"
• DZdb_ijZ\Z^he`gu[ulvmnZceZqlh[u_]hfh]ebqblZlvibkZlv
bbkihegylv\k_ihevah\Zl_eb djhf__]h\eZ^_evpZ"<hafh`gheb
lZdh_\hh[s_"
• ?kebijh]jZffZaZims_gZ\nhgh\hfj_`bf_dZd__fh`ghaZ\_jrblv"
• Fh`ghebh^ghcdhfZg^hcjZaj_rblvql_gb_b\uiheg_gb_ghaZ
ij_lblvaZibkv^eydZdh]h-lhnZceZ"
• DZdaZij_lblvaZibkv\nZcekmgbdZevgufbf_g_fghg_ba\_klguf
f_klhgZoh`^_gb_f"
• Fh`gh eb h^ghc dhfZg^hc m^Zeblv \kx nZceh\mx kbkl_fm gZqbgZykdhjg_\h]hdZlZeh]Z"Qlhfh`_lwlhfmihf_rZlv"
9
• <u\_klbgZwdjZgkljhdmkh^_j`Zsmx3,'aZ^Zgghcijh]jZffu
• <u\_^bl_ gZ ^bkie_c kh^_j`bfh_ <Zr_]h ^hfZrg_]h dZlZeh]Z
\dexqZyih^dZlZeh]b.
• DZd kha^Zlv nZce \ bf_gb dhlhjh]h _klv ijh[_e" Ijb\_^bl_ _s_
h^bgkihkh[g_baf_gyybf_gbdhfZg^udhlhjhc<u\hkihevah\Zebkv^eyj_r_gby
• <u\_^bl_ gZ wdjZg kibkhd ijhp_kkh\ gZa\Zgby dhlhjuo kh^_j`Zl
'getty
[_adZ\uq_ddjhf_ijhp_kkh\ihjh`^_gguo<Zrbfihbkdhf
• <u\_^bl_gZwdjZgkibkhd\k_obkihegyxsbokyijhp_kkh\hij_^_e_ggh]hihevah\Zl_ey
• Ijh]jZffZabcdefh`_laZ\_jrZlvkymki_rghbg_mki_rghDZdaZimklblvijh]jZffmabcdelZdqlh[uijbg_mki_rghfaZ\_jr_gbb\
nZce /tmp/run-result \u\h^beZkv kljhdZ ³abcde failed´" DZd fh^bnbpbjh\Zlvihemq_ggmx<ZfbdhfZg^gmxkljhdmlZdbfh[jZahf
qlh[u\wlhlnZce\u\h^bekybdh^aZ\_jr_gbyijh]jZffu"
• DZdk^_eZlvlZdqlh[udhfZg^Zrm\k_]^ZaZijZrb\ZeZih^l\_j`^_gb_ m^Ze_gby nZceh\" DZd k^_eZlv lZd qlh[uwlhk\hckl\hkhojZgyehkvf_`^mk_ZgkZfbjZ[hlu"
• DZdi_j_bf_gh\Zlv\k_nZceukbf_gZfb myproj*\khhl\_lkl\mxsb_myproj*.old\dexqZynZceu\h\k_oih^dZlZeh]Zo"
AZgylb_<uqbkebl_evgucdeZkl_jGB<PF=M
1. :jobl_dlmjZdeZkl_jZ6&,
<gZklhysbcfhf_gl\GB<PF=MmklZgh\e_ghljb\uqbkebl_evguodeZkl_jZ
SKY, SCI b AQUA DeZkl_j SKY ij_^klZ\ey_l kh[hc \uqbkebl_evgmx n_jfm
ba^\moijhp_kkhjguomaeh\kijhp_kkhjZfbPentium IIIF=pkh_^bg_gguo
dhffmgbdZpbhgghc k_lvx )DVW (WKHUQHW b bkihevam_lky ij_bfms_kl\_ggh ^ey
aZimkdZh^ghijhp_kkhjguobebkeZ[hk\yaZgguofgh]hijhp_kkhjguoaZ^Zq>ey
\uiheg_gbyijZdlbq_kdboaZ^Zgbcij_^hklZ\ey_lky^hklmiddeZkl_jmSCIihwlhfmgZ_]hZjobl_dlmj_hklZgh\bfkygb`_ih^jh[g__DeZkl_jAQUAihoh`
ihk\h_cZjobl_dlmj_gZdeZkl_jSCIghihkljh_ggZ[he__fhsguoijhp_kkhjZob\g_fbkihevamxlky[he__gh\u_ijh]jZffgh-ZiiZjZlgu_j_r_gbyIh^jh[gmx bgnhjfZpbx h deZkl_jZo GB<P F=M fh`gh gZclb gZ kljZgbp_
http://parallel.ru/cluster/.
DeZkl_j SCI ihkljh_g gZ [Za_ ^\moijhp_kkhjguo maeh\ k ijhp_kkhjZfb
3HQWLXP,,,Maeuh[t_^bgyxlky\^\mof_jgmxj_r_ldmkihfhsvx\ukhdhkdh
jhklghc k_lb 6&, Scalable Coherent Interface < dZq_kl\_ kem`_[ghc k_lb bk
ihevam_lky )DVW (WKHUQHW >hihegbl_evgh mklZgh\e_g h^ghijhp_kkhjguc dhf
ivxl_jbkihevam_fuc\dZq_kl\_]heh\ghcfZrbgu^eyaZ]jmadbaZ^ZqgZdeZ
10
kl_jZlZd`_fhsgucnZce-k_j\_jk5$,'-fZkkb\hfMklZgh\e_gZlZd`_ki_
pbZevgZyjZ[hqZyklZgpbyhjb_glbjh\ZggZygZaZ^Zqb\bamZebaZpbb
KljmdlmjZ\uqbkebl_evgh]hdeZkl_jZdeZkl_j6&,
ijhp_kkhjh\ 3HQWLXP ,,,0+] 'ROSKLQ 6&, ^\mf_jguc lhj ijhba\h^bl_evghklv *)/236
<uqbkebl_evguc ma_e
[ 3HQWLXP ,,, F=p
iZfylv =[Zcl 'ROSKLQ :XOINLW
HK 5HG+DW /LQX[
VFL
VFL
VFL
VFL
VFL
VFL
DhffmlZlhj )DVW (WKHUQHW
VFL
VFL
VFL
VFL
VFL
VFL
=heh\gZy fZrbgZ
3HQWLXP ,,, F=p
F[Zcl iZfylb
VFL
VFL
VFL
VFL
VFL
VFL
NZcek_j\_j
3HQWLXP ,,, F=p
5$,'fZkkb\ =[
Kljbf_j =[
<gZklhys__\j_fymaeh\deZkl_jZSCIh[t_^bg_gu\^\mof_jgmxj_r_ldm
[ DZ`^uc ma_e bf__l h^ghgZijZ\e_ggmx k\yav kh ke_^mxsbf ih ]hjbahglZebbih\_jlbdZebihke_^gbcbf__lk\yavki_j\ufLZdbfh[jZahfdZ`^uc
ma_eijbkmlkl\m_l\^\moh^ghgZijZ\e_gguodhevpZoaZhj]ZgbaZpbxh[f_gh\
ih dhlhjuf hl\_qZxl hkgh\gZy b ^hq_jgyy dZjlu 6&, 6&,-dhgljhee_ju \ khklZ\_dhfie_dlZ:XOINLWh[_ki_qb\ZxlfZjrjmlbaZpbxf_`^mdhevpZfbgZZiiZjZlghfmjh\g_<kemqZ_\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_gbcf_lh^hf/8-jZaeh`_gbyIjbj_r_gbbkbkl_fumjZ\g_gbc k fZljbp_c [ gZ ijhp_kkhjZo deZkl_jZ 6&, [ueZ ihemq_gZ
ijhba\h^bl_evghklvhdheh=nehikfbeebZj^h\hi_jZpbckieZ\Zxs_clhq
dhc\k_dmg^m
2. <oh^gZdeZkl_j
M^Ze_gguc ^hklmi d \uqbkebl_evghfm deZkl_jm hkms_kl\ey_lky q_j_a ]heh\gmx fZrbgm cluster.parallel.ru G_ihkj_^kl\_gguc l_jfbgZevguc ^hklmi gZ
maeu deZkl_jZ g_\hafh`_g < gZklhysbc fhf_gl m^Ze_gguc l_jfbgZevguc
^hklmigZdeZkl_jhkms_kl\ey_lkyihijhlhdhem66+\_jkbb66+ihdZlZd
`_ ih^^_j`b\Z_lky < 8QL[ wlhl ijhlhdhe ih^^_j`b\Z_lky klZg^Zjlghc dhfZg^hc ssh < kj_^_ :LQGRZVfh`ghihevah\Zlvkyl_jfbgZevghcijh]jZffhc
TeraTerm k ^hihegbl_evguf fh^me_f ^ey ih^^_j`db 66+ beb ^jm]bfb ijh]jZffZfbTelneat, SSHSecureShellClient, sshNT.exe, PuTTYb^j
<k\yabkijh[e_fZfb[_ahiZkghklbijhlhdheZ)73i_j_^ZqZnZceh\gZdeZkl_j
hkms_kl\ey_lkyih^jm]bfijhlhdheZflZdbfdZdscp, Zmodem, SFTPb^j
3. Dhfibeypby
>ey dhfibeypbb 03,-ijbeh`_gbc j_dhf_g^m_lky ihevah\Zlvky dhfZg^Zfb
mpicc^eyijh]jZffgZKmpiCC^eyijh]jZffgZKbmpif77/mpif90^ey
ijh]jZffgZNhjljZg_HipbydhfibeylhjZ³-o name´iha\hey_laZ^Zlv
bfy name ^ey ihemqZ_fh]h \uihegbfh]h nZceZ ih mfheqZgbx \uihegbfuc
nZce gZau\Z_lky a.out >ey hilbfbaZpbb j_dhf_g^m_lky bkihevah\Zlv dexq
dhfibeylhjZ³-fast´gZijbf_j
mpif77 -fast -o program program.f
?kebg_h[oh^bfhlhevdhkdhfibebjh\Zlvh^bgh[t_dlgucfh^mevbg_\uihegylvebgdh\dmbkihevam_lkyhipby³-k´gZijbf_j
mpiCC -c program2.C
12
>ey k[hjdb fgh]hfh^mevguo ijbeh`_gbc p_e_khh[jZagh ihevah\Zlvky mlbeblhc makeIjhkl_crb_ijbf_ju03,-ijh]jZffgZyaudZoKbbNhjljZg
^hklmigugZdeZkl_j_\dZlZeh]_/usr/local/examples.
4. Kbkl_fZhq_j_^_c
Kbkl_fZ mijZ\e_gby hq_j_^yfb Cleo (http://parallel.ru/cluster/batch.html)
ij_^gZagZq_gZ^eymijZ\e_gbyijhoh`^_gb_faZ^ZqgZfgh]hijhp_kkhjguo\uqbkebl_evguomklZgh\dZo\lhfqbke_deZkl_jguoHgZiha\hey_lZ\lhfZlbq_kdbjZkij_^_eylv\uqbkebl_evgu_j_kmjkuf_`^maZ^ZqZfbmijZ\eylvihjy^dhfboaZimkdZ\j_f_g_fjZ[hluihemqZlvbgnhjfZpbxhkhklhygbbhq_j_^_c
< gZklhys__ \j_fy gZ deZkl_j_ SCI knhjfbjh\Zgu ^\Z g_aZ\bkbfuo ih^jZa^_eZ³long´^ey^ebl_evguoaZ^Zqb³short´^eydhjhldboaZ^ZqIhmfheqZgbx \h \k_o dhfZg^Zo bkihevam_lky hq_j_^v mdZaZggZy \ i_j_f_gghc hdjm`_gby QS_QUEUE AgZq_gb_ wlhc i_j_f_gghc fh`gh baf_gblv \ nZce_
~/.bash_profile dhfZg^hc³export QS_QUEUE=short”.
AZ^ZqZklZ\blky\hq_j_^vh[uqghcdhfZg^hcaZimkdZMPI-ijbeh`_gbc\d\Z^jZlguokdh[dZomdZaZgug_h[yaZl_evgu_iZjZf_lju
mpirun -np N [-q Q] [-maxtime T] [-p P@ijh]jZffZkZj]mf_glZfb!,
]^_ N -qbkehijhp_kkhjh\dhlhjh_^he`gh[ulvg_[he__jZaj_r_ggh]hqbkeZ
ijhp_kkhjh\^eyh^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
dhlhjuo[ueZaZims_gZijh]jZffZ
4. Web-bgl_jn_ckaZimkdZaZ^ZqgZ\uqbkebl_evghfdeZkl_j_
>eylh]hqlh[uex[hcihevah\Zl_evg_bkdmr_gguc\\hijhkZojZkiZjZee_eb
\Zgby fh] m\b^_lv wnn_dl hl bkihevah\Zgby iZjZee_evguo ijh]jZff gZ \u
qbkebl_evghfdeZkl_j_GB<PF=Mij_^mkfhlj_gZ\hafh`ghklvaZimkdZg_dh
lhjuol_klh\uoijbf_jh\ihkj_^kl\hfWeb-bgl_jn_ckZ
L_klh\uciheb]hg (http://parallel.ru/polygon/)ij_^gZagZq_g^eyhi_jZlb\gh]h
^hklmiZd\uqbkebl_evgufj_kmjkZf^eyijh\_^_gbyg_[hevrboij_^\Zjbl_ev
guowdki_jbf_glh\b\u[hjZ\uqbkebl_evghcieZlnhjfu=eZ\gh_qlhgm`gh
ihgylvihevah\Zl_ex\gZqZe_jZ[hluwlhgZdZdhclbi\uqbkebl_eyhjb_glb
jh\Zlvky Hkgh\guoiZjZf_ljh\g_kdhevdh\u[hjf_`^mdhfivxl_jZfbkh[
s_cbebjZkij_^_e_gghciZfylvxkhhlghr_gb_f_`^mkdhjhklvxijhp_kkhjh\
b kdhjhklvx h[f_gZ ^Zggufb \ dhffmgbdZpbhgghc kj_^_ \u[hj l_ogheh]bb
iZjZee_evgh]hijh]jZffbjh\Zgby\u[hjZe]hjblfbq_kdh]hih^oh^Zbg_dhlh
ju_^jm]b_
AZimkdZy l_klh\u_ aZ^Zqb gZ ij_^hklZ\ey_fuo ijh]jZffgh-ZiiZjZlguo ieZl
nhjfZoihevah\Zl_evfh`_lhp_gblvwnn_dlb\ghklvj_ZebaZpbbl_obebbguo
dhffmgbdZpbhgguo ko_f ijb bkihevah\Zgbb jZaebqguo k_l_\uo l_ogheh]bc
gZgZklhysbcfhf_gl6&,b)DVW(WKHUQHWkjZ\gblvwnn_dlb\ghklvjZaebqguo
dhgkljmdpbc ij_^hklZ\ey_fuo l_ogheh]byfb iZjZee_evgh]h ijh]jZffbjh\Z
gby gZijbf_j jZaebqguo \ZjbZglh\ i_j_kuehd beb ]eh[Zevguo hi_jZpbc \
03,Z\dhg_qghfblh]_hp_gblvij_^iheZ]Z_fmxwnn_dlb\ghklv\hafh`guo
iZjZee_evguo j_ZebaZpbc kh[kl\_gghc aZ^Zqb gZ ij_^hklZ\ey_fuo \uqbkeb
l_evguoj_kmjkZo
GZ^Zggucfhf_gl\L_klh\hfiheb]hg_j_Zebah\Zguke_^mxsb_lbih\u_Ze
]hjblfbq_kdb_kljmdlmjuf_`ijhp_kkhjgh]h\aZbfh^_ckl\by
• i_j_kq_lwe_f_glh\ijyfhm]hevghcfZljbpuihba\_klghfmaZdhgmq_j_a
khk_^gb_we_f_glukaZ^Zgghcrbjbghc]jZgbqghch[eZklb
• jZaebqgu_\ZjbZgluj_ZebaZpbbi_j_kuedb^ZgguohldZ`^h]hijhp_kkh
jZdZ`^hfm
15
• jZaebqgu_\ZjbZgluj_ZebaZpbbi_j_kuedb^Zgguoihdhevp_\hclhiheh
]bb
• jZaebqgu_ \ZjbZglu j_ZebaZpbb ^\mgZijZ\e_gguo i_j_kuehd ^Zgguo
f_`^m^\mfy\u^_e_ggufbijhp_kkhjZfb
Bkihevamy ZHE-bgl_jn_ck ihevah\Zl_ev nhjfbjm_l aZijhk gZ \u[hj p_e_\hc
ijh]jZffgh-ZiiZjZlghckj_^ubmdZau\Z_lbgl_j_kmxs___]hl_klh\h_ijbeh
`_gb_HibjZykvdZdgZ^hklmiguciZjd\uqbkebl_evguokbkl_fP_gljZlZdb
gZ\hafh`ghklvhi_jZlb\gh]hmijZ\e_gbyjZkij_^_e_gb_faZ^Zgbcf_`^mkbk
l_fZfbijhbkoh^blaZimkdl_klh\h]hijbeh`_gbyb\ha\jZlj_amevlZlh\ihev
ah\Zl_exGZ^Zggucfhf_gl\dZq_kl\_ZiiZjZlguoieZlnhjfL_klh\h]hiheb
]hgZij_^hklZ\eyxlky\uqbkeb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bgml Djhf_ lh]h \_^_lky iheguc ijhlhdhe
bkihevah\ZgbyL_klh\h]hiheb]hgZ\k_fbihevah\Zl_eyfb
5. AZ^Zgby
• Ijh\_jblv gZ l_klh\hc fZljbp_ ijZ\bevghklv \uiheg_gby ijh
]jZffu j_r_gby kbkl_f ebg_cguo Ze]_[jZbq_kdbo mjZ\g_gbc f_
lh^hf=ZmkkZaZf_jblv\j_fy\uiheg_gbybkke_^h\Zlv\hafh`gh
klbdhfibeylhjZihhilbfbaZpbb\uiheg_gby^Zgghcijh]jZffu
• Hldhfibebjh\Zlv b ijh\_jblv wnn_dlb\ghklv \uiheg_gby ijh
]jZffu \uqbke_gby qbkeZ Ib gZ jZaebqghf qbke_ ijhp_kkhjh\
(/usr/local/examples/mpi/cpi.c beb fpi.f).
• >ey q_]h gZdeZkl_j_gm`gZ[ukljZyk_lv">eydZdboaZ^Zq^hklZ
lhqgh-f_]Z[blghck_lb"
16
• DZdb_ij_bfms_kl\Zbf__ll_ogheh]bySCIi_j_^Fast Ethernetijb
ihkljh_gbbdeZkl_jguokbkl_f"
• DZdh\u^hklhbgkl\Zbg_^hklZldbjZkiheh`_gby^hfZrgbodZlZeh
]h\ihevah\Zl_e_cgZnZce-k_j\_j_Zg_gZehdZevghf^bkd_"
• DZdmagZlvdlh_s_baihevah\Zl_e_cjZ[hlZ_l\^Zggucfhf_glgZ
deZkl_j_bqvbaZ^Zqbk_cqZkkqblZxlky"
• P_e_khh[jZagh eb aZimkdZlv gZ h^ghf ^\moijhp_kkhjghf mae_
[hevr_^\mokq_lguoijhp_kkh\"Fh]mlebgZh^ghfZdeZkl_j_[
mae_\ijhp_kkhj_h^gh\j_f_gghkqblZlvkyaZ^ZqbjZaguoihevah
\Zl_e_c"
• DZd<u^mfZ_l_gZqlhij_`^_\k_]hih\eby_lbaf_g_gb_jZaf_j
ghklbj_r_ldbdeZkl_jZkdhffmgbdZpbhgghck_lvxSCIgZijbf_j
kjZ\gbl_\ZjbZgludhgnb]mjZp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^gh\j_f_ggh]h\uiheg_gby
g_kdhevdbo ^_ckl\bc bf__l ^\_ jZagh\b^ghklb dhg\_c_jghklv b kh[kl\_ggh
iZjZee_evghklv H[Z \b^Z iZjZee_evghc h[jZ[hldb bglmblb\gh ihgylgu ih
wlhfmk^_eZ_febrvg_[hevrb_ihykg_gby
17
IZjZee_evgZyh[jZ[hldZ?kebg_dh_mkljhckl\h\uihegy_lh^gmhi_jZpbxaZ
_^bgbpm \j_f_gb lh lukyqm hi_jZpbc hgh \uihegbl aZ lukyqm _^bgbp ?keb
ij_^iheh`blv qlh bf__lky iylvlZdbo`_g_aZ\bkbfuomkljhckl\kihkh[guo
jZ[hlZlvh^gh\j_f_gghbg_aZ\bkbfhlhlm`_lukyqmhi_jZpbckbkl_fZbaiy
lbmkljhckl\fh`_l\uihegblvm`_g_aZlukyqmZaZ^\_klb_^bgbp\j_f_gb
:gZeh]bqgh kbkl_fZ ba 1 mkljhckl\ lm `_ jZ[hlm \uihegbl ijbf_jgh aZ
1_^bgbp\j_f_gb
Dhg\_c_jgZyh[jZ[hldZQlhg_h[oh^bfh^eykeh`_gby^\mo\_s_kl\_gguoqb
k_eij_^klZ\e_gguo\nhjf_kieZ\Zxs_caZiylhc"P_eh_fgh`_kl\hf_edbo
hi_jZpbc lZdbo dZd kjZ\g_gb_ ihjy^dh\ \ujZ\gb\Zgb_ ihjy^dh\ keh`_gb_
fZglbkkghjfZebaZpbybliIjhp_kkhjui_j\uodhfivxl_jh\\uihegyeb\k_
wlb ³fbdjhhi_jZpbb´ ^ey dZ`^hc iZju Zj]mf_glh\ ihke_^h\Zl_evgh h^gZ aZ
^jm]hc^hl_oihjihdZg_^hoh^beb^hhdhgqZl_evgh]hj_amevlZlZbebrvih
ke_wlh]hi_j_oh^bebdh[jZ[hld_ke_^mxs_ciZjukeZ]Z_fuo
B^_y dhg\_c_jghc h[jZ[hldb aZdexqZ_lky \ \u^_e_gbb hl^_evguo wlZih\ \u
iheg_gbyh[s_chi_jZpbb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h\Zl_evgh_lh\j_fyh[jZ[hldb[m^_ljZ\ghl×n<j_amevlZl_ihemqbfmk
dhj_gb_ihqlb\ljZaaZkq_lbkihevah\Zgbydhg\_c_jghch[jZ[hldb^Zgguo
DZaZehkv[udhg\_c_jgmxh[jZ[hldmfh`ghkmki_ohfaZf_gblvh[uqgufiZ
jZee_ebafhf ^ey q_]h ijh^m[ebjh\Zlv hkgh\gh_ mkljhckl\h klhevdh jZa
kdhevdh klmi_g_c dhg\_c_jZ ij_^iheZ]Z_lky \u^_eblv H^gZdh klhbfhklv b
18
keh`ghklvihemqb\r_ckykbkl_fu[m^_lg_khihklZ\bfZkhklhbfhklvxbkeh`
ghklvxdhg\_c_jgh]h\ZjbZglZZijhba\h^bl_evghklv[m^_lihqlblZdhc`_
>eylh]hqlh[ugZibkZlviZjZee_evgmxijh]jZffmg_h[oh^bfh\u^_eblv\g_c
]jmiiuhi_jZpbcdhlhju_fh]ml\uqbkeylvkyh^gh\j_f_gghbg_aZ\bkbfhjZa
gufb ijhp_kkhjZfb nmgdpbhgZevgufb mkljhckl\Zfb beb `_ jZagufb klmi_
gyfbdhg\_c_jZ
<hafh`ghklv wlh]h hij_^_ey_lky gZebqb_f beb hlkmlkl\b_f \ ijh]jZff_ bk
lbgguobgnhjfZpbhgguoaZ\bkbfhkl_c>\_hi_jZpbbijh]jZffuZ\^Zgghf
kemqZ_ih^hi_jZpb_cfh`ghihgbfZlvdZdhl^_evgh_kjZ[Zlu\Zgb_g_dhlhjh]h
hi_jZlhjZlZdb[he__djmigu_dmkdbdh^Zijh]jZffugZau\ZxlkybgnhjfZ
pbhgghaZ\bkbfufb_kebj_amevlZl\uiheg_gbyh^ghchi_jZpbbbkihevam_lky\
dZq_kl\_ Zj]mf_glZ \^jm]hcHq_\b^ghqlh_kebhi_jZpbyBbgnhjfZpbhggh
aZ\bkblhlhi_jZpbbAlh_klvbkihevam_ldZdb_-lhj_amevlZluhi_jZpbbA\
dZq_kl\_ k\hbo Zj]mf_glh\ lh hi_jZpby B fh`_l [ulv \uiheg_gZ lhevdh ih
aZ\_jr_gbbhi_jZpbbAK^jm]hcklhjhgu_kebhi_jZpbbAbBg_y\eyxlky
bgnhjfZpbhggh aZ\bkbfufb lh Ze]hjblfhf g_ gZdeZ^u\Z_lky gbdZdbo h]jZ
gbq_gbc gZ ihjy^hd bo \uiheg_gby \ qZklghklb hgb fh]ml [ulv \uiheg_gu
h^gh\j_f_ggh LZdbf h[jZahf aZ^ZqZ jZkiZjZee_eb\Zgby ijh]jZffu h[uqgh
k\h^blkydgZoh`^_gbx\g_c^hklZlhqgh]hdhebq_kl\ZbgnhjfZpbhgghg_aZ\b
kbfuo hi_jZpbc jZkij_^_e_gbx bo f_`^m \uqbkebl_evgufb mkljhckl\Zfb
h[_ki_q_gbxkbgojhgbaZpbbbg_h[oh^bfuodhffmgbdZpbc
<\_^_ggh_ ihgylb_ bgnhjfZpbhgghc aZ\bkbfhklb y\ey_lky ^hklZlhqgh ijh
kluf gh bkke_^h\Zgb_ \k_]h gZ[hjZ bgnhjfZpbhgguo aZ\bkbfhkl_c kms_kl
\mxsbo\j_Zevghcijh]jZff_y\ey_lky\_kvfZkeh`ghcaZ^Zq_c>hklZlhqgh
ij_^klZ\blv k_[_ ijh]jZffm khklhysmx ba ^_kyldh\ lukyq hi_jZlhjh\ b
mq_klv qlh dZ`^uc pbde fh`_l khklhylv ba h]jhfgh]h dhebq_kl\Z bl_jZpbc
qlh[uijbf_jghij_^klZ\blvk_[_keh`ghklv\hagbdZxsboijh[e_f>eylh]h
qlh[unhjfZebah\ZlvaZ^Zqmbh[e_]qblvZgZeba\\h^blkyihgylb_]jZnh\bg
nhjfZpbhgguoaZ\bkbfhkl_c
<_jrbgZfb\lZdbo]jZnZoh[uqghy\eyxlkyg_dhlhju_hi_jZpbbijh]jZffuZ
\ kemqZ_ _keb f_`^m ^\mfy hi_jZpbyfb kms_kl\m_l bgnhjfZpbhggZy aZ\bkb
fhklvlhkhhl\_lkl\mxsb_w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jZffg_h[oh^bfubgkljmf_glZevgu_ijh]jZffgu_kj_^kl\Z
2. Bkihevah\Zgb_iZjZee_ebafZ
Ij_^iheh`bfl_i_jvqlhfugZmqbebkvdZdbf-lhh[jZahfkljhblvbbkke_^h
\Zlv bgnhjfZpbhggmx bklhjbx \uiheg_gby ijh]jZffu <u^_eb\ \ g_c fgh
`_kl\ZbgnhjfZpbhgghg_aZ\bkbfuohi_jZpbcijboh^bfd\hijhkmdZdbf`_
h[jZahf jZkij_^_eylv wlb fgh`_kl\Zf_`^mijhp_kkhjZfbbeb^jm]bfbh[jZ
[Zlu\Zxsbfbmkljhckl\Zfb"
>hklZlhqghhq_\b^gufkihkh[hf[m^_lke_^mxsbcIhf_lbf\bgnhjfZpbhg
ghcbklhjbbl_hi_jZpbbdhlhju_aZ\bkyllhevdhhl\g_rgbo^Zgguoijh]jZf
fubkdZ`_fqlhlZdb_hi_jZpbbijbgZ^e_`Zldi_j\hfmyjmkmbgnhjfZpbhg
ghcbklhjbbGZ\lhjhcyjmkihf_klbfhi_jZpbbaZ\bkysb_lhevdhhlhi_jZ
pbci_j\h]hyjmkZb\g_rgbo^ZgguoblZd^Ze__JZkij_^_eb\lZdbfh[jZahf
hi_jZpbb bgnhjfZpbhgghc bklhjbb ihemqZ_f __ \b^ gZau\Z_fuc yjmkghiZjZee_evghc nhjfhc ijh]jZffu Dhebq_kl\h yjmkh\ yjmkgh-iZjZee_evghc
nhjfu gZau\Z_lky ^ebghc djblbq_kdh]h imlb Ih ihkljh_gbx hi_jZpbb ih
iZ\rb_gZh^bgyjmkg_fh]mlkhklhylv\hlghr_gbbbgnhjfZpbhgghcaZ\bkb
fhklbZagZqblfh]ml[ulv\uiheg_guh^gh\j_f_gghLZdbfh[jZahfijhp_kk
ihemq_gbyiZjZee_evghcijh]jZffufh`_l[ulvke_^mxsbfkgZqZeZjZkij_
^_ey_f f_`^m ijhp_kkhjZfb hi_jZpbb i_j\h]h yjmkZ ihke_ ba aZ\_jr_gby –
hi_jZpbb\lhjh]hyjmkZbl^Ihkdhevdmex[Zyhi_jZpbyn-]hyjmkZaZ\bkbloh
ly[uhlh^ghchi_jZpbbn-1)-]hyjmkZlh__g_evaygZqZlv\uihegylvjZgvr_
q_f aZ\_jrblky \uiheg_gb_ hi_jZpbc ij_^u^ms_]h yjmkZ Z agZqbl yjmkghiZjZee_evgZynhjfZij_^klZ\ey_lkh[hc\hij_^_e_gghfkfuke_fZdkbfZevgh
iZjZee_evgmxj_ZebaZpbxijh]jZffuIjbwlhf^ebgZdjblbq_kdh]himlboZ
jZdl_jbam_ldhebq_kl\hiZjZee_evguorZ]h\g_h[oh^bfuo^ey__\uiheg_gby
H^gZdhyjmkgh-iZjZee_evgZynhjfZihqlbgbdh]^Zg_bkihevam_lky^eyijZdlb
q_kdh]hjZkiZjZee_eb\Zgbyijh]jZffIjbqbghcwlh]hy\ey_lkylhqlhhibkZg
guc kihkh[ jZkiZjZee_eb\Zgby iehoh kh]eZkh\Zg dZd k dhgkljmdpbyfb j_Zev
guoyaudh\ijh]jZffbjh\ZgbylZdbkZjobl_dlmjgufbhkh[_gghklyfbkh\j_
f_gguo dhfivxl_jh\ Qlh[u m[_^blvky \ wlhf fh`_l_ ihijh[h\Zlv kdhgkl
jmbjh\ZlvlZdbfkihkh[hfiZjZee_evgmxj_ZebaZpbxijZdlbq_kdbex[h]hZe
20
]hjblfZbhp_gblvdZdkeh`ghklvgZibkZgbylZdhcijh]jZffulZdbdhebq_kl
\hg_h[oh^bfuodhffmgbdZpbcf_`^mijhp_kkhjZfb
< j_Zevghklb]hjZa^hqZs_bkihevamxlky^jm]b_kihkh[ujZkiZjZee_eb\Zgby
bkihevamxsb_ oZjZdl_jgu_ hkh[_gghklb gZb[he__ jZkijhkljZg_gguo yaudh\
ijh]jZffbjh\ZgbyLZdkZfufijhkluf\ZjbZglhfjZkij_^_e_gbyjZ[hlf_`
^m ijhp_kkhjZfb y\ey_lky ijbf_jgh ke_^mxsZy dhgkljmdpby djmigh[ehqgh_
jZkiZjZee_eb\Zgb_):
if (MyProc
...
if (MyProk
...
^hi_jZpbb\uihegy_fu_-ufijhp_kkhjhf`
K^hi_jZpbb\uihegy_fu_K-ufijhp_kkhjhf`
Ijbwlhfij_^iheZ]Z_lkyqlhdZ`^ucijhp_kkhjdZdbf-lhh[jZahffh`_lih
emqblvmgbdZevgucghf_jijbk\hblv_]hi_j_f_gghc MyProcbbkihevah\Zlv\
^Zevg_cr_f^eyihemq_gbymqZkldZdh^Z^eyg_aZ\bkbfh]hbkiheg_gbyLZdbf
h[jZahf\ijb\_^_gghfijbf_j_hi_jZpbb\i_j\uonb]mjguokdh[dZo[m^ml
\uiheg_gu lhevdh ijhp_kkhjhf k ghf_jhf 0 hi_jZpbb \h \lhjuo nb]mjguo
kdh[dZo–ijhp_kkhjhfkghf_jhf Kbl^Ijbwlhf_kl_kl\_gghg_h[oh^bfh
qlh[u h^gh\j_f_ggh jZagu_ ijhp_kkhju fh]eb \uihegylv lhevdh [ehdb bg
nhjfZpbhggh g_aZ\bkbfuo hi_jZpbc qlh fh`_l ihlj_[h\Zlv hi_jZpbc kbg
ojhgbaZpbbijhp_kkhjh\ZlZd`_ijbg_h[oh^bfhklbgm`ghh[_ki_qb\Zlvh[
f_g^Zggufbf_`^mijhp_kkhjZfb
H^gZdh ^Ze_dh g_ \k_]^Z m^Z_lky \u^_eblv \ ijh]jZff_ ^hklZlhqgh [hevrh_
qbkeh [ehdh\ g_aZ\bkbfuo hi_jZpbc Z agZqbl ijb agZqbl_evghf qbke_ ijh
p_kkhjh\\bkihevam_fhfdhfivxl_j_qZklvbagbo[m^_lijhklZb\ZlvIhwlh
fm gZjy^m k ij_^u^msbf kihkh[hf bkihevamxl lZd`_ [he__ gbadhmjh\g_\h_
jZkiZjZee_eb\Zgb_DZdihdZau\Z_lijZdlbdZgZb[hevrbcj_kmjkiZjZee_eba
fZ\ijh]jZffZokhkj_^hlhq_g\pbdeZoIhwlhfmgZb[he__jZkijhkljZg_gguf
kihkh[hf jZkiZjZee_eb\Zgby y\ey_lky lh beb bgh_ jZkij_^_e_gb_ bl_jZpbc
pbdeh\?kebf_`^mbl_jZpbyfbg_dhlhjh]hpbdeZg_lbgnhjfZpbhgguoaZ\b
kbfhkl_c lh bo fh`gh l_f beb bguf kihkh[hf jZa^Zlv jZaguf ijhp_kkhjZf
^eyh^gh\j_f_ggh]hbkiheg_gbyMkeh\ghwlhfh`_l[ulv\ujZ`_ghijbf_jgh
ke_^mxs_cdhgkljmdpb_c
for (i = 0; i < N; i++) {
if (i ~ MyProc) {
hi_jZpbbi-cbl_jZpbb^ey\uiheg_gbyijhp_kkhjhfMyProc */
}
}
A^_kv dhgkljmdpby i ~ MyProcijbf_g_gZ^eylh]hqlh[umdZaZlvqlhghf_j
bl_jZpbb idZdbf-lhh[jZahfkhhlghkblkykghf_jhfijhp_kkhjZ MyProcDhg
dj_lguc kihkh[ aZ^Zgby wlh]h khhlghr_gby hij_^_ey_l lh dZdb_ bl_jZpbb
pbdeZgZdZdb_ijhp_kkhju[m^mljZkij_^_eylvky<ijbgpbi_gbqlhg_f_rZ
_l gZijbf_j jZa^Zlv \k_f ijhp_kkhjZf ih h^ghc bl_jZpbb Z \k_ hklZevgu_
21
bl_jZpbb\uihegblvdZdbf-lhh^gbfijhp_kkhjhfH^gZdhhq_\b^ghqlh\ih
^Z\eyxs_f qbke_ kemqZ_\ lZdh_ jZkij_^_e_gb_ g_wnn_dlb\gh ihkdhevdm \k_
ijhp_kkhjudjhf_h^gh]h\uihegb\k\hxbl_jZpbx[m^mlkdhj__\k_]hijh
klZb\ZlvLZdbfh[jZahfh^gbfbalj_[h\ZgbcdjZkij_^_e_gbxbl_jZpbcdZd
\ijhq_f b d ijhp_kkm jZkiZjZee_eb\Zgby \hh[s_ y\ey_lky ih \hafh`ghklb
jZ\ghf_jgZy aZ]jmadZ ijhp_kkhjh\ GZb[he__ jZkijhkljZg_ggu_ kihkh[u jZk
ij_^_e_gbybl_jZpbcpbdeh\\lhcbebbghckl_i_gbm^h\e_l\hjyxlwlhfmlj_
[h\Zgbx
;ehqgh_ jZkij_^_e_gb_ bl_jZpbc ij_^iheZ]Z_l qlh jZkij_^_e_gb_ bl_jZpbc
pbdeZihijhp_kkhjZf\_^_lky[ehdZfbihg_kdhevdhihke_^h\Zl_evguobl_jZ
pbc<ijhkl_cr_fkemqZ_dhebq_kl\hbl_jZpbcpbdeZ N^_eblkygZqbkehijh
p_kkhjh\ P j_amevlZl hdjm]ey_lky ^h [eb`Zcr_]h p_eh]h k\_jom b qbkeh N/P
hij_^_ey_ldhebq_kl\hbl_jZpbc\[ehd_Ijbwlhfihqlb\k_ijhp_kkhjuih
emqZxl h^bgZdh\h_ dhebq_kl\h bl_jZpbc h^gZdh h^bg beb g_kdhevdh ihke_^
gbo ijhp_kkhjh\ fh]ml ijhklZb\Zlv <u[hj f_gvr_]h jZaf_jZ [ehdZ fh`_l
mf_gvrblv wlhl ^bk[ZeZgk h^gZdh ijb wlhf qZklv bl_jZpbc hklZg_lky g_jZk
ij_^_e_gghc?kebg_jZkij_^_e_ggu_bl_jZpbbkgh\ZgZqZlvjZkij_^_eylvlZ
dbfb `_ [ehdZfb gZqbgZy k i_j\h]h ijhp_kkhjZ lh ihemqbf [ehqghpbdebq_kdh_ jZkij_^_e_gb_ bl_jZpbc ?keb mf_gvrZlv dhebq_kl\h bl_jZpbc
^Zevr_ lh ^hc^_f ^h jZkij_^_e_gby ih h^ghc bl_jZpbb dhlhjh_ gZau\Z_lky
pbdebq_kdbf jZkij_^_e_gb_f Pbdebq_kdh_ jZkij_^_e_gb_ iha\hey_l fbgbfb
abjh\Zlv^bk[ZeZgk\aZ]jmad_ijhp_kkhjh\\hagbdZ\rbcijb[ehqguojZkij_
^_e_gbyo
JZkkfhljbfg_[hevrhcijbf_jImklvlj_[m_lkyjZkij_^_eblvihijhp_kkhjZf
bl_jZpbbke_^mxs_]hpbdeZ
for (i = 0; i < N; i++)
a[i] = a[i] + b[i];
Imklv\p_e_\hfdhfivxl_j_bf__lkyPijhp_kkhjh\kghf_jZfb0...P-1Lh]^Z
[ehqgh_jZkij_^_e_gb_bl_jZpbcwlh]hpbdeZfh`ghaZibkZlvke_^mxsbfh[
jZahf
k = (N-1)/PjZaf_j[ehdZbl_jZpbc
ibeg = MyProc * kgZqZeh[ehdZbl_jZpbcijhp_kkhjZMyProc */
iend = (MyProc + 1) * k -dhg_p[ehdZbl_jZpbcijhp_kkhjZ
MyProc */
if (ibeg >= N) iend = ibeg –_kebijhp_kkhjmg_^hklZehkv
bl_jZpbc
else if (iend >= N) iend = N –_kebijhp_kkhjm^hklZehkv
f_gvr_bl_jZpbc
for (i = ibeg; i <= iend; i++)
a[i] = a[i] + b[i];
22
Pbdebq_kdh_jZkij_^_e_gb_bl_jZpbclh]h`_pbdeZfh`ghaZibkZlvlZd
for (i = MyProc; i < N; i+=P)
a[i] = a[i] + b[i];
Gm`ghaZf_lblvqlh\k_khh[jZ`_gbyhjZkij_^_e_gbbbl_jZpbcpbdeh\kp_
evx ^hklb`_gby jZ\ghf_jghklb aZ]jmadb ijhp_kkhjh\ bf_xl kfuke lhevdh \
ij_^iheh`_gbbqlhjZkij_^_ey_fu_bl_jZpbbijb[ebabl_evghjZ\ghp_gguih
\j_f_gb bkiheg_gby <h fgh]bo j_Zevguo kemqZyo gZijbf_j ijb j_r_gbb
fZljbqguoaZ^Zqklj_m]hevghcfZljbp_cwlhfh`_l[ulvg_lZdZagZqblfh
]mlihlj_[h\Zlvkykh\_jr_ggh^jm]b_kihkh[ujZkij_^_e_gby
H^gZdh lhevdh jZ\ghf_jghc aZ]jmadb ijhp_kkhjh\ h[uqgh g_^hklZlhqgh ^ey
ihemq_gby wnn_dlb\ghc iZjZee_evghc ijh]jZffu Lhevdh \ djZcg_ j_^dbo
kemqZyo ijh]jZffZ g_ k^_j`bl bgnhjfZpbhgguo aZ\bkbfhkl_c \hh[s_ ?keb
`_ _klv bgnhjfZpbhggZy aZ\bkbfhklv f_`^m hi_jZpbyfb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[ebjm_lkyqlhfh`_lijb\_klbd
ihl_j_wnn_dlb\ghklb
JZkkfhljbfg_[hevrhcijbf_j
for (i = 1; i < N; i++)
for (j = 1; j < M; j++)
a[i,j] = a[i-1,j] + a[i,j];
IjhkljZgkl\hbl_jZpbc^Zggh]hnjZ]f_glZfh`ghbah[jZablvke_^mxsbfh[
jZahf
J
M-1
3
2
1
0
1 2 3 4
N-1 I
GZ wlhf jbkmgd_ djm`db khhl\_lkl\mxl hl^_evguf kjZ[Zlu\Zgbyf hi_jZlhjZ
ijbk\Zb\Zgby Z klj_edb ihdZau\Zxl bgnhjfZpbhggu_ aZ\bkbfhklb KjZam
\b^ghqlhjZa[b_gb_ijhkljZgkl\Zbl_jZpbcihbaf_j_gbxIijb\_^_ldjZaju
\mbgnhjfZpbhgguoaZ\bkbfhkl_cH^gZdhbgnhjfZpbhgguoaZ\bkbfhkl_cih
baf_j_gbxJg_lihwlhfm\hafh`ghijbf_g_gb_f_lh^Zdhhj^bgZlkjZa[b_gb
_fijhkljZgkl\Zbl_jZpbc]bi_jiehkdhklyfbhjlh]hgZevgufbhkbJgZijbf_j
dZd ihdZaZgh gZ jbkmgd_ imgdlbjgufb ebgbyfb AZl_f hi_jZpbb ihiZ\rb_ \
h^gm ]jmiim jZkij_^_eyxlky ^ey \uiheg_gby gZ h^bg ijhp_kkhj p_e_\h]h
dhfivxl_jZ
G_fgh]hmkeh`gbfijbf_j
for (i = 1; i < N; i++)
for (j = 1; j < M; j++)
a[i,j] = a[i-1,j] + a[i,j-1];
IjhkljZgkl\hbl_jZpbc^Zggh]hnjZ]f_glZfh`ghbah[jZablvke_^mxsbfh[
jZahf
24
J
M-1
3
2
1
0
1 2 3 4
N-1 I
Hq_\b^ghqlhf_lh^dhhj^bgZl\^ZgghfkemqZ_g_ijbf_gbfihlhfmqlhex
[h_jZa[b_gb_dZdihbaf_j_gbx IlZdbihbaf_j_gbx J ijb\_^_ldjZaju\m
bgnhjfZpbhgguoaZ\bkbfhkl_cH^gZdhgZjbkmgd_imgdlbjgufbebgbyfbih
dZaZgu]bi_jiehkdhklb I + J = constdhlhju_kh^_j`Zl\_jrbguf_`^mdh
lhjufbg_lbgnhjfZpbhgguoaZ\bkbfhkl_cWlhhagZqZ_l\hafh`ghklvijbf_
g_gby f_lh^Z ]bi_jiehkdhkl_c ijb dhlhjhf hkms_kl\ey_lky i_j_[hj ]bi_ji
ehkdhkl_cI + J = constb^eydZ`^hcbagbokhhl\_lkl\mxsb_hi_jZpbbjZk
ij_^_eyxlkyf_`^mijhp_kkhjZfbp_e_\h]hdhfivxl_jZ
?kebi_j_oh^blvhljZkiZjZee_eb\Zgbyhl^_evguopbdebq_kdbodhgkljmdpbcd
jZkiZjZee_eb\Zgbxp_ehcijh]jZffulhfh`_lhdZaZlvkyg_\u]h^gufbkihev
ah\Zlv\_kvgZc^_ggucj_kmjkiZjZee_ebafZ\hkh[_gghklbgZdhfivxl_jZok
jZkij_^_e_gghc iZfylvx ihkdhevdm ihlj_[m_lky [hevrh_ dhebq_kl\h i_j_
jZkij_^_e_gbc^Zgguof_`^m\uiheg_gb_fpbdeh\
<g_dhlhjuokemqZyofh`gh^h[blvky[he__wnn_dlb\gh]hjZkiZjZee_eb\Zgby
ijh]jZffu ijb ihfhsb wd\b\Ze_glguo ij_h[jZah\Zgbc – lZdbo ij_h[jZah\Z
gbcdh^Zijh]jZffuijbdhlhjuoiheghklvxkhojZgy_lkyj_amevlZl__\uihe
g_gby Kms_kl\m_l ^hklZlhqgh [hevrh_ qbkeh ih^h[guo ij_h[jZah\Zgbc ih
e_aguo \ jZaebqguo kemqZyo gZijbf_j i_j_klZgh\db pbdeh\ koehiu\Zgb_
pbdeh\jZks_ie_gb_pbdeh\bl^
Ijb\_^_fh^bgg_[hevrhcijbf_j>himklbfqlh\ijh]jZff_kh^_j`blkylZ
dhcpbde
for (i = 1; i < N; i++) {
a[i] = a[i] + b[i];
c[i] = c[i-1] + b[i];
}
< ^Zgghf pbde_ _klv bgnhjfZpbhggu_ aZ\bkbfhklb f_`^m kjZ[Zlu\Zgbyfb
\lhjh]h hi_jZlhjZ ba l_eZ pbdeZ gZ i-c b (i-1)-c bl_jZpbyo Ihwlhfm g_evay
ijhklhjZa^Zlvbl_jZpbbbkoh^gh]hpbdeZ^ey\uiheg_gbyjZaebqgufijhp_k
khjZfH^gZdh^hklZlhqghhq_\b^ghqlhwlhlpbdefh`ghjZa[blvgZ^\Zi_j
\ucbadhlhjuoklZg_liZjZee_evguf
25
for (i = 1;
a[i] =
for (i = 1;
c[i] =
i < N;
a[i] +
i < N;
c[i-1]
i++)
b[i];
i++)
+ b[i];
< g_dhlhjuo kemqZyo b wd\b\Ze_glgu_ ij_h[jZah\Zgby [_kkbevgu ihfhqv \
jZkiZjZee_eb\Zgbbijh]jZffugh^himklbfu^jm]b_f_lh^uijbij_^iheh`_
gbb qlh fh`gh ij_g_[j_qv hrb[dZfb hdjm]e_gby GZijbf_j imklv gm`gh
ijhba\_klbkmffbjh\Zgb_we_f_glh\fZkkb\Z
for (i = 0, s = 0; i < N; i++)
s+=a[i];
?keb ih^hclb d wlhfm pbdem nhjfZevghlhjZkiZjZee_eblv_]hg_ihemqblky
lZd dZd f_`^m bl_jZpbyfb pbdeZ kms_kl\mxl bgnhjfZpbhggu_ aZ\bkbfhklb
H^gZdh _keb hrb[dZfb hdjm]e_gby \ua\Zggufb jZaguf ihjy^dhf kmffbjh
\Zgbywe_f_glh\fZkkb\Za^himklbfhij_g_[j_qvlh^ZggucnjZ]f_glfh`gh
jZkiZjZee_eblv ijb ihfhsb rbjhdh ba\_klghc ko_fu k^\Zb\Zgby gZ i_j\hf
rZ]_ i_j\uc ijhp_kkhj kmffbjm_l we_f_glu a[0] b a[1] \lhjhc ijhp_kkhj
kmffbjm_lwe_f_glu a[2]b a[3]bl^gZke_^mxs_frZ]_ihiZjghkmffbjm
xlkywlbqZklbqgu_kmffublZd^hihemq_gbyhdhgqZl_evgh]hj_amevlZlZ?k
eb bf__lky N/2 ijhp_kkhjh\ lh \_kv Ze]hjblf kmffbjh\Zgby \uihegy_lky aZ
log2NiZjZee_evguorZ]h\
3. Wnn_dlb\ghklvjZkiZjZee_eb\Zgby
?kl_kl\_gghqlhbkihevamyiZjZee_evgmxkbkl_fmk p\uqbkebl_evgufbmkl
jhckl\Zfbihevah\Zl_evh`b^Z_lihemqblvmkdhj_gb_k\h_cijh]jZffu\pjZa
ihkjZ\g_gbxkihke_^h\Zl_evguf\ZjbZglhfGh^_ckl\bl_evghklvijZdlbq_
kdb\k_]^ZhdZau\Z_lky^Ze_dZhlb^_ZeZ
Ij_^iheh`bfqlhkljmdlmjZbgnhjfZpbhgguoaZ\bkbfhkl_cijh]jZffuhij_
^_e_gZqlh\h[s_fkemqZ_y\ey_lky\_kvfZg_ijhklhcaZ^Zq_cb^heyhi_jZ
pbcdhlhju_gm`gh\uihegylvihke_^h\Zl_evghjZ\gZ f]^_ 0 ”f ”ijb
wlhf^heyihgbfZ_lkyg_ihklZlbq_kdhfmqbkemkljhddh^ZZih\j_f_gb\u
iheg_gby ihke_^h\Zl_evghc ijh]jZffu DjZcgb_ kemqZb \ agZq_gbyo f khhl
\_lkl\mxl iheghklvx iZjZee_evguf (f = 0) b iheghklvx ihke_^h\Zl_evguf
(f = 1) ijh]jZffZfLh]^Z^eylh]hqlh[uhp_gblvdZdh_mkdhj_gb_ Sfh`_l
[ulvihemq_ghgZdhfivxl_j_bapijhp_kkhjh\ijb^ZgghfagZq_gbbffh`gh
\hkihevah\ZlvkyaZdhghf:f^ZeZ
S≤
1
1−f
f+
p
26
GZijbf_j_kebijh]jZffubkihegy_lkyiZjZee_evghZih-ij_`g_fm
ihke_^h\Zl_evghlhmkdhj_gby[he__jZaihemqblv\ijbgpbi_g_\hafh`gh
\g_aZ\bkbfhklbhldZq_kl\Zj_ZebaZpbbiZjZee_evghcqZklbdh^ZbqbkeZbk
ihevam_fuo ijhp_kkhjh\ ykgh qlh ihemqZ_lky lhevdh \ lhf kemqZ_ dh]^Z
\j_fybkiheg_gbyiZjZee_evghcqZklbjZ\ghHlkx^Zfh`ghk^_eZlv\u\h^
qlh g_ ex[Zy ijh]jZffZ fh`_l [ulv wnn_dlb\gh jZkiZjZee_e_gZ >ey lh]h
qlh[uwlh[ueh\hafh`ghg_h[oh^bfhqlh[u^heybgnhjfZpbhgghg_aZ\bkb
fuohi_jZpbc[ueZhq_gv[hevrhc<ijbgpbi_wlhg_^he`ghhlim]b\Zlvhl
iZjZee_evgh]hijh]jZffbjh\ZgbyihlhfmqlhdZdihdZau\Z_lijZdlbdZ[hev
rbgkl\h \uqbkebl_evguo Ze]hjblfh\ mkljh_gh\wlhfkfuke_^hklZlhqghoh
jhrbfh[jZahf
Ij_^iheh`bf l_i_jv qlh \ ijh]jZff_ hlghkbl_evgh g_fgh]h ihke_^h\Zl_ev
guohi_jZpbcDZaZehkv[u\^ZgghfkemqZ_\k_ijh[e_fum^ZehkvjZaj_rblv
Ghij_^klZ\vl_qlh^hklmigu_\Zfijhp_kkhjujZaghjh^guihk\h_cijhba\h
^bl_evghklbAgZqbl[m^_llZdhcfhf_gldh]^Zdlh-lhbagbo_s_ljm^blkyZ
dlh-lh m`_ \k_ k^_eZe b [_kihe_agh ijhklZb\Z_l \ h`b^Zgbb ?keb jZa[jhk \
ijhba\h^bl_evghklb ijhp_kkhjh\ [hevrhc lh b wnn_dlb\ghklv \k_c kbkl_fu
ijbjZ\ghf_jghcaZ]jmad_[m^_ldjZcg_gbadhc
Ghij_^iheh`bfqlh\k_ijhp_kkhjuh^bgZdh\uIjh[e_fudhgqbebkv"Hiylv
g_lIjhp_kkhju\uihegbebk\hxjZ[hlmghj_amevlZlZfbqZs_\k_]hgZ^hh[
f_gb\Zlvky^eyijh^he`_gby\uqbke_gbcZgZi_j_^Zqm^Zgguomoh^bl\j_fy
b \ wlh \j_fy ijhp_kkhju hiylv ijhklZb\Zxl Djhf_ mdZaZgguo _klv b _s_
[hevrh_ dhebq_kl\h nZdlhjh\ \ebyxsbo gZ wnn_dlb\ghklv \uiheg_gby iZ
jZee_evguoijh]jZffijbq_f\k_hgb^_ckl\mxlh^gh\j_f_gghZagZqbl\k_\
lhcbebbghckl_i_gb^he`gumqblu\ZlvkyijbjZkiZjZee_eb\Zgbb
LZdbf h[jZahf aZklZ\blv iZjZee_evgmx \uqbkebl_evgmx kbkl_fm beb kmi_jW<FjZ[hlZlvkfZdkbfZevghcwnn_dlb\ghklvxgZdhgdj_lghcijh]jZff_-wlh
aZ^ZqZg_baijhkluoihkdhevdmg_h[oh^bfhlsZl_evgh_kh]eZkh\Zgb_kljmd
lmju ijh]jZff b Ze]hjblfh\ k hkh[_gghklyfb Zjobl_dlmju iZjZee_evguo
\uqbkebl_evguokbkl_f
4. H[km`^_gb_fh^_evghcaZ^Zqb
Ij_^eZ]Z_fZy ^ey j_ZebaZpbb fh^_evgZy ijh]jZffZ f_lh^ =ZmkkZ j_r_gby
kbkl_f ebg_cguo Ze]_[jZbq_kdbo mjZ\g_gbc http://parallel.ru/vvv/tasks/ i_j
\Zyy\ey_lky^hklZlhqghijhklhcb\lh`_\j_fykh^_j`Zl_evghcklhqdbaj_
gbyjZkiZjZee_eb\ZgbyGZ__ijbf_j_fh`ghijhclb\k_hkgh\gu_wlZiuijh
p_kkZgZibkZgbyiZjZee_evguoijh]jZffb\klj_lblvkykhfgh]bfbih^kl_j_
]ZxsbfbgZwlhfimlbljm^ghklyfb
27
Ij_^eZ]Z_lky ke_^mxsZy ihke_^h\Zl_evghklv ^_ckl\bc ih gZibkZgbx b hilb
fbaZpbbijh]jZffu\h[s_fkemqZ_g_h[yaZl_evgZyijbkha^ZgbbiZjZee_ev
ghcijh]jZffu
• fZl_fZlbq_kdZyihklZgh\dZaZ^ZqbaZibkv\nhjfmevghf\b^_
• ihkljh_gb_\uqbkebl_evgh]hZe]hjblfZ
• kha^Zgb_bhilbfbaZpbyihke_^h\Zl_evghcijh]jZffu
• bkke_^h\Zgb_ j_kmjkZ iZjZee_ebafZ ijh]jZffu b \u[hj f_lh^Z jZkiZ
jZee_eb\Zgby
• gZibkZgb_³dZdhc-lh´iZjZee_evghcijh]jZffukbkihevah\Zgb_fex[uo
dhgkljmdpbcex[uol_ogheh]bciZjZee_evgh]hijh]jZffbjh\Zgby
• hilbfbaZpby iZjZee_evghc kljmdlmju ijh]jZffu \u[hj gZb[he__ ih^
oh^ysbo dhgkljmdpbc \hafh`gh ijbgylb_ ^jm]h]h j_r_gby ih f_lh^m
jZkiZjZee_eb\Zgby
• ^hihegbl_evgZy hilbfbaZpby ijh]jZffuk\yaZggZygZijbf_jkwdhgh
fb_ciZfylbbeb^jm]bfblj_[h\ZgbyfbkhklhjhguZiiZjZlmjubebijh
]jZffgh]hh[_ki_q_gby
5. AZ^Zgby
• Bkke_^h\ZlvbgnhjfZpbhggmxkljmdlmjmijh]jZffuj_Zebamxs_c
f_lh^=ZmkkZj_r_gbykbkl_febg_cguoZe]_[jZbq_kdbomjZ\g_gbc
ij_^eh`blv jZaebqgu_ f_lh^u jZkij_^_e_gby hi_jZpbc f_`^m
ijhp_kkhjZfb\u[jZlvh^bgbagbo^eyj_ZebaZpbbbfhlb\bjh\Zlv
k\hc\u[hj
• Imklv dhg\_c_jgh_ mkljhckl\h khklhbl ba n klmi_g_c dZ`^Zy ba
dhlhjuo \uihegy_lky aZ ti (i=1…n) lZdlh\ Imklv gZ ^Zgghf mkl
jhckl\_gm`ghkh\_jrblv Nhi_jZpbcAZdZdh_fbgbfZevgh_dheb
q_kl\hlZdlh\wlhfh`_l[ulvk^_eZgh"
• QlhlZdh_[ZeZgkbjh\dZaZ]jmadbbdZdhgZ\eby_lgZmkdhj_gb_jZ
[hluijh]jZffu"
• Hibrbl_ kblmZpbx ijb dhlhjhc bkihevah\Zgb_ dwr-iZfylb ijh
p_kkhjh\ fh`_l gZjmrblv aZdhg :f^ZeZ kmi_jebg_cgh_ mkdhj_
gb_
• Ij_^iheh`bfqlhgZfgm`ghmkdhjblvjZ[hlmijh]jZffu\jZa
qZklvwlhcijh]jZffufh`ghmkdhjblvg_[he__q_f\jZa
<hkdhevdhjZagm`ghmkdhjblvhklZ\rb_kyijh]jZffuqlh[u
^hklbqvihklZ\e_gghcp_eb"
• Q_fmjZ\gZ^ebgZdjblbq_kdh]himlbbgnhjfZpbhggh]h]jZnZke_
^mxsbonjZ]f_glh\
Z)
for (i = 1; i < N; i++) {
for (j = 1; j < N; j++) {
a[i][j] = (a[i-1][j] + a[i][j-1])/2;
}
28
}
[)
for (i = 1; i <= n; i++) {
for (j = 1; j <= n; j++) {
u[i+j] = u[2*n+1-i-j];
}
}
• Fh`gheb\uihegblviZjZee_evghnjZ]f_glubaij_^u^ms_]haZ
^Zgbyb_keb^ZlhdZd"
• <_jgh eb ml\_j`^_gb_ qlh _keb g_dhlhjuc njZ]f_gl ijh]jZffu
fh`_l[ulvwnn_dlb\ghj_Zebah\ZggZdhg\_c_jghfmkljhckl\_lh
hgfh`_l[ulvwnn_dlb\ghj_Zebah\Zgb\iZjZee_evghfj_`bf_gZ
gZ[hj_ihke_^h\Zl_evguomkljhckl\bgZh[hjhl"
• Ijb^mfZcl_aZ^ZqmdhlhjZy[uwnn_dlb\gh\uihegyeZkvgZfZdjh
dhg\_c_j_ klmi_gyfb dhlhjh]h y\eyxlky hl^_evgu_ dhfivxl_ju
ehdZevghck_lb
AZgylb_L_ogheh]byMPI
2. <\_^_gb_
GZb[he__ jZkijhkljZg_gghc l_ogheh]b_c ijh]jZffbjh\Zgby iZjZee_evguo
dhfivxl_jh\kjZkij_^_e_gghciZfylvx\gZklhys__\j_fyy\ey_lky03,Hk
gh\guf kihkh[hf \aZbfh^_ckl\by iZjZee_evguo ijhp_kkh\ \ lZdbo kbkl_fZo
y\ey_lky i_j_^ZqZ khh[s_gbc ^jm] ^jm]m Wlh b hljZ`_gh \ gZa\Zgbb ^Zgghc
l_ogheh]bb — Message Passing Interface KlZg^Zjl MPI nbdkbjm_l bgl_jn_ck
dhlhjuc^he`gZkh[ex^ZlvdZdkbkl_fZijh]jZffbjh\ZgbyMPIgZdZ`^hc\u
qbkebl_evghc kbkl_f_ lZd b ihevah\Zl_ev ijb kha^Zgbb k\hbo ijh]jZff Kh
\j_f_ggu_j_ZebaZpbbqZs_\k_]hkhhl\_lkl\mxlklZg^Zjlm03,\_jkbb<
1997—]h^Zoihy\bekyklZg^Zjl03,-agZqbl_evghjZkrbjb\rbcnmgd
pbhgZevghklvij_^u^ms_c\_jkbbH^gZdh^hkboihjwlhl\ZjbZglMPIg_ih
emqbe rbjhdh]h jZkijhkljZg_gby <_a^_ ^Ze__ _keb bgh]h g_ h]h\hj_gh fu
[m^_fbf_lv^_ehkhklZg^Zjlhf
03,ih^^_j`b\Z_ljZ[hlmkyaudZfbKbbNhjljZg<^Zgghfihkh[bb\k_ijb
f_jubhibkZgby\k_onmgdpbc[m^ml^Zgukbkihevah\Zgb_fyaudZKbH^gZdh
wlhkh\_jr_gghg_y\ey_lkyijbgpbibZevgufihkdhevdmhkgh\gu_b^_b03,b
ijZ\beZ hnhjfe_gby hl^_evguo dhgkljmdpbc ^ey wlboyaudh\\hfgh]hfkoh
`b IhegZy \_jkby bgl_jn_ckZ kh^_j`bl hibkZgb_ [he__ nmgdpbc GZrZ
aZ^ZqZ — h[tykgblvb^_xl_ogheh]bbbihfhqvhk\hblvg_h[oh^bfu_gZijZd
lbd_dhfihg_glu;he__ih^jh[ghh[bgl_jn_ck_MPIfh`ghihqblZlvgZkljZ
gbp_http://parallel.ru/tech/tech_dev/mpi.html.
29
Bgl_jn_ckih^^_j`b\Z_lkha^Zgb_iZjZee_evguoijh]jZff\klbe_0,0'qlh
ih^jZamf_\Z_lh[t_^bg_gb_ijhp_kkh\kjZaebqgufbbkoh^gufbl_dklZfbH^
gZdh gZ ijZdlbd_ ijh]jZffbklu ]hjZa^h qZs_ bkihevamxl SPMD-fh^_ev \
jZfdZodhlhjhc^ey\k_oiZjZee_evguoijhp_kkh\bkihevam_lkyh^bgblhl`_
dh^ < gZklhys__ \j_fy \k_ [hevr_ b [hevr_ j_ZebaZpbc MPI ih^^_j`b\Zxl
jZ[hlmkgblyfb
<k_ ^hihegbl_evgu_ h[t_dlu bf_gZ nmgdpbc dhgklZglu ij_^hij_^_e_ggu_
lbiu^Zgguob libkihevam_fu_\03,bf_xlij_nbdk MPI_?kebihevah\Z
l_evg_[m^_lbkihevah\Zlv\ijh]jZff_bf_gklZdbfij_nbdkhflhdhgnebd
lh\kh[t_dlZfbMPIaZ\_^hfhg_[m^_l<k_hibkZgbybgl_jn_ckZMPIkh[jZgu
\ nZce_ mpi.h ihwlhfm \ gZqZe_ 03,-ijh]jZffu ^he`gZ klhylv ^bj_dlb\Z
#include <mpi.h>.
MPI-ijh]jZffZ — wlh fgh`_kl\h iZjZee_evguo \aZbfh^_ckl\mxsbo ijhp_k
kh\ <k_ ijhp_kku ihjh`^Zxlky h^bg jZa h[jZamy iZjZee_evgmx qZklv ijh
]jZffu < oh^_ \uiheg_gby MPI-ijh]jZffu ihjh`^_gb_ ^hihegbl_evguo
ijhp_kkh\ beb mgbqlh`_gb_ kms_kl\mxsbo g_ ^himkdZ_lky DZ`^uc ijhp_kk
jZ[hlZ_l\k\h_fZ^j_kghfijhkljZgkl\_gbdZdboh[sboi_j_f_gguobeb^Zgguo\MPIg_lHkgh\gufkihkh[hf\aZbfh^_ckl\byf_`^mijhp_kkZfby\ey_l
kyy\gZyihkuedZkhh[s_gbc
>ey ehdZebaZpbb \aZbfh^_ckl\by iZjZee_evguo ijhp_kkh\ ijh]jZffu fh`gh
kha^Z\Zlv]jmiiuijhp_kkh\ij_^hklZ\eyybfhl^_evgmxkj_^m^eyh[s_gby —
dhffmgbdZlhj KhklZ\ h[jZam_fuo ]jmii ijhba\he_g =jmiiu fh]ml ihegh
klvx\oh^blvh^gZ\^jm]mxg_i_j_k_dZlvkybebi_j_k_dZlvkyqZklbqghIjb
klZjl_ijh]jZffu\k_]^ZkqblZ_lkyqlh\k_ihjh`^_ggu_ijhp_kkujZ[hlZxl\
jZfdZo \k_h[t_fexs_]h dhffmgbdZlhjZ bf_xs_]h ij_^hij_^_e_ggh_ bfy
MPI_COMM_WORLD Wlhl dhffmgbdZlhj kms_kl\m_l \k_]^Z b kem`bl ^ey \aZbfh
^_ckl\by\k_oijhp_kkh\MPI-ijh]jZffu
DZ`^uc ijhp_kk MPI-ijh]jZffu bf__l mgbdZevguc Zljb[ml ghf_j ijhp_kkZ,
dhlhjucy\ey_lkyp_eufg_hljbpZl_evgufqbkehfKihfhsvxwlh]hZljb[mlZ
ijhbkoh^blagZqbl_evgZyqZklv\aZbfh^_ckl\byijhp_kkh\f_`^mkh[hcYkgh
qlh\h^ghfblhf`_dhffmgbdZlhj_\k_ijhp_kkubf_xljZaebqgu_ghf_jZ
Ghihkdhevdmijhp_kkfh`_lh^gh\j_f_ggh\oh^blv\jZagu_dhffmgbdZlhju
lh_]hghf_j\h^ghfdhffmgbdZlhj_fh`_lhlebqZlvkyhl_]hghf_jZ\^jm]hf
Hlkx^Z klZgh\ylky ihgylgufb ^\Z hkgh\guo Zljb[mlZ ijhp_kkZ dhffmgbdZ
lhj b ghf_j \ dhffmgbdZlhj_ ?keb ]jmiiZ kh^_j`bl n ijhp_kkh\ lh ghf_j
ex[h]hijhp_kkZ\^Zgghc]jmii_e_`bl\ij_^_eZohl^hn – 1.
30
Hkgh\gufkihkh[hfh[s_gbyijhp_kkh\f_`^mkh[hcy\ey_lkyihkuedZkhh[
s_gbc Khh[s_gb_ — wlh gZ[hj ^Zgguo g_dhlhjh]h lbiZ DZ`^h_ khh[s_gb_
bf__l g_kdhevdh Zljb[mlh\ \ qZklghklb ghf_j ijhp_kkZ-hlijZ\bl_ey ghf_j
ijhp_kkZ-ihemqZl_ey b^_glbnbdZlhj khh[s_gby b ^jm]b_ H^gbf ba \Z`guo
Zljb[mlh\khh[s_gbyy\ey_lky_]hb^_glbnbdZlhjbeblw]Ihb^_glbnbdZlhjm
ijhp_kkijbgbfZxsbckhh[s_gb_gZijbf_jfh`_ljZaebqblv^\Zkhh[s_gby
ijbr_^rb_dg_fmhlh^gh]hblh]h`_ijhp_kkZKZfb^_glbnbdZlhjkhh[s_
gby y\ey_lky p_euf g_hljbpZl_evguf qbkehf e_`Zsbf \ ^bZiZahg_ hl ^h
>eyjZ[hlukZljb[mlZfbkhh[s_gbc\\_^_gZkljmdlmjZ MPI_Statusih
eydhlhjhc^Zxl^hklmidboagZq_gbyf
3. H[sb_nmgdpbb03,
Ij_`^_ q_f i_j_oh^blv d hibkZgbx dhgdj_lguonmgdpbck^_eZ_fg_kdhevdh
h[sboaZf_qZgbcIjbhibkZgbbnmgdpbcfu\k_]^Z[m^_fihevah\Zlvkykeh
\hf OUT^eyh[hagZq_gby\uoh^guoiZjZf_ljh\q_j_adhlhju_nmgdpby\ha\jZ
sZ_lj_amevlZlu>Z`__kebj_amevlZlhfjZ[hlunmgdpbby\ey_lkyh^ghqbkeh
hgh[m^_l\ha\jZs_ghq_j_ah^bgbaiZjZf_ljh\K\yaZghwlhkl_fqlhijZdlb
q_kdb\k_nmgdpbbMPI\ha\jZsZxl\dZq_kl\_k\h_]hagZq_gbybgnhjfZpbxh[
mki_rghklbaZ\_jr_gby<kemqZ_mki_rgh]h\uiheg_gbynmgdpby\_jg_lagZ
q_gb_ MPI_SUCCESSbgZq_ — dh^hrb[db<b^hrb[dbdhlhjZyijhbahreZijb
\uiheg_gbbnmgdpbbfh`gh[m^_lihgylvbahibkZgbydZ`^hcnmgdpbbIj_
^hij_^_e_ggu_\ha\jZsZ_fu_agZq_gbykhhl\_lkl\mxsb_jZaebqgufhrb[hq
gufkblmZpbyfhij_^_e_gu\nZce_ mpi.h<^Zevg_cr_fijbhibkZgbbdhg
dj_lguonmgdpbc_kebgbq_]hki_pbZevghg_kdZaZghlh\ha\jZsZ_fh_nmgdpb_cagZq_gb_[m^_lih^qbgylvkybf_gghwlhfmijZ\bem
< ^Zgghf jZa^_e_ fu hklZgh\bfky gZ h[sbo nmgdpbyo MPI g_h[oh^bfuo
ijZdlbq_kdb\dZ`^hcijh]jZff_
int MPI_Init(int *argc, char ***argv)
BgbpbZebaZpbyiZjZee_evghcqZklbijh]jZffu<k_^jm]b_nmgdpbb03,fh
]ml [ulv \ua\Zgu lhevdh ihke_ \uah\Z MPI_Init G_h[uqguc lbi Zj]mf_glh\
MPI_Init ij_^mkfhlj_g^eylh]hqlh[ubf_lv\hafh`ghklvi_j_^Zlv\k_fijh
p_kkZfZj]mf_glunmgdpbb mainBgbpbZebaZpbyiZjZee_evghcqZklb^eydZ`
^h]hijbeh`_gby^he`gZ\uihegylvkylhevdhh^bgjZa
int MPI_Finalize(void)
AZ\_jr_gb_ iZjZee_evghc qZklb ijbeh`_gby <k_ ihke_^mxsb_ h[jZs_gby d
ex[uf03,-nmgdpbyf\lhfqbke_d MPI_InitaZij_s_guDfhf_glm\uah\Z
MPI_Finalize dZ`^ufijhp_kkhfijh]jZffu\k_^_ckl\bylj_[mxsb__]hmqZ
klby\h[f_g_khh[s_gbyfb^he`gu[ulvaZ\_jr_gu
31
H[sZyko_fZMPI-ijh]jZffu\u]ey^bllZd
main(int argc, char **argv)
{
…
MPI_Init(&argc, &argv);
…
MPI_Finalize();
…
}
int MPI_Comm_size(MPI_Comm comm, int *size)
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT size — qbkehijhp_kkh\\dhffmgbdZlhj_comm.
Hij_^_e_gb_h[s_]hqbkeZiZjZee_evguoijhp_kkh\\dhffmgbdZlhj_commJ_
amevlZl\ha\jZsZ_lkyq_j_aiZjZf_lj size^eyq_]hnmgdpbbi_j_^Z_lkyZ^j_k
wlhc i_j_f_gghc Ihkdhevdm dhffmgbdZlhjy\ey_lkykeh`ghckljmdlmjhci_
j_^ gbf klhbl bfy ij_^hij_^_e_ggh]h lbiZ MPI_Comm hij_^_e_ggh]h \ nZce_
mpi.h.
LQW03,B&RPPBUDQN03,BKRPPFRPPLQWUDQN
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT rank — ghf_jijhp_kkZ\dhffmgbdZlhj_comm.
Hij_^_e_gb_ ghf_jZ ijhp_kkZ \ dhffmgbdZlhj_ comm ?keb nmgdpby
MPI_Comm_size ^eylh]h`_dhffmgbdZlhjZcomm \_jgmeZagZq_gb_sizelhagZ
q_gb_\ha\jZsZ_fh_nmgdpb_cMPI_Comm_rankq_j_ai_j_f_ggmxranke_`bl\
^bZiZahg_hl0^hsize-1.
double MPI_Wtime(void)
WlZ nmgdpby \ha\jZsZ_l Zkljhghfbq_kdh_ \j_fy \ k_dmg^Zo \_s_kl\_ggh_
qbkehijhr_^r__kg_dhlhjh]hfhf_glZ\ijhrehf?kebg_dhlhjucmqZklhd
ijh]jZffu hdjm`blv \uah\Zfb ^Zgghc nmgdpbb lh jZaghklv \ha\jZsZ_fuo
agZq_gbc ihdZ`_l \j_fy jZ[hlu ^Zggh]h mqZkldZ =ZjZglbjm_lky qlh fhf_gl
\j_f_gb bkihevam_fuc \ dZq_kl\_ lhqdb hlkq_lZ g_ [m^_l baf_g_g aZ \j_fy
kms_kl\h\Zgbyijhp_kkZAZf_lbfqlhwlZnmgdpby\ha\jZsZ_lj_amevlZlk\h_c
jZ[hlug_q_j_aiZjZf_ljuZy\gufh[jZahf
Ijhkl_crbc ijbf_j ijh]jZffu \ dhlhjhc bkihevah\Zgu hibkZggu_ \ur_
nmgdpbb\u]ey^bllZd
32
main(int argc, char **argv)
{
int me, size;
…
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &me);
MPI_Comm_size(MPI_COMM_WORLD, &size);
printf("Process %d size %d \n", me, size);
…
MPI_Finalize();
…
}
KljhdZkhhl\_lkl\mxsZynmgdpbbprintf[m^_l\u\_^_gZklhevdhjZakdhevdh
ijhp_kkh\[uehihjh`^_ghijb\uah\_ MPI_InitIhjy^hdihy\e_gbykljhdaZ
jZg__g_hij_^_e_gbfh`_l[ulv\hh[s_]h\hjyex[uf=ZjZglbjm_lkylhev
dhlhqlhkh^_j`bfh_hl^_evguokljhdg_[m^_li_j_f_rZgh^jm]k^jm]hf
4. Ijb_fi_j_^ZqZkhh[s_gbcf_`^mhl^_evgufbijhp_kkZfb
<k_nmgdpbbi_j_^Zqbkhh[s_gbc\03,^_eylkygZ^\_]jmiiu<h^gm]jmiim
\oh^yl nmgdpbb dhlhju_ ij_^gZagZq_gu ^ey \aZbfh^_ckl\by ^\mo ijhp_kkh\
ijh]jZffu LZdb_ hi_jZpbb gZau\Zxlky bg^b\b^mZevgufb beb hi_jZpbyfb
lbiZ lhqdZ-lhqdZ Nmgdpbb ^jm]hc ]jmiiu ij_^iheZ]Zxl qlh \ hi_jZpbx
^he`gu[ulv\h\e_q_gu\k_ijhp_kkug_dhlhjh]hdhffmgbdZlhjZLZdb_hi_
jZpbbgZau\Zxlkydhee_dlb\gufbGZqg_fhibkZgb_nmgdpbch[f_gZkhh[s_
gbyfbkh[km`^_gbyhi_jZpbclbiZlhqdZ-lhqdZ<k_nmgdpbb^Zgghc]jmiiu\
k\hxhq_j_^vlZd`_^_eylkygZ^\ZdeZkkZnmgdpbbk[ehdbjh\dhckkbgojh
gbaZpb_cbnmgdpbb[_a[ehdbjh\dbZkbgojhggu_
Ijb_fi_j_^ZqZkhh[s_gbck[ehdbjh\dhcaZ^Zxlkydhgkljmdpbyfbke_^mxs_
]h\b^Z
int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest,
int msgtag, MPI_Comm comm)
• buf — Z^j_kgZqZeZ[mn_jZkihkueZ_fufkhh[s_gb_f
• count — qbkehi_j_^Z\Z_fuowe_f_glh\\khh[s_gbb
• datatype — lbii_j_^Z\Z_fuowe_f_glh\
• dest — ghf_jijhp_kkZ-ihemqZl_ey
• msgtag — b^_glbnbdZlhjkhh[s_gby
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
33
;ehdbjmxsZy ihkuedZ khh[s_gby k b^_glbnbdZlhjhf msgtag khklhys_]h ba
count we_f_glh\lbiZ datatypeijhp_kkmkghf_jhf dest<k_we_f_gluihku
eZ_fh]hkhh[s_gbyjZkiheh`_guih^jy^\[mn_j_ bufAgZq_gb_ count fh`_l
[ulv gme_f JZaj_rZ_lky i_j_^Z\Zlv khh[s_gb_ kZfhfm k_[_ Lbi i_j_^Z\Z_
fuo we_f_glh\ datatype ^he`_g mdZau\Zlvky k ihfhsvx ij_^hij_^_e_gguo
dhgklZgl lbiZ gZijbf_j MPI_INT, MPI_LONG, MPI_SHORT, MPI_LONG_DOUBLE,
MPI_CHAR, MPI_UNSIGNED_CHAR, MPI_FLOAT b li >ey dZ`^h]h lbiZ ^Zgguo
yaudh\NhjljZgbKb_klvk\hydhgklZglZIheguckibkhdij_^hij_^_e_gguo
bf_glbih\fh`ghgZclb\nZce_mpi.h.
;ehdbjh\dZ]ZjZglbjm_ldhjj_dlghklvih\lhjgh]hbkihevah\Zgby\k_oiZjZf_l
jh\ihke_\ha\jZlZbaih^ijh]jZffuWlhhagZqZ_lqlhihke_\ha\jZlZba^Zg
ghc nmgdpbb fh`gh bkihevah\Zlv ex[u_ ijbkmlkl\mxsb_ \ \uah\_ nmgdpbb
i_j_f_ggu_[_ahiZk_gbybkihjlblvi_j_^Z\Z_fh_khh[s_gb_<u[hjkihkh[Z
hkms_kl\e_gbywlhc]ZjZglbbdhibjh\Zgb_\ijhf_`mlhqguc[mn_jbebg_ih
kj_^kl\_ggZyi_j_^ZqZijhp_kkm desthklZ_lkyaZjZajZ[hlqbdZfbdhgdj_lghc
j_ZebaZpbb03,
Ke_^m_lki_pbZevghhlf_lblvqlh\ha\jZlbanmgdpbbMPI_Send g_hagZqZ_lgb
lh]hqlhkhh[s_gb_ihemq_ghijhp_kkhfdestgblh]hqlhkhh[s_gb_ihdbgm
eh ijhp_kkhjguc we_f_gl gZ dhlhjhf \uihegy_lky ijhp_kk \uihegb\rbc
MPI_Send Ij_^hklZ\ey_lky lhevdh ]ZjZglby [_ahiZkgh]h baf_g_gby i_j_f_g
guo bkihevah\Zgguo \ \uah\_ ^Zgghc nmgdpbb Ih^h[gZy g_hij_^_e_gghklv
^Ze_dhg_\k_]^ZmkljZb\Z_lihevah\Zl_eyQlh[ujZkrbjblv\hafh`ghklbi_
j_^Zqbkhh[s_gbc\MPI\\_^_gu^hihegbl_evgu_ljbnmgdpbb<k_iZjZf_l
jumwlbonmgdpbclZdb_`_dZdbmnmgdpbbMPI_Sendh^gZdhmdZ`^hcbagbo
_klvk\hyhkh[_gghklv
MPI_Bsend — i_j_^ZqZ khh[s_gby k [mn_jbaZpb_c ?keb ijb_f ihkueZ_fh]h
khh[s_gby _s_ g_ [ue bgbpbZebabjh\Zg ijhp_kkhf-ihemqZl_e_f lh khh[s_
gb_ [m^_l aZibkZgh \ [mn_j b ijhbahc^_l g_f_^e_gguc \ha\jZl ba nmgdpbb
<uiheg_gb_ ^Zgghc nmgdpbb gbdZd g_ aZ\bkbl hl khhl\_lkl\mxs_]h \uah\Z
nmgdpbbijb_fZkhh[s_gbyL_fg_f_g__nmgdpbyfh`_l\_jgmlvdh^hrb[
db_kebf_klZih^[mn_jg_^hklZlhqgh
MPI_Ssend — i_j_^ZqZ khh[s_gby k kbgojhgbaZpb_c <uoh^ ba ^Zgghc nmgd
pbbijhbahc^_llhevdhlh]^Zdh]^Zijb_fihkueZ_fh]hkhh[s_gby[m^_lbgb
pbZebabjh\Zgijhp_kkhf-ihemqZl_e_fLZdbfh[jZahfaZ\_jr_gb_i_j_^Zqbk
kbgojhgbaZpb_c ]h\hjbl g_ lhevdh h \hafh`ghklb ih\lhjgh]h bkihevah\Zgby
[mn_jZ gh b h ]ZjZglbjh\Zgghf ^hklb`_gbb ijhp_kkhf-ihemqZl_e_f lhqdb
ijb_fZkhh[s_gby\ijh]jZff_?kebijb_fkhh[s_gbylZd`_\uihegy_lkyk
34
[ehdbjh\dhclhnmgdpby MPI_Ssend khojZgy_lk_fZglbdm[ehdbjmxsbo\uah
\h\
MPI_Rsend — i_j_^ZqZ khh[s_gby ih ]hlh\ghklb >Zgghc nmgdpb_c fh`gh
ihevah\Zlvky lhevdh \ lhf kemqZ_ _keb ijhp_kk-ihemqZl_ev m`_ bgbpbbjh\Ze
ijb_fkhh[s_gby<ijhlb\ghfkemqZ_\uah\nmgdpbb\hh[s_]h\hjyy\ey_l
kyhrb[hqgufbj_amevlZl__\uiheg_gbyg_hij_^_e_g<hfgh]boj_ZebaZpb
yo nmgdpby MPI_Rsend khdjZsZ_l ijhlhdhe \aZbfh^_ckl\by f_`^m hlijZ\bl_e_fbihemqZl_e_fmf_gvrZygZdeZ^gu_jZkoh^ugZhj]ZgbaZpbxi_j_^Z
qb
int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int source,
int msgtag, MPI_Comm comm, MPI_Status *status)
• OUT buf — Z^j_kgZqZeZ[mn_jZ^eyijb_fZkhh[s_gby
• count — fZdkbfZevgh_qbkehwe_f_glh\\ijbgbfZ_fhfkhh[s_gbb
• datatype — lbiwe_f_glh\ijbgbfZ_fh]hkhh[s_gby
• source — ghf_jijhp_kkZ-hlijZ\bl_ey
• msgtag — b^_glbnbdZlhjijbgbfZ_fh]hkhh[s_gby
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT status — iZjZf_ljuijbgylh]hkhh[s_gby
Ijb_fkhh[s_gbykb^_glbnbdZlhjhf msgtag hlijhp_kkZ source k[ehdbjh\
dhcQbkehwe_f_glh\\ijbgbfZ_fhfkhh[s_gbbg_^he`ghij_\hkoh^blvagZ
q_gbycount?kebqbkehijbgyluowe_f_glh\f_gvr_agZq_gbycountlh]ZjZg
lbjm_lkyqlh\[mn_j_ bufbaf_gylkylhevdhwe_f_glukhhl\_lkl\mxsb_we_
f_glZf ijbgylh]h khh[s_gby ?keb gm`gh magZlv lhqgh_ qbkeh we_f_glh\ \
ijbgbfZ_fhfkhh[s_gbblhfh`gh\hkihevah\Zlvkynmgdpb_c MPI_Get_count.
;ehdbjh\dZ]ZjZglbjm_lqlhihke_\ha\jZlZbanmgdpbb\k_we_f_glukhh[s_
gbym`_[m^mlijbgylubjZkiheh`_gu\[mn_j_buf.
Gb`_ijb\_^_gijbf_jijh]jZffu\dhlhjhcgme_\hcijhp_kkihkueZ_lkhh[
s_gb_ijhp_kkmkghf_jhfh^bgb`^_lhlg_]hhl\_lZ?kebijh]jZffZ[m^_l
aZims_gZ k [hevrbf qbkehf ijhp_kkh\ lh j_Zevgh \uihegylv i_j_kuedb \k_
jZ\ghklZgmllhevdhgme_\hcbi_j\ucijhp_kkuHklZevgu_ijhp_kkuihke_bo
ihjh`^_gby nmgdpb_c MPI_Init kjZam aZ\_jrZlky \uihegb\ nmgdpbx
MPI_Finalize.
#include "mpi.h"
#include <stdio.h>
int main(int argc, char **argv)
{
int numtasks, rank, dest, src, rc, tag=1;
35
char inmsg, outmsg='x';
MPI_Status Stat;
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0) {
dest = 1;
src = 1;
rc = MPI_Send(&outmsg, 1, MPI_CHAR, dest, tag,
MPI_COMM_WORLD);
rc = MPI_Recv(&inmsg, 1, MPI_CHAR, src, tag,
MPI_COMM_WORLD, &Stat);
}
else
if (rank == 1) {
dest = 0;
src = 0;
rc = MPI_Recv(&inmsg, 1, MPI_CHAR, src, tag,
MPI_COMM_WORLD, &Stat);
rc = MPI_Send(&outmsg, 1, MPI_CHAR, dest, tag,
MPI_COMM_WORLD);
}
MPI_Finalize();
}
<ke_^mxs_fijbf_j_dZ`^ucijhp_kkkq_lgufghf_jhfihkueZ_lkhh[s_gb_
k\h_fmkhk_^mkghf_jhfgZ_^bgbpm[hevrbf>hihegbl_evghihklZ\e_gZijh
\_jdZ^eyijhp_kkZkfZdkbfZevgufghf_jhfqlh[uhgg_ihkeZekhh[s_gb_
g_kms_kl\mxs_fmijhp_kkmIhdZaZgZlhevdhko_fZijh]jZffu
#include "mpi.h"
#include <stdio.h>
main(int argc, char **argv)
{
int me, size;
int SOME_TAG=0;
MPI_Status status;
…
MPI_Init (&argc, &argv);
MPI_Comm_rank (MPI_COMM_WORLD, &me);
MPI_Comm_size (MPI_COMM_WORLD, &size);
36
if ((me % 2) == 0) {
if ((me+1) < sizeihkueZxl\k_ijhp_kkudjhf_
ihke_^g_]h
MPI_Send (…, me+1, SOME_TAG, MPI_COMM_WORLD);
}
else
MPI_Recv (…, me-1, SOME_TAG, MPI_COMM_WORLD, &status);
…
MPI_Finalize();
}
< dZq_kl\_ ghf_jZ ijhp_kkZ-hlijZ\bl_ey fh`gh mdZaZlv ij_^hij_^_e_ggmx
dhgklZglmMPI_ANY_SOURCE — ijbagZdlh]hqlhih^oh^blkhh[s_gb_hlex[h]h
ijhp_kkZ<dZq_kl\_b^_glbnbdZlhjZijbgbfZ_fh]hkhh[s_gbyfh`ghmdZaZlv
dhgklZglm MPI_ANY_TAG — wlhijbagZdlh]hqlhih^oh^blkhh[s_gb_kex[uf
b^_glbnbdZlhjhfIjbh^gh\j_f_gghfbkihevah\Zgbbwlbo^\modhgklZgl[m
^_lijbgylhex[h_khh[s_gb_hlex[h]hijhp_kkZ
IZjZf_lju ijbgylh]h khh[s_gby \k_]^Z fh`gh hij_^_eblv ih khhl\_lkl\mx
sbf iheyf kljmdlmju status Ij_^hij_^_e_gguc lbi MPI_Status hibkZg \
nZce_ mpi.h < yaud_ Kb iZjZf_lj status y\ey_lky kljmdlmjhc kh^_j`Zs_c
iheykbf_gZfb MPI_SOURCE, MPI_TAGb MPI_ERRORJ_Zevgu_agZq_gbyghf_jZ
ijhp_kkZ-hlijZ\bl_ey b^_glbnbdZlhjZ khh[s_gby b dh^Z hrb[db ^hklmigu
q_j_a status.MPI_SOURCE, status.MPI_TAG b status.MPI_ERROR < NhjljZg_
iZjZf_lj statusy\ey_lkyp_ehqbke_gguffZkkb\hfjZaf_jZ MPI_STATUS_SIZE.
DhgklZglu MPI_SOURCE, MPI_TAGb MPI_ERRORy\eyxlkybg^_dkZfbih^Zgghfm
fZkkb\m ^ey ^hklmiZ d agZq_gbyf khhl\_lkl\mxsbo ihe_c gZijbf_j
status(MPI_SOURCE).
H[jZlbf \gbfZgb_ gZ g_dhlhjmx g_kbff_ljbqghklv hi_jZpbc ihkuedb b
ijb_fZkhh[s_gbcKihfhsvxdhgklZglu MPI_ANY_SOURCEfh`ghijbgylvkh
h[s_gb_hlex[h]hijhp_kkZH^gZdh\kemqZ_ihkuedb^Zgguolj_[m_lkyy\gh
mdZaZlvghf_jijbgbfZxs_]hijhp_kkZ
< klZg^Zjl_ h]h\hj_gh qlh _keb h^bg ijhp_kk ihke_^h\Zl_evgh ihkueZ_l ^\Z
khh[s_gby ^jm]hfm ijhp_kkm b h[Z wlb khh[s_gby khhl\_lkl\mxl h^ghfm b
lhfm`_\uah\m MPI_Recvlhi_j\uf[m^_lijbgylhkhh[s_gb_dhlhjh_[ueh
hlijZ\e_ghjZgvr_<f_kl_kl_f_keb^\Zkhh[s_gby[uebh^gh\j_f_gghhl
ijZ\e_gujZagufbijhp_kkZfbbh[Zkhh[s_gbykhhl\_lkl\mxlh^ghfmblhfm
`_\uah\m MPI_Recvlhihjy^hdboihemq_gbyijbgbfZxsbfijhp_kkhfaZjZ
g__g_hij_^_e_g
37
Ihke_^g__ aZf_qZgb_ hlghkbl_evgh bkihevah\Zgby [ehdbjmxsbo nmgdpbc
ijb_fZbihkuedbk\yaZghk\hafh`guf\hagbdgh\_gb_flmibdh\hckblmZpbb
Ij_^iheh`bfqlhjZ[hlZxl^\ZiZjZee_evguoijhp_kkZbhgbohlylh[f_gylv
ky^Zggufb;ueh[u\iheg__kl_kl\_ggh\dZ`^hfijhp_kk_kgZqZeZ\hkihev
ah\Zlvkynmgdpb_c MPI_SendZaZl_f MPI_Recv.Ghbf_gghwlh]hbg_klhbl^_
eZlv>_eh\lhfqlhfuaZjZg__g_agZ_fdZdj_Zebah\ZgZnmgdpby MPI_Send.
?kebjZajZ[hlqbdb^ey]ZjZglbbdhjj_dlgh]hih\lhjgh]hbkihevah\Zgby[mn_
jZ ihkuedb aZeh`beb ko_fm ijb dhlhjhc ihkueZxsbc ijhp_kk `^_l gZqZeZ
ijb_fZlh\hagbdg_ldeZkkbq_kdbclmibdI_j\ucijhp_kkg_fh`_l\_jgmlvky
banmgdpbbihkuedbihkdhevdm\lhjhcg_gZqbgZ_lijb_fkhh[s_gby:\lh
jhc ijhp_kk g_ fh`_l gZqZlv ijb_f khh[s_gby ihkdhevdm kZf ih ihoh`_c
ijbqbg_aZkljyegZihkued_<uoh^bawlhckblmZpbbijhklGm`ghbkihevah
\Zlv eb[h g_[ehdbjmxsb_ nmgdpbb ijb_fZi_j_^Zqb eb[h nmgdpbx kh\f_
s_gghci_j_^Zqbbijb_fZH[Z\ZjbZglZfuh[km^bfgb`_
int MPI_Get_count(MPI_Status *status, MPI_Datatype datatype, int
*count)
• status — iZjZf_ljuijbgylh]hkhh[s_gby
• datatype — lbiwe_f_glh\ijbgylh]hkhh[s_gby
• OUT count — qbkehwe_f_glh\khh[s_gby
Ih agZq_gbx iZjZf_ljZ status ^ZggZynmgdpbyhij_^_ey_lqbkehm`_ijbgy
luo ihke_ h[jZs_gby d MPI_Recv beb ijbgbfZ_fuo ihke_ h[jZs_gby d
MPI_Probe beb MPI_Iprobewe_f_glh\khh[s_gbylbiZdatatype>ZggZynmgd
pby\qZklghklbg_h[oh^bfZ^eyhij_^_e_gbyjZaf_jZh[eZklbiZfylb\u^_
ey_fhc^eyojZg_gbyijbgbfZ_fh]hkhh[s_gby
int MPI_Probe(int source, int msgtag, MPI_Comm comm, MPI_Status
*status)
• source — ghf_jijhp_kkZ-hlijZ\bl_eybebMPI_ANY_SOURCE;
• msgtag — b^_glbnbdZlhjh`b^Z_fh]hkhh[s_gbybebMPI_ANY_TAG;
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT status — iZjZf_ljugZc^_ggh]hih^oh^ys_]hkhh[s_gby
Ihemq_gb_ bgnhjfZpbb h kljmdlmj_ h`b^Z_fh]h khh[s_gby k [ehdbjh\dhc
<ha\jZlZbanmgdpbbg_ijhbahc^_l^hl_oihjihdZkhh[s_gb_kih^oh^ysbf
b^_glbnbdZlhjhfbghf_jhfijhp_kkZ-hlijZ\bl_eyg_[m^_l^hklmigh^eyih
emq_gby :ljb[mlu ^hklmigh]h khh[s_gby fh`gh hij_^_eblv h[uqguf h[jZ
ahfkihfhsvxiZjZf_ljZ statusKe_^m_lhkh[hh[jZlblv\gbfZgb_gZlhqlh
nmgdpbyhij_^_ey_llhevdhnZdlijboh^Zkhh[s_gbyghj_Zevgh_]hg_ijbgb
fZ_l
38
Ijb_fi_j_^ZqZkhh[s_gbc[_a[ehdbjh\db <hlebqb_hlnmgdpbck[ehdbjh\
dhc\ha\jZlbanmgdpbc^Zgghc]jmiiuijhbkoh^blkjZam[_adZdhc-eb[h[eh
dbjh\dbijhp_kkh\GZnhg_^Zevg_cr_]h\uiheg_gbyijh]jZffuh^gh\j_f_g
gh ijhbkoh^bl b h[jZ[hldZ Zkbgojhggh aZims_gghc hi_jZpbb < ijbgpbi_
^ZggZy \hafh`ghklv bkdexqbl_evgh ihe_agZ ^ey kha^Zgby wnn_dlb\guo ijh
]jZff<kZfhf^_e_ijh]jZffbklagZ_lqlh\g_dhlhjucfhf_gl_fmihlj_[m_lkyfZkkb\dhlhjuc\uqbkey_l^jm]hcijhp_kkHgaZjZg__\uklZ\ey_l\ijh
]jZff_ZkbgojhggucaZijhkgZihemq_gb_^Zggh]hfZkkb\ZZ^hlh]hfhf_glZ
dh]^ZfZkkb\j_Zevghihlj_[m_lkyhgfh`_l\uihegylvex[mx^jm]mxihe_a
gmx jZ[hlm Hiylv `_ \h fgh]bo kemqZyo kh\_jr_ggh g_ h[yaZl_evgh ^h`b
^ZlvkyhdhgqZgbyihkuedbkhh[s_gby^ey\uiheg_gbyihke_^mxsbo\uqbke_
gbc
?keb_klv\hafh`ghklvhi_jZpbbijb_fZi_j_^Zqbkhh[s_gbckdjulvgZnhg_
\uqbke_gbclhwlbf\jh^_[ugZ^h[_ah]h\hjhqghihevah\ZlvkyH^gZdhgZ
ijZdlbd_g_\k_kh]eZkm_lkykl_hjb_cFgh]h_aZ\bkblhldhgdj_lghcj_ZebaZ
pbb D kh`Ze_gbx ^Ze_dh g_ \k_]^Z Zkbgojhggu_ hi_jZpbb wnn_dlb\gh ih^
^_j`b\Zxlky ZiiZjZlmjhc b kbkl_fguf hdjm`_gb_f Ihwlhfm g_ klhbl m^b\
eylvky _keb wnn_dl hl \uiheg_gby \uqbke_gbc gZ nhg_ i_j_kuehd hdZ`_lky
gme_\uf K^_eZggu_ aZf_qZgby dZkZxlky lhevdh \hijhkh\ wnn_dlb\ghklb <
hlghr_gbbij_^hklZ\ey_fhcnmgdpbhgZevghklbZkbgojhggu_hi_jZpbbbkdex
qbl_evghihe_aguihwlhfmhgbijbkmlkl\mxlijZdlbq_kdb\dZ`^hcj_Zevghc
ijh]jZff_
int MPI_Isend(void *buf, int count, MPI_Datatype datatype, int dest,
int msgtag, MPI_Comm comm, MPI_Request *request)
• buf — Z^j_kgZqZeZ[mn_jZcihkueZ_fufkhh[s_gb_f
• count — qbkehi_j_^Z\Z_fuowe_f_glh\\khh[s_gbb
• datatype — lbii_j_^Z\Z_fuowe_f_glh\
• dest — ghf_jijhp_kkZ-ihemqZl_ey
• msgtag — b^_glbnbdZlhjkhh[s_gby
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT request — b^_glbnbdZlhjZkbgojhgghchi_jZpbb
I_j_^ZqZkhh[s_gbyZgZeh]bqgZ\uah\m MPI_Sendh^gZdh\ha\jZlbanmgdpbb
MPI_Isend ijhbkoh^blkjZamihke_bgbpbZebaZpbbijhp_kkZi_j_^Zqb[_ah`b
^Zgby h[jZ[hldb \k_]h khh[s_gby gZoh^ys_]hky \ [mn_j_ buf Wlh hagZqZ_l
qlhg_evayih\lhjghbkihevah\Zlv^Zgguc[mn_j^ey^jm]bop_e_c[_aihemq_
gby^hihegbl_evghcbgnhjfZpbbih^l\_j`^Zxs_caZ\_jr_gb_^Zgghcihkue
db Hij_^_eblv lhl fhf_gl \j_f_gb dh]^Z fh`gh ih\lhjgh bkihevah\Zlv [m
n_j buf [_a hiZk_gby bkihjlblv i_j_^Z\Z_fh_ khh[s_gb_ fh`gh k ihfhsvx
iZjZf_ljZrequestbnmgdpbcMPI_Wait bMPI_Test.
39
:gZeh]bqgh lj_f fh^bnbdZpbyf nmgdpbb MPI_Send ij_^mkfhlj_gu ljb ^h
ihegbl_evguo\ZjbZglZnmgdpbc MPI_Ibsend, MPI_Issend, MPI_IrsendDbaeh
`_gghc\ur_k_fZglbd_jZ[hluwlbonmgdpbc^h[Z\ey_lkyZkbgojhgghklv
int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int source,
int msgtag, MPI_Comm comm, MPI_Request *request)
• OUT buf — Z^j_kgZqZeZ[mn_jZ^eyijb_fZkhh[s_gby
• count — fZdkbfZevgh_qbkehwe_f_glh\\ijbgbfZ_fhfkhh[s_gbb
• datatype — lbiwe_f_glh\ijbgbfZ_fh]hkhh[s_gby
• source — ghf_jijhp_kkZ-hlijZ\bl_ey
• msgtag — b^_glbnbdZlhjijbgbfZ_fh]hkhh[s_gby
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT request — b^_glbnbdZlhj hi_jZpbb Zkbgojhggh]h ijb_fZ khh[s_
gby
Ijb_f khh[s_gby ZgZeh]bqguc MPI_Recv h^gZdh \ha\jZl ba nmgdpbb ijhbk
oh^bl kjZam ihke_ bgbpbZebaZpbb ijhp_kkZ ijb_fZ [_a h`b^Zgby ihemq_gby
\k_]hkhh[s_gbyb_]haZibkb\[mn_j_bufHdhgqZgb_ijhp_kkZijb_fZfh`gh
hij_^_eblv k ihfhsvx iZjZf_ljZ request b ijhp_^mj lbiZ MPI_Wait b
MPI_Test.
Khh[s_gb_hlijZ\e_ggh_ex[hcbanmgdpbc MPI_Send, MPI_Isendbex[hcba
lj_o bo fh^bnbdZpbc fh`_l [ulv ijbgylh ex[hc ba ijhp_^mj MPI_Recv b
MPI_Irecv.
Kihfhsvx^Zgghcnmgdpbbe_]dhh[hclb\hafh`gmxlmibdh\mxkblmZpbxh
dhlhjhc]h\hjbehkvjZg__AZf_gbf\uah\nmgdpbbijb_fZkhh[s_gbyk[ehdb
jh\dhcgZ\uah\nmgdpbb MPI_IrecvJZkiheh`bf_]hi_j_^\uah\hfnmgdpbb
MPI_Sendl_ij_h[jZam_fnjZ]f_glke_^mxsbfh[jZahf
…
MPI_Send (…)
MPI_Recv(…)
…
…
MPI_Irecv (…)
MPI_Send (…)
…
< lZdhc kblmZpbb lmibd ]ZjZglbjh\Zggh g_ \hagbdg_l ihkdhevdm d fhf_glm
\uah\ZnmgdpbbMPI_Send aZijhkgZijb_fkhh[s_gbym`_[m^_l\uklZ\e_g
int MPI_Wait(MPI_Request *request, MPI_Status *status)
• request — b^_glbnbdZlhjhi_jZpbbZkbgojhggh]hijb_fZbebi_j_^Zqb
• OUT status — iZjZf_ljukhh[s_gby
H`b^Zgb_aZ\_jr_gbyZkbgojhgghchi_jZpbbZkkhpbbjh\Zgghckb^_glbnbdZ
lhjhf request b aZims_gghc nmgdpb_c MPI_Isend beb MPI_Irecv IhdZ Zkbg
40
ojhggZy hi_jZpby g_ [m^_l aZ\_jr_gZ ijhp_kk \uihegb\rbc nmgdpbx
MPI_Wait[m^_laZ[ehdbjh\Zg?kebj_qvb^_lhijb_f_Zljb[mlub^ebgmijb
gylh]hkhh[s_gbyfh`ghhij_^_eblvh[uqgufh[jZahfkihfhsvxiZjZf_ljZ
status.
int MPI_Waitall(int count, MPI_Request *requests, MPI_Status
*statuses)
• count — qbkehb^_glbnbdZlhjh\Zkbgojhgguohi_jZpbc
• requests — b^_glbnbdZlhju hi_jZpbc Zkbgojhggh]h ijb_fZ beb i_j_
^Zqb
• OUT statuses — iZjZf_ljukhh[s_gbc
<uiheg_gb_ijhp_kkZ[ehdbjm_lky^hl_oihjihdZ\k_hi_jZpbbh[f_gZZkkh
pbbjh\Zggu_ k mdZaZggufb b^_glbnbdZlhjZfb g_ [m^ml aZ\_jr_gu ?keb \h
\j_fyh^ghcbebg_kdhevdbohi_jZpbch[f_gZ\hagbdebhrb[dblhihe_hrb[
db\we_f_glZofZkkb\Z statuses[m^_lmklZgh\e_gh\khhl\_lkl\mxs__agZq_
gb_
Gb`_ ihdZaZg ijbf_j ijh]jZffu \ dhlhjhc \k_ ijhp_kku h[f_gb\Zxlky kh
h[s_gbyfbk[eb`Zcrbfbkhk_^yfb\khhl\_lkl\bbklhiheh]b_cdhevpZ
#include "mpi.h"
#include <stdio.h>
int main(int argc, char **argv)
{
int numtasks, rank, next, prev, buf[2], tag1=1, tag2=2;
MPI_Request reqs[4];
MPI_Status stats[4];
MPI_Init(&argc,&argv);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
prev = rank
next = rank
if (rank ==
if (rank ==
– 1;
+ 1;
0) prev = numtasks – 1;
(numtasks – 1)) next = 0;
MPI_Irecv(&buf[0], 1, MPI_INT, prev, tag1, MPI_COMM_WORLD,
&reqs[0]);
MPI_Irecv(&buf[1], 1, MPI_INT, next, tag2, MPI_COMM_WORLD,
&reqs[1]);
41
MPI_Isend(&rank, 1, MPI_INT, prev, tag2, MPI_COMM_WORLD,
&reqs[2]);
MPI_Isend(&rank, 1, MPI_INT, next, tag1, MPI_COMM_WORLD,
&reqs[3]);
MPI_Waitall(4, reqs, stats);
MPI_Finalize();
}
int MPI_Waitany( int count, MPI_Request *requests, int *index,
MPI_Status *status)
• count — qbkehb^_glbnbdZlhjh\Zkbgojhgguohi_jZpbc
• requests — b^_glbnbdZlhju hi_jZpbc Zkbgojhggh]h ijb_fZ beb i_j_
^Zqb
• OUT index — ghf_jaZ\_jr_gghchi_jZpbbh[f_gZ
• OUT status — iZjZf_ljukhh[s_gbc
<uiheg_gb_ ijhp_kkZ [ehdbjm_lky ^h l_o ihj ihdZ dZdZy-eb[h ZkbgojhggZy
hi_jZpbyh[f_gZZkkhpbbjh\ZggZykmdZaZggufbb^_glbnbdZlhjZfbg_[m^_l
aZ\_jr_gZ ?keb aZ\_jrbebkv g_kdhevdh hi_jZpbc lh kemqZcgufh[jZahf[m
^_l\u[jZgZh^gZbagboIZjZf_lj index kh^_j`blghf_jwe_f_glZ\fZkkb\_
requestskh^_j`Zs_]hb^_glbnbdZlhjaZ\_jr_gghchi_jZpbb
int MPI_Waitsome( int incount, MPI_Request *requests, int *outcount,
int *indexes, MPI_Status *statuses)
• incount — qbkehb^_glbnbdZlhjh\Zkbgojhgguohi_jZpbc
• requests — b^_glbnbdZlhju hi_jZpbc Zkbgojhggh]h ijb_fZ beb i_j_
^Zqb
• OUT outcount — qbkehb^_glbnbdZlhjh\aZ\_jrb\rbokyhi_jZpbch[f_
gZ
• OUT indexes — fZkkb\ghf_jh\aZ\_jrb\rbokyhi_jZpbbh[f_gZ
• OUT statuses — iZjZf_ljuaZ\_jrb\rbokykhh[s_gbc
<uiheg_gb_ijhp_kkZ[ehdbjm_lky^hl_oihjihdZohly[uh^gZbahi_jZpbc
h[f_gZZkkhpbbjh\ZgguokmdZaZggufbb^_glbnbdZlhjZfbg_[m^_laZ\_jr_
gZ IZjZf_lj outcount kh^_j`bl qbkeh aZ\_jr_gguo hi_jZpbc Z i_j\u_
outcount we_f_glh\ fZkkb\Z indexes kh^_j`Zl ghf_jZ we_f_glh\ fZkkb\Z
requests k bo b^_glbnbdZlhjZfb I_j\u_ outcount we_f_glh\ fZkkb\Z
statuseskh^_j`ZliZjZf_ljuaZ\_jr_gguohi_jZpbc
int MPI_Test(MPI_Request *request, int *flag, MPI_Status *status)
• request — b^_glbnbdZlhjhi_jZpbbZkbgojhggh]hijb_fZbebi_j_^Zqb
42
• OUT flag — ijbagZdaZ\_jr_gghklbhi_jZpbbh[f_gZ
• OUT status — iZjZf_ljukhh[s_gby
Ijh\_jdZaZ\_jr_gghklbZkbgojhgguonmgdpbc MPI_Isendbeb MPI_IrecvZk
khpbbjh\Zgguo k b^_glbnbdZlhjhf request < iZjZf_lj_ flag nmgdpby
MPI_Test\ha\jZsZ_lagZq_gb_ 1_kebkhhl\_lkl\mxsZyhi_jZpbyaZ\_jr_gZb
agZq_gb_0\ijhlb\ghfkemqZ_?kebaZ\_jr_gZijhp_^mjZijb_fZlhZljb[mlu
b^ebgmihemq_ggh]hkhh[s_gbyfh`ghhij_^_eblvh[uqgufh[jZahfkihfh
svxiZjZf_ljZstatus.
int MPI_Testall( int count, MPI_Request *requests, int *flag,
MPI_Status *statuses)
• count — qbkehb^_glbnbdZlhjh\Zkbgojhgguohi_jZpbc
• requests — b^_glbnbdZlhju hi_jZpbc Zkbgojhggh]h ijb_fZ beb i_j_
^Zqb
• OUT flag — ijbagZdaZ\_jr_gghklbhi_jZpbch[f_gZ
• OUT statuses — iZjZf_ljukhh[s_gbc
<iZjZf_lj_ flagnmgdpby\ha\jZsZ_lagZq_gb_ 1_keb\k_hi_jZpbbZkkhpbb
jh\Zggu_ k mdZaZggufb b^_glbnbdZlhjZfb aZ\_jr_gu < wlhf kemqZ_ iZjZ
f_ljukhh[s_gbc[m^mlmdZaZgu\fZkkb\_ statuses?kebdZdZy-eb[hbahi_
jZpbcg_aZ\_jrbeZkvlh\ha\jZsZ_lky 0bhij_^_e_gghklvwe_f_glh\fZkkb\Z
statusesg_]ZjZglbjm_lky
int MPI_Testany(int count, MPI_Request *requests, int *index,
*flag, MPI_Status *status)
int
• count — qbkehb^_glbnbdZlhjh\Zkbgojhgguohi_jZpbc
• requests — b^_glbnbdZlhju hi_jZpbc Zkbgojhggh]h ijb_fZ beb i_j_
^Zqb
• OUT index — ghf_jaZ\_jr_gghchi_jZpbbh[f_gZ
• OUT flag — ijbagZdaZ\_jr_gghklbhi_jZpbbh[f_gZ
• OUT status — iZjZf_ljukhh[s_gby
?kebdfhf_glm\uah\Znmgdpbb MPI_Testanyohly[uh^gZbahi_jZpbcZkbg
ojhggh]h h[f_gZ aZ\_jrbeZkv lh \ iZjZf_lj_ flag \ha\jZsZ_lky agZq_gb_ 1,
index kh^_j`bl ghf_j khhl\_lkl\mxs_]h we_f_glZ \ fZkkb\_ requests Z
status — iZjZf_lju khh[s_gby < ijhlb\ghf kemqZ_ \ iZjZf_lj_ flag [m^_l
\ha\jZs_ghagZq_gb_0.
int MPI_Testsome( int incount, MPI_Request *requests, int *outcount,
int *indexes, MPI_Status *statuses)
• incount — qbkehb^_glbnbdZlhjh\Zkbgojhgguohi_jZpbc
43
• requests — b^_glbnbdZlhju hi_jZpbc Zkbgojhggh]h ijb_fZ beb i_j_
^Zqb
• OUT outcount — qbkehb^_glbnbdZlhjh\aZ\_jrb\rbokyhi_jZpbch[f_
gZ
• OUT indexes — fZkkb\ghf_jh\aZ\_jrb\rbokyhi_jZpbbh[f_gZ
• OUT statuses — iZjZf_ljuaZ\_jrb\rbokyhi_jZpbc
>ZggZy nmgdpby jZ[hlZ_l lZd `_ dZd b MPI_Waitsome aZ bkdexq_gb_f lh]h
qlh \ha\jZl ijhbkoh^bl g_f_^e_ggh ?keb gb h^gZ ba mdZaZgguo hi_jZpbc g_
aZ\_jrbeZkvlhagZq_gb_outcount[m^_ljZ\ghgmex
int MPI_Iprobe( int source, int msgtag, MPI_Comm comm, int *flag,
MPI_Status *status)
• source — ghf_jijhp_kkZ-hlijZ\bl_eybebMPI_ANY_SOURCE;
• msgtag — b^_glbnbdZlhjh`b^Z_fh]hkhh[s_gbybebMPI_ANY_TAG;
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT flag — ijbagZdaZ\_jr_gghklbhi_jZpbbh[f_gZ
• OUT status — iZjZf_ljuih^oh^ys_]hkhh[s_gby
Ihemq_gb_bgnhjfZpbbhihklmie_gbbbkljmdlmj_h`b^Z_fh]hkhh[s_gby[_a
[ehdbjh\db<iZjZf_lj_flag\ha\jZsZ_lkyagZq_gb_1_kebkhh[s_gb_kih^
oh^ysbfb Zljb[mlZfb m`_ fh`_l [ulv ijbgylh \ wlhf kemqZ_ __ ^_ckl\b_
iheghklvxZgZeh]bqghMPI_ProbebagZq_gb_0_kebkhh[s_gbykmdZaZggufb
Zljb[mlZfb_s_g_l
H[t_^bg_gb_ aZijhkh\ gZ \aZbfh^_ckl\b_ Ijhp_^mju ^Zgghc ]jmiiu iha\h
eyxl kgbablv gZdeZ^gu_ jZkoh^u \hagbdZxsb_ \ jZfdZo h^gh]h ijhp_kkhjZ
ijbh[jZ[hld_ijb_fZi_j_^Zqbbi_j_f_s_gbbg_h[oh^bfhcbgnhjfZpbbf_
`^m ijhp_kkhf b k_l_\uf dhgljhee_jhf G_kdhevdh aZijhkh\ gZ ijb_f bbeb
i_j_^Zqmfh]mlh[t_^bgylvky\f_kl_^eylh]hqlh[u^Ze__bofh`gh[ueh[u
aZimklblvh^ghcdhfZg^hcKihkh[ijb_fZkhh[s_gbygbdZdg_aZ\bkblhlkihkh[Z_]hihkuedbkhh[s_gb_hlijZ\e_ggh_kihfhsvxh[t_^bg_gbyaZijhkh\
eb[hh[uqgufkihkh[hffh`_l[ulvijbgylhdZdh[uqgufkihkh[hflZdbk
ihfhsvxh[t_^bg_gbyaZijhkh\
int MPI_Send_init( void *buf, int count, MPI_Datatype datatype, int
dest, int msgtag, MPI_Comm comm, MPI_Request *request)
• buf — Z^j_kgZqZeZ[mn_jZkihkueZ_fufkhh[s_gb_f
• count — qbkehi_j_^Z\Z_fuowe_f_glh\\khh[s_gbb
• datatype — lbii_j_^Z\Z_fuowe_f_glh\
• dest — ghf_jijhp_kkZ-ihemqZl_ey
44
• msgtag — b^_glbnbdZlhjkhh[s_gby
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT request — b^_glbnbdZlhjZkbgojhgghci_j_^Zqb
Nhjfbjh\Zgb_aZijhkZgZ\uiheg_gb_i_j_kuedb^Zgguo<k_iZjZf_ljulhq
ghlZdb_`_dZdbmih^ijh]jZffu MPI_Isendh^gZdh\hlebqb_hlg__i_j_
kuedZ g_ gZqbgZ_lky ^h \uah\Z ih^ijh]jZffu MPI_Startall DZd b ij_`^_
^hihegbl_evghij_^mkfhlj_gu\ZjbZglub^eylj_ofh^bnbdZpbcihkuedbkh
h[s_gbcMPI_Bsend_init, MPI_Ssend_init, MPI_Rsend_init.
int MPI_Recv_init( void *buf, int count, MPI_Datatype datatype, int
source, int msgtag, MPI_Comm comm, MPI_Request *request)
• OUT buf — Z^j_kgZqZeZ[mn_jZijb_fZkhh[s_gby
• count — qbkehijbgbfZ_fuowe_f_glh\\khh[s_gbb
• datatype — lbiijbgbfZ_fuowe_f_glh\
• source — ghf_jijhp_kkZ-hlijZ\bl_ey
• msgtag — b^_glbnbdZlhjkhh[s_gby
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT request — b^_glbnbdZlhjZkbgojhggh]hijb_fZ
Nhjfbjh\Zgb_aZijhkZgZ\uiheg_gb_ijb_fZkhh[s_gby<k_iZjZf_ljulhq
gh lZdb_ `_ dZd b m nmgdpbb MPI_Irecv h^gZdh \ hlebqb_ hl g__ j_Zevguc
ijb_fg_gZqbgZ_lky^h\uah\ZnmgdpbbMPI_Startall.
MPI_Startall(int count, MPI_Request *requests)
• count — qbkehaZijhkh\gZ\aZbfh^_ckl\b_
• OUT requests — fZkkb\b^_glbnbdZlhjh\ijb_fZi_j_^Zqb
AZimkd\k_ohleh`_gguohi_jZpbci_j_^Zqbbijb_fZZkkhpbbjh\Zgguokwe_
f_glZfb fZkkb\Z aZijhkh\ requests b bgbpbbjh\Zgguo nmgdpbyfb
MPI_Recv_init, MPI_Send_initbeb__lj_fyfh^bnbdZpbyfb<k_hleh`_ggu_
\aZbfh^_ckl\byaZimkdZxlky\j_`bf_[_a[ehdbjh\dbZboaZ\_jr_gb_fh`gh
hij_^_eblv h[uqguf h[jZahf k ihfhsvx nmgdpbc k_f_ckl\ MPI_Wait b
MPI_Test.
Kh\f_s_ggu_ ijb_f b i_j_^ZqZ khh[s_gbc Kh\f_s_gb_ ijb_fZ b i_j_^Zqb
khh[s_gbcf_`^mijhp_kkZfbiha\hey_le_]dhh[oh^blvfgh`_kl\hih^\h^guo
dZfg_ck\yaZgguok\hafh`gufblmibdh\ufbkblmZpbyfbIj_^iheh`bfqlh
\ ebg_cd_ ijhp_kkh\ g_h[oh^bfh hj]Zgbah\Zlv h[f_g ^Zggufb f_`^m i-f b
(i+1)-uf ijhp_kkZfb ?keb \hkihevah\Zlvky klZg^Zjlgufb [ehdbjmxsbfb
nmgdpbyfb ihkuedb khh[s_gbc lh \hafh`_g lmibd h[km`^Z\rbcky jZg__
45
H^bgbakihkh[h\h[oh^ZlZdhckblmZpbbkhklhbl\bkihevah\Zgbbnmgdpbbkh
\f_s_ggh]hijb_fZbi_j_^Zqb
int MPI_Sendrecv( void *sbuf, int scount, MPI_Datatype stype, int
dest, int stag, void *rbuf, int rcount, MPI_Datatype rtype, int
source, MPI_Datatype rtag, MPI_Comm comm, MPI_Status *status)
• sbuf — Z^j_kgZqZeZ[mn_jZkihkueZ_fufkhh[s_gb_f
• scount — qbkehi_j_^Z\Z_fuowe_f_glh\\khh[s_gbb
• stype — lbii_j_^Z\Z_fuowe_f_glh\
• dest — ghf_jijhp_kkZ-ihemqZl_ey
• stag — b^_glbnbdZlhjihkueZ_fh]hkhh[s_gby
• OUT rbuf — Z^j_kgZqZeZ[mn_jZijb_fZkhh[s_gby
• rcount — qbkehijbgbfZ_fuowe_f_glh\khh[s_gby
• rtype — lbiijbgbfZ_fuowe_f_glh\
• source — ghf_jijhp_kkZ-hlijZ\bl_ey
• rtag — b^_glbnbdZlhjijbgbfZ_fh]hkhh[s_gby
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
• OUT status — iZjZf_ljuijbgylh]hkhh[s_gby
>ZggZy hi_jZpby h[t_^bgy_l \ _^bghf aZijhk_ ihkuedm b ijb_f khh[s_gbc
?kl_kl\_ggh qlh j_ZebaZpby wlhc nmgdpbb ]ZjZglbjm_l hlkmlkl\b_ lmibdh\
dhlhju_fh]eb[u\hagbdgmlvf_`^mijhp_kkZfbijbbkihevah\Zgbbh[uqguo
[ehdbjmxsbohi_jZpbc MPI_Sendb MPI_RecvIjbgbfZxsbcbhlijZ\eyxsbc
ijhp_kkufh]mly\eylvkyh^gbfbl_f`_ijhp_kkhf;mn_jZijb_fZbihkuedb
h[yaZl_evgh ^he`gu [ulv jZaebqgufb Khh[s_gb_ hlijZ\e_ggh_ hi_jZpb_c
MPI_Sendrecvfh`_l[ulvijbgylhh[uqgufh[jZahfblhqghlZd`_hi_jZpby
MPI_Sendrecv fh`_l ijbgylv khh[s_gb_ hlijZ\e_ggh_ h[uqghc hi_jZpb_c
MPI_Send.
5. AZ^Zgby
• GZqgbl_ kha^Z\Zlv iZjZee_evguc \ZjbZgl ijh]jZffu j_Zebamx
s_cf_lh^=ZmkkZj_r_gbykbkl_febg_cguoZe]_[jZbq_kdbomjZ\
g_gbcbkihevamybamq_ggu_nmgdpbbMPI.
• Ibg]-ihg]Kfh^_ebjh\Zlvihke_^h\Zl_evguch[f_gkhh[s_gbyfb
f_`^m^\mfyijhp_kkZfbaZf_jblv\j_fygZh^gmbl_jZpbxh[f_
gZhij_^_eblvaZ\bkbfhklv\j_f_gbhl^ebgukhh[s_gby
• KjZ\gblv wnn_dlb\ghklv j_ZebaZpbb jZaebqguo \b^h\ i_j_kuehd
^Zgguof_`^m^\mfy\u^_e_ggufbijhp_kkhjZfb
• Fh`gh eb \ ijhp_kk_ jZ[hlu 03,-ijh]jZffu ihjh`^Zlv gh\u_
ijhp_kku_kebhk\h[h^bebkvk\h[h^gu_ijhp_kkhju"
46
• Fh]ml eb jZaebqgu_ ijhp_kku 03,-ijh]jZffu aZibku\Zlv h^gh
\j_f_gghZgZh^bgblhl`_^bkd"[\h^bgblhl`_nZce"
• Fh`_leb03,-ijh]jZffZijh^he`ZlvjZ[hlmihke_Z\Zjbcgh]haZ
\_jr_gbyh^gh]hbaijhp_kkh\"
• Fh]mleb]jmiiuijhp_kkh\bf_lvg_imklh_i_j_k_q_gb_g_kh\iZ
^Zxs__gbkh^ghcbagboiheghklvx"
• Fh`ghebkhh[s_gb_hlijZ\e_ggh_kihfhsvx[ehdbjmxs_chi_
jZpbbihkuedbijbgylvg_[ehdbjmxs_chi_jZpb_cijb_fZ"
• Qlh]ZjZglbjm_l[ehdbjh\dZijbhlijZ\d_ijb_f_khh[s_gbc"
• DZdijbgylvex[h_khh[s_gb_hlex[h]hijhp_kkZ"
AZgylb_L_ogheh]byMPIijh^he`_gb_
1. Dhee_dlb\gu_\aZbfh^_ckl\byijhp_kkh\
<hi_jZpbyodhee_dlb\gh]h\aZbfh^_ckl\byijhp_kkh\mqZkl\mxl\k_ijhp_k
kudhffmgbdZlhjZKhhl\_lkl\mxsZyijhp_^mjZ^he`gZ[ulv\ua\ZgZdZ`^uf
ijhp_kkhf[ulvfh`_lkhk\hbfgZ[hjhfiZjZf_ljh\<ha\jZlbaijhp_^mju
dhee_dlb\gh]h \aZbfh^_ckl\by fh`_l ijhbahclb \ lhl fhf_gl dh]^Z mqZklb_
ijhp_kkZ\^Zgghchi_jZpbbm`_aZdhgq_ghDZdb^ey[ehdbjmxsboijhp_^mj
\ha\jZlhagZqZ_llhqlhjZaj_r_gk\h[h^guc^hklmid[mn_jmijb_fZbebih
kuedb:kbgojhgguodhee_dlb\guohi_jZpbc\MPIg_l
< dhee_dlb\guo hi_jZpbyo fh`gh bkihevah\Zlv l_ `_ dhffmgbdZlhju qlh b
[ueb bkihevah\Zgu ^ey hi_jZpbc lbiZ lhqdZ-lhqdZ MPI ]ZjZglbjm_l qlh kh
h[s_gby \ua\Zggu_ dhee_dlb\gufb hi_jZpbyfb gbdZd g_ ih\ebyxl gZ \u
iheg_gb_ ^jm]bo hi_jZpbc b g_ i_j_k_dmlkykkhh[s_gbyfbihy\b\rbfbky\
j_amevlZl_bg^b\b^mZevgh]h\aZbfh^_ckl\byijhp_kkh\
<hh[s_]h\hjyg_evayjZkkqblu\ZlvgZkbgojhgbaZpbxijhp_kkh\kihfhsvx
dhee_dlb\guo hi_jZpbc ?keb dZdhc-lh ijhp_kk m`_ aZ\_jrbe k\h_ mqZklb_ \
dhee_dlb\ghc hi_jZpbb lh wlh g_ hagZqZ_l gb lh]h qlh ^ZggZy hi_jZpby aZ
\_jr_gZ^jm]bfbijhp_kkZfbdhffmgbdZlhjZgb^Z`_lh]hqlhhgZbfbgZqZlZ
dhg_qgh`__kebwlh\hafh`ghihkfukemhi_jZpbb
<dhee_dlb\guohi_jZpbyog_bkihevamxlkyb^_glbnbdZlhjukhh[s_gbc
int MPI_Bcast(void *buf, int count, MPI_Datatype datatype, int source,
MPI_Comm comm)
• OUT buf — Z^j_kgZqZeZ[mn_jZihkuedbkhh[s_gby
• count — qbkehi_j_^Z\Z_fuowe_f_glh\\khh[s_gbb
47
• datatype — lbii_j_^Z\Z_fuowe_f_glh\
• source — ghf_jjZkkueZxs_]hijhp_kkZ
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
JZkkuedZ khh[s_gby hl ijhp_kkZ source \k_f ijhp_kkZf ^Zggh]hdhffmgbdZ
lhjZ\dexqZyjZkkueZxsbcijhp_kkIjb\ha\jZl_baijhp_^mjukh^_j`bfh_
[mn_jZ buf ijhp_kkZ source [m^_l kdhibjh\Zgh \ ehdZevguc [mn_j dZ`^h]h
ijhp_kkZdhffmgbdZlhjZ commAgZq_gbyiZjZf_ljh\ count, datatype, sourceb
comm ^he`gu [ulv h^bgZdh\ufb m \k_o ijhp_kkh\ < j_amevlZl_ \uiheg_gby
ke_^mxs_]hhi_jZlhjZ\k_fbijhp_kkZfbdhffmgbdZlhjZcomm:
MPI_Bcast(array, 100, MPI_INT, 0, comm);
i_j\u_klhp_euoqbk_ebafZkkb\Z arraygme_\h]hijhp_kkZ[m^mlkdhibjh\Z
gu\ehdZevgu_[mn_jZarraydZ`^h]hijhp_kkZdhffmgbdZlhjZ comm.
int MPI_Gather( void *sbuf, int scount, MPI_Datatype stype, void
*rbuf, int rcount, MPI_Datatype rtype, int dest, MPI_Comm comm)
• sbuf — Z^j_kgZqZeZ[mn_jZihkuedb
• scount — qbkehwe_f_glh\\ihkueZ_fhfkhh[s_gbb
• stype — lbiwe_f_glh\hlkueZ_fh]hkhh[s_gby
• OUT rbuf — Z^j_kgZqZeZ[mn_jZk[hjdb^Zgguo
• rcount — qbkehwe_f_glh\\ijbgbfZ_fhfkhh[s_gbb
• rtype — lbiwe_f_glh\ijbgbfZ_fh]hkhh[s_gby
• dest — ghf_jijhp_kkZgZdhlhjhfijhbkoh^blk[hjdZ^Zgguo
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
K[hjdZ^Zgguokh\k_oijhp_kkh\\[mn_j_ rbufijhp_kkZ destDZ`^ucijh
p_kk \dexqZy dest ihkueZ_l kh^_j`bfh_ k\h_]h [mn_jZ sbuf ijhp_kkm dest.
Kh[bjZxsbcijhp_kkkhojZgy_l^Zggu_\[mn_j_rbufjZkiheZ]Zybo\ihjy^d_
\hajZklZgby ghf_jh\ ijhp_kkh\ GZ ijhp_kk_ dest kms_kl\_ggufb y\eyxlky
agZq_gby \k_o iZjZf_ljh\ Z gZ \k_o hklZevguo ijhp_kkZo — lhevdh agZq_gby
iZjZf_ljh\sbuf, scount, stype, dest bcommAgZq_gbyiZjZf_ljh\dest bcomm
^he`gu [ulv h^bgZdh\ufb m \k_o ijhp_kkh\ IZjZf_lj rcount m ijhp_kkZ
desth[hagZqZ_lqbkehwe_f_glh\lbiZ rtypeijbgbfZ_fuog_hl\k_oijhp_k
kh\\kmff_ZhldZ`^h]hijhp_kkZKihfhsvxihoh`_cnmgdpbbMPI_Gatherv
fh`ghijbgbfZlvhlijhp_kkh\fZkkb\u^ZgguojZaebqghc^ebgu
int MPI_Scatter(void *sbuf, int scount, MPI_Datatype stype, void
*rbuf, int rcount, MPI_Datatype rtype, int source, MPI_Comm comm)
• sbuf — Z^j_kgZqZeZ[mn_jZihkuedb
• scount — qbkehwe_f_glh\\ihkueZ_fhfkhh[s_gbb
48
• stype — lbiwe_f_glh\hlkueZ_fh]hkhh[s_gby
• OUT rbuf — Z^j_kgZqZeZ[mn_jZk[hjdb^Zgguo
• rcount — qbkehwe_f_glh\\ijbgbfZ_fhfkhh[s_gbb
• rtype — lbiwe_f_glh\ijbgbfZ_fh]hkhh[s_gby
• source — ghf_jijhp_kkZgZdhlhjhfijhbkoh^blk[hjdZ^Zgguo
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
Nmgdpby MPI_Scatter ih k\h_fm ^_ckl\bx y\ey_lky h[jZlghc d MPI_Gather.
Ijhp_kk source jZkkueZ_l ihjpbb ^Zgguo ba fZkkb\Z sbuf \k_f n ijhp_kkZf
ijbeh`_gbyFh`ghkqblZlvqlhfZkkb\ sbuf ^_eblkygZ njZ\guoqZkl_ckh
klhysbobascount we_f_glh\lbiZstypeihke_q_]hi-yqZklvihkueZ_lkyi-fm
ijhp_kkm GZ ijhp_kk_ source kms_kl\_ggufb y\eyxlky agZq_gby \k_o iZjZ
f_ljh\ Z gZ \k_o hklZevguo ijhp_kkZo — lhevdh agZq_gby iZjZf_ljh\ rbuf,
rcount, rtype, source b comm AgZq_gby iZjZf_ljh\ source b comm ^he`gu
[ulvh^bgZdh\ufbm\k_oijhp_kkh\:gZeh]bqghnmgdpbb MPI_Gathervkih
fhsvxnmgdpbb MPI_Scatterv ijhp_kkZffh`ghhlhkeZlvihjpbb^ZgguojZa
ebqghc^ebgu
<ke_^mxs_fijbf_j_ihdZaZghbkihevah\Zgb_nmgdpbb MPI_Scatter^eyjZk
kuedbkljhdfZkkb\ZGZihfgbfqlh\yaud_Kb\hlebqb_hlNhjljZgZfZk
kb\uojZgylky\iZfylbihkljhdZf
#include "mpi.h"
#include <stdio.h>
#define SIZE 4
int main(int argc, char **argv)
{
int numtasks, rank, sendcount, recvcount, source;
float sendbuf[SIZE][SIZE] = {
{1.0, 2.0, 3.0, 4.0},
{5.0, 6.0, 7.0, 8.0},
{9.0, 10.0, 11.0, 12.0},
{13.0, 14.0, 15.0, 16.0} };
float recvbuf[SIZE];
MPI_Init(&argc,&argv);
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &numtasks);
if (numtasks == SIZE) {
source = 1;
sendcount = SIZE;
49
recvcount = SIZE;
MPI_Scatter(sendbuf,sendcount,MPI_FLOAT,recvbuf,
recvcount,
MPI_FLOAT,source,MPI_COMM_WORLD);
printf("rank= %d Results: %f %f %f %f\n", rank,
recvbuf[0],recvbuf[1],recvbuf[2],recvbuf[3]);
}
else
printfQbkehijhp_kkh\^he`gh[ulvjZ\ghd. \n",
SIZE);
MPI_Finalize();
}
Ddhee_dlb\gufhi_jZpbyfhlghkylkybj_^mdpbhggu_hi_jZpbbLZdb_hi_jZ
pbb ij_^iheZ]Zxl qlh gZ dZ`^hf ijhp_kk_ ojZgylky g_dhlhju_ ^Zggu_ gZ^
dhlhjufbg_h[oh^bfh\uihegblv_^bgmxhi_jZpbxgZijbf_jhi_jZpbxkeh
`_gby qbk_e beb hi_jZpbx gZoh`^_gby fZdkbfZevgh]h agZq_gby Hi_jZpby
fh`_l [ulv eb[h ij_^hij_^_e_gghc hi_jZpb_c MPI eb[h hi_jZpb_c hij_^_
e_gghcihevah\Zl_e_fDZ`^Zyij_^hij_^_e_ggZyhi_jZpbybf__lk\h_bfygZ
ijbf_j MPI_MAX - ]eh[Zevguc fZdkbfmf MPI_MIN – ]eh[Zevguc fbgbfmf
MPI_SUM –]eh[ZevgZykmffZMPI_PROD –]eh[Zevgh_ijhba\_^_gb_b li
int MPI_Allreduce( void *sbuf, void *rbuf, int count,
datatype, MPI_Op op, MPI_Comm comm)
MPI_Datatype
• sbuf — Z^j_kgZqZeZ[mn_jZ^eyZj]mf_glh\hi_jZpbbop;
• OUT rbuf — Z^j_kgZqZeZ[mn_jZ^eyj_amevlZlZhi_jZpbbop;
• count — qbkehZj]mf_glh\mdZ`^h]hijhp_kkZ
• datatype — lbiZj]mf_glh\
• op — b^_glbnbdZlhj]eh[Zevghchi_jZpbb
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
>ZggZy nmgdpby aZ^Z_l \uiheg_gb_ count g_aZ\bkbfuo ]eh[Zevguohi_jZpbc
op Ij_^iheZ]Z_lky qlh \ [mn_j_ sbuf dZ`^h]h ijhp_kkZ jZkiheh`_gh count
Zj]mf_glh\bf_xsbolbi datatypeI_j\u_we_f_glufZkkb\h\ sbuf mqZkl\m
xl\i_j\hchi_jZpbbop\lhju_we_f_glufZkkb\h\sbuf mqZkl\mxl\h\lhjhc
hi_jZpbb op b l^J_amevlZlu\uiheg_gby\k_o count hi_jZpbcaZibku\Zxlky
\[mn_j rbufgZdZ`^hfijhp_kk_AgZq_gbyiZjZf_ljh\ count, datatype, opb
commm\k_oijhp_kkh\^he`gu[ulvh^bgZdh\ufbBakhh[jZ`_gbcwnn_dlb\
ghklb j_ZebaZpbb ij_^iheZ]Z_lky qlh hi_jZpby op h[eZ^Z_l k\hckl\ZfbZkkh
pbZlb\ghklbbdhffmlZlb\ghklb
50
int MPI_Reduce( void *sbuf, void *rbuf, int count,
datatype, MPI_Op op, int root, MPI_Comm comm)
MPI_Datatype
• sbuf — Z^j_kgZqZeZ[mn_jZ^eyZj]mf_glh\
• OUT rbuf — Z^j_kgZqZeZ[mn_jZ^eyj_amevlZlZ
• count — qbkehZj]mf_glh\mdZ`^h]hijhp_kkZ
• datatype — lbiZj]mf_glh\
• op — b^_glbnbdZlhj]eh[Zevghchi_jZpbb
• root — ijhp_kk-ihemqZl_evj_amevlZlZ
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
Nmgdpby ZgZeh]bqgZ ij_^u^ms_c gh j_amevlZl hi_jZpbb [m^_l aZibkZg \[m
n_jrbufg_m\k_oijhp_kkh\Zlhevdhmijhp_kkZroot.
2. KbgojhgbaZpbyijhp_kkh\
KbgojhgbaZpby ijhp_kkh\ \ MPI hkms_kl\ey_lky k ihfhsvx _^bgkl\_gghc
nmgdpbbMPI_Barrier.
int MPI_Barrier(MPI_Comm comm)
• comm — b^_glbnbdZlhjdhffmgbdZlhjZ
Nmgdpby [ehdbjm_l jZ[hlm \ua\Z\rbo __ ijhp_kkh\ ^h l_o ihj ihdZ \k_ hk
lZ\rb_ky ijhp_kku dhffmgbdZlhjZ comm lZd`_ g_ \uihegyl wlm ijhp_^mjm
Lhevdh ihke_ lh]h dZd ihke_^gbc ijhp_kk dhffmgbdZlhjZ \uihegbl ^Zggmx
nmgdpbx\k_ijhp_kku[m^mljZa[ehdbjh\Zgubijh^he`Zl\uiheg_gb_^Zev
r_ >ZggZy nmgdpby y\ey_lky dhee_dlb\ghc <k_ ijhp_kku ^he`gu \ua\Zlv
MPI_Barrierohlyj_Zevghbkiheg_ggu_\uah\ujZaebqgufbijhp_kkZfbdhf
fmgbdZlhjZfh]ml[ulvjZkiheh`_gu\jZaguof_klZoijh]jZffu
3. JZ[hlZk]jmiiZfbijhp_kkh\
G_kfhljygZlhqlh\MPI_klvagZqbl_evgh_fgh`_kl\hnmgdpbchjb_glbjh
\ZgguogZjZ[hlmkdhffmgbdZlhjZfbb]jmiiZfbijhp_kkh\fug_[m^_fih^
jh[gh hklZgZ\eb\Zlvky gZ ^Zgghf jZa^_e_ Ij_^klZ\e_ggZynmgdpbhgZevghklv
iha\hey_lkjZ\gblvkhklZ\]jmiihij_^_eblvboi_j_k_q_gb_h[t_^bg_gb_^h
[Z\blvijhp_kku\]jmiimm^Zeblv]jmiimb l ^<dZq_kl\_ijbf_jZijb\_^_f
ebrvh^bgkihkh[h[jZah\Zgbygh\uo]jmiigZhkgh\_kms_kl\mxsbo
int MPI_Comm_split(MPI_Comm comm, int color, int key, MPI_Comm
*newcomm)
• comm — b^_glbnbdZlhjkms_kl\mxs_]hdhffmgbdZlhjZ
51
• color — ijbagZdjZa^_e_gbygZ]jmiiu
• key — iZjZf_ljhij_^_eyxsbcgmf_jZpbx\gh\uo]jmiiZo
• OUT newcomm — b^_glbnbdZlhjgh\h]hdhffmgbdZlhjZ
>ZggZy ijhp_^mjZ jZa[b\Z_l \k_ fgh`_kl\h ijhp_kkh\ \oh^ysbo \ ]jmiim
commgZg_i_j_k_dZxsb_kyih^]jmiiu — h^gmih^]jmiimgZdZ`^h_agZq_gb_
iZjZf_ljZcolorAgZq_gb_iZjZf_ljZcolor ^he`gh[ulvg_hljbpZl_evgufp_
eufqbkehfDZ`^Zygh\Zyih^]jmiiZkh^_j`bl\k_ijhp_kkumdhlhjuoiZjZ
f_lj colorbf__lh^ghblh`_agZq_gb_l_\dZ`^hcgh\hcih^]jmii_[m^ml
kh[jZgu \k_ ijhp_kku ³h^gh]h p\_lZ´ <k_f ijhp_kkZf ih^]jmiiu [m^_l \ha
\jZs_ghh^ghblh`_agZq_gb_newcomm.
Ij_^iheh`bfqlhgm`ghjZa^_eblv\k_ijhp_kkuijh]jZffugZ^\_ih^]jmiiu
\ aZ\bkbfhklb hl lh]h y\ey_lky eb ghf_j ijhp_kkZ q_lguf beb g_q_lguf<
wlhf kemqZ_ \ ihe_ color ^hklZlhqgh ihf_klblv \ujZ`_gb_ My_Id%2 ]^_
My_Id — wlhghf_jijhp_kkZAgZq_gb_f^Zggh]h\ujZ`_gbyfh`_l[ulveb[h
0 eb[h 1 <k_ ijhp_kku k q_lgufb ghf_jZfb Z\lhfZlbq_kdb ihiZ^ml \ h^gm
]jmiimZijhp_kkukg_q_lgufb\^jm]mx
int MPI_Comm_free(MPI_Comm comm)
• OUT comm — b^_glbnbdZlhjdhffmgbdZlhjZ
Ihy\e_gb_ gh\h]h dhffmgbdZlhjZ \k_]^Z \uau\Z_l kha^Zgb_ gh\hc kljmdlmju
^Zgguo?kebkha^ZggucdhffmgbdZlhj[hevr_g_gm`_glhkhhl\_lkl\mxsmx
h[eZklv iZfylb g_h[oh^bfh hk\h[h^blv >ZggZy nmgdpby mgbqlh`Z_l dhffm
gbdZlhjZkkhpbbjh\Zgguckb^_glbnbdZlhjhf commdhlhjucihke_\ha\jZs_
gbybanmgdpbb[m^_lbf_lvij_^hij_^_e_ggh_agZq_gb_MPI_COMM_NULL.
6. AZ^Zgby
• Ihemqblv jZ[hlZxsbc iZjZee_evguc \ZjbZgl ijh]jZffu j_Zeb
amxs_c f_lh^ =ZmkkZ j_r_gby kbkl_f ebg_cguo Ze]_[jZbq_kdbo
mjZ\g_gbc bkke_^h\Zlv _]h wnn_dlb\ghklv ij_^eh`blv \ZjbZglu
\hafh`guomemqr_gbc
• <_jghebqlh\dhee_dlb\guo\aZbfh^_ckl\byomqZkl\mxl\k_ijh
p_kkuijbeh`_gby"
• Fh]mleb\hagbdZlvdhgnebdluf_`^mkhh[s_gbyfbihkueZ_fufb
ijhp_kkZfb ^jm] ^jm]m b khh[s_gbyfb dhee_dlb\guo hi_jZpbc"
?keb^ZdZdhgbjZaj_rZxlky"
• Kfh^_ebjh\Zlv[Zjv_jgmxkbgojhgbaZpbxijbihfhsbi_j_kuehd
lhqdZ-lhqdZ b kjZ\gblv wnn_dlb\ghklv lZdhc j_ZebaZpbb b klZg
^Zjlghcnmgdpbb
52
• Kfh^_ebjh\Zlv ]eh[Zevgh_ kmffbjh\Zgb_ f_lh^hf k^\Zb\Zgby b
kjZ\gblvwnn_dlb\ghklvlZdhcj_ZebaZpbbknmgdpb_cMPI_Reduce.
• GZibrbl_k\hc\ZjbZglijhp_^mjuMpi_Gatherbkihevamynmgdpbb
ihkuedbkhh[s_gbclbiZlhqdZ-lhqdZ
• Ih^mfZcl_ dZd hj]Zgbah\Zlv dhee_dlb\guc Zkbgojhgguc h[f_g
^ZggufbZgZeh]bqgucnmgdpbbZMPI_Reduce[MPI_AlltoAll.
• Ih^mfZcl_ dZdZy oZjZdl_jbklbdZ k_l_\hc kj_^u [hevr_ \k_]h
\eby_lgZ\j_fy\uiheg_gby[Zjv_jghckbgojhgbaZpbb
• HagZdhfvl_kv kh klZg^Zjlhf MPI-bgZah\bl__]hdexq_\u_hl
ebqbyhlMPI-1.1.
AZgylb_ L_ogheh]bb iZjZee_evgh]h ijh]jZffbjh\Zgby
h[ahj
1. Ki_pdhff_glZjbb
GZqg_fkbkihevah\Zgby\ljZ^bpbhgguoyaudZoijh]jZffbjh\Zgbyki_pbZev
guodhff_glZjb_\^h[Z\eyxsbo³iZjZee_evgmx´ki_pbnbdm\bagZqZevghih
ke_^h\Zl_evgu_ ijh]jZffu Ij_^iheh`bf qlh \u jZ[hlZ_l_ gZ \_dlhjghdhg\_c_jghf dhfivxl_j_ &UD\ 7 <u agZ_l_ qlh \k_ bl_jZpbb g_dhlhjh]h
pbdeZijh]jZffug_aZ\bkbfubke_^h\Zl_evgh_]hfh`gh\_dlhjbah\Zlvl_
hq_gv wnn_dlb\gh bkihegblv k ihfhsvx \_dlhjguo dhfZg^ gZ dhg\_c_jguo
nmgdpbhgZevguo mkljhckl\Zo ?keb pbdeijhklhclhdhfibeylhjbkZfhij_
^_ebl \hafh`ghklv ij_h[jZah\Zgby ihke_^h\Zl_evgh]h dh^Z \ iZjZee_evguc
?kebm\_j_gghklb\\ukhdhfbgl_ee_dl_dhfibeylhjZg_llhi_j_^aZ]heh\dhf
pbdeZ emqr_ \klZ\blv y\gh_ mdZaZgb_ gZ hlkmlkl\b_ aZ\bkbfhklb b \hafh`
ghklv\_dlhjbaZpbb<qZklghklb^eyyaudZNhjljZgwlh\u]ey^bllZd
CDIR$ NODEPCHK
IhijZ\bemNhjljZgZ[md\Z
C
\i_j\hcihabpbb]h\hjblhlhfqlh\kykljhdZ
y\ey_lky dhff_glZjb_f ihke_^h\Zl_evghklv DIR$
mdZau\Z_l gZ lh qlh wlh
ki_pdhff_glZjbc^eydhfibeylhjZZqZklv
NODEPCHK
dZdjZab]h\hjblh[hl
kmlkl\bbbgnhjfZpbhgghcaZ\bkbfhklbf_`^mbl_jZpbyfbihke_^mxs_]hpbd
eZ
Ke_^m_l hlf_lblv qlh bkihevah\Zgb_ ki_pdhff_glZjb_\ g_ lhevdh ^h[Z\ey_l
\hafh`ghklviZjZee_evgh]hbkiheg_gbyghbiheghklvxkhojZgy_lbkoh^guc
\ZjbZglijh]jZffuGZijZdlbd_wlhhq_gvm^h[gh —_kebdhfibeylhjgbq_]h
g_agZ_lhiZjZee_ebaf_lh\k_ki_pdhff_glZjbbhgijhklhijhimklbl\ay\aZ
hkgh\mihke_^h\Zl_evgmxk_fZglbdmijh]jZffu
53
GZbkihevah\Zgb_dhff_glZjb_\hibjZ_lkybrbjhdhjZkijhkljZg_gguc\gZ
klhys__ \j_fy klZg^Zjl Open_MP Hkgh\gZy hjb_glZpby k^_eZgZgZjZ[hlmk
h[s_ciZfylvxgblyfbWKUHDGVby\gufhibkZgb_fiZjZee_ebafZ<NhjljZ
g_ijbagZdhfki_pdhff_glZjby2SHQB03y\ey_lkyij_nbdk!$OMPZ\yaud_Kb
bkihevamxl^bj_dlb\m #pragma omp<gZklhys__\j_fyijZdlbq_kdb\k_\_^m
sb_ ijhba\h^bl_eb 603-dhfivxl_jh\ ih^^_j`b\Zxl 2SHQB03 \ dhfibey
Документ
Категория
Без категории
Просмотров
9
Размер файла
695 Кб
Теги
2002, вычисления, паралельне, методичка, pdf, введение
1/--страниц
Пожаловаться на содержимое документа