ãã®æçš¿ã§ã¯ãäŸãšããŠã€ã³ãã«Â®MPIã©ã€ãã©ãªãŒã䜿çšããŠãMPIã䜿çšããããŒã¿äº€æã®ç·šæã«ã€ããŠèª¬æããŸãã ãã®æ å ±ã¯ãå®éã«äžŠåé«æ§èœã³ã³ãã¥ãŒãã£ã³ã°ã®åéã«ç²Ÿéããã人ã«ãšã£ãŠèå³æ·±ããã®ã«ãªããšæããŸãã
䞊åMPIããŒã¹ã®ã¢ããªã±ãŒã·ã§ã³ã§ããŒã¿äº€æãã©ã®ããã«ç·šæããããã«ã€ããŠã®ç°¡åãªèª¬æãšããã詳现ãªèª¬æãå«ãå€éšãœãŒã¹ãžã®ãªã³ã¯ãæäŸããŸãã å®çšçãªéšåã§ã¯ããã¢MPIã¢ããªã±ãŒã·ã§ã³ãHello Worldãã®éçºã®ãã¹ãŠã®æ®µéã«ã€ããŠèª¬æããŸããå¿ èŠãªç°å¢ã®ã»ããã¢ããããããã°ã©ã èªäœã®èµ·åãŸã§ã§ãã
MPIïŒã¡ãã»ãŒãžããã·ã³ã°ã€ã³ã¿ãŒãã§ã€ã¹ïŒ
MPIã¯ãåäžã®ã¿ã¹ã¯ãå®è¡ããããã»ã¹éã®ã¡ãã»ãŒãžããã·ã³ã°ã€ã³ã¿ãŒãã§ã€ã¹ã§ãã OpenMPãªã©ãšã¯ç°ãªããäž»ã«åæ£ã¡ã¢ãªã·ã¹ãã ïŒ MPP ïŒã察象ãšããŠããŸãã ååãšããŠãåæ£ïŒã¯ã©ã¹ã¿ãŒïŒã·ã¹ãã ã¯ãé«æ§èœéä¿¡ãã£ãã«ïŒããšãã°ã InfiniBand ïŒã§æ¥ç¶ãããäžé£ã®ã³ã³ãã¥ãŒãã£ã³ã°ããŒãã§ãã
MPIã¯ã䞊åããã°ã©ãã³ã°ã§æãäžè¬çãªããŒã¿è»¢éã€ã³ã¿ãŒãã§ã€ã¹æšæºã§ãã MPIã¯MPIãã©ãŒã©ã ã æšæºåããŠããŸãã ææ°ã®ãã©ãããã©ãŒã ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãããã³èšèªã®ã»ãšãã©ã«MPIå®è£ ããããŸãã MPIã¯ãèšç®ç©çåŠãå»è¬åãææç§åŠãéºäŒåŠããã®ä»ã®ç¥èåéã®ããŸããŸãªåé¡ã®è§£æ±ºã«åºã䜿çšãããŠããŸãã
MPIã®èŠ³ç¹ããèŠã䞊åããã°ã©ã ã¯ãç°ãªãã³ã³ãã¥ãŒãã£ã³ã°ããŒãã§å®è¡ãããäžé£ã®ããã»ã¹ã§ãã åããã»ã¹ã¯ãåãããã°ã©ã ã³ãŒãã«åºã¥ããŠçæãããŸãã
MPIã®äž»ãªæäœã¯ãã¡ãã»ãŒãžã®åãæž¡ãã§ãã MPIã¯ãã»ãŒãã¹ãŠã®åºæ¬çãªéä¿¡ãã³ãã¬ãŒãïŒãã€ã³ãããŒãã€ã³ããéåãããã³çé¢ïŒãå®è£ ããŠããŸãã
MPIã䜿çšãã
å žåçãªMPIããã°ã©ã ãã©ã®ããã«æ©èœãããã®å®äŸãèŠãŠââã¿ãŸãããã ãã¢ã¢ããªã±ãŒã·ã§ã³ãšããŠãIntel MPIã©ã€ãã©ãªã«ä»å±ããŠãããµã³ãã«ã®ãœãŒã¹ã³ãŒããèŠãŠã¿ãŸãããã æåã®MPIããã°ã©ã ãéå§ããåã«ãå®éšçšã®äœæ¥ç°å¢ãæºåããŠèšå®ããå¿ èŠããããŸãã
ã¯ã©ã¹ã¿ãŒç°å¢ã®ã»ããã¢ãã
å®éšã«ã¯ãããã€ãã®èšç®ããŒããå¿ èŠã§ãïŒåæ§ã®ç¹æ§ãæã€ããšãæãŸããïŒã 2ã€ã®ãµãŒããŒãæå ã«ãªãå Žåã¯ããã€ã§ãã¯ã©ãŠããµãŒãã¹ã䜿çšã§ããŸãã
ãã¢ã³ã¹ãã¬ãŒã·ã§ã³ã®ããã«ã Amazon Elastic Compute Cloud ïŒAmazon EC2ïŒãéžæããŸããã Amazonã¯æ°èŠãŠãŒã¶ãŒã«ç¡æã®ãšã³ããªãŒã¬ãã«ã®ãµãŒããŒäœ¿çšã®è©Šçšå¹ŽãæäŸããŸã ã
Amazon EC2ã®æäœã¯çŽæçã§ãã 質åãããå Žåã¯ã詳现ãªããã¥ã¡ã³ã ïŒè±èªïŒãåç §ã§ããŸãã å¿ èŠã«å¿ããŠãä»ã®åæ§ã®ãµãŒãã¹ã䜿çšã§ããŸãã
2ã€ã®åäœããä»®æ³ãµãŒããŒãäœæããŸãã 管çã³ã³ãœãŒã«ã§ãã¯ã©ãŠãå ã®EC2ä»®æ³ãµãŒããŒãéžæãã ã€ã³ã¹ã¿ã³ã¹ãèµ·åããŸãïŒãã€ã³ã¹ã¿ã³ã¹ãã¯ä»®æ³ãµãŒããŒã®ã€ã³ã¹ã¿ã³ã¹ãæå³ããŸãïŒã
次ã®ã¹ãããã¯ããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®éžæã§ãã Intel MPI Libraryã¯ãLinuxãšWindowsã®äž¡æ¹ããµããŒãããŠããŸãã MPIã®æåã®ç¥ãåãã«ã¯ãOC LinuxãéžæããŸãã Red Hat Enterprise Linux 6.6 64-bitãŸãã¯SLES11.3 / 12.0ãéžæããŸãã
[ ã€ã³ã¹ã¿ã³ã¹ã¿ã€ã] ïŒãµãŒããŒã¿ã€ãïŒãéžæããŸãã å®éšã«ã¯ãt2.microãé©ããŠããŸãïŒ1 vCPUã2.5 GHzãIntel Xeonããã»ããµãââã¡ããªã1 GiB RAMïŒã æè¿ç»é²ãããŠãŒã¶ãŒãšããŠããã®ã¿ã€ããç¡æã§äœ¿çšã§ããŸã-ãç¡æå©çšæ ãããŒã¯ã ã€ã³ã¹ã¿ã³ã¹æ°ã®èšå®ïŒ2ïŒä»®æ³ãµãŒããŒã®æ°ïŒã
ãµãŒãã¹ãã€ã³ã¹ã¿ã³ã¹ã®èµ·å ïŒèšå®æžã¿ã®ä»®æ³ãµãŒããŒïŒãèµ·åããããã«èŠæ±ããåŸãå€éšããä»®æ³ãµãŒããŒãšéä¿¡ããããã«å¿ èŠãªSSHããŒãä¿åããŸãã ä»®æ³ãµãŒããŒã®ç¶æ ãšããŒã«ã«ã³ã³ãã¥ãŒã¿ãŒã®ãµãŒããŒãšéä¿¡ããããã®IPã¢ãã¬ã¹ã¯ã管çã³ã³ãœãŒã«ã§ç£èŠã§ããŸãã
éèŠãªãã€ã³ãïŒ NetworkïŒSecurity / Security Groupsã®èšå®ã§ãTCPæ¥ç¶çšã®ããŒããéãã«ãŒã«ãäœæããå¿ èŠããããŸã-ããã¯MPIããã»ã¹ãããŒãžã£ãŒã«å¿ èŠã§ãã ã«ãŒã«ã¯æ¬¡ã®ããã«ãªããŸãã
ã¿ã€ãïŒã«ã¹ã¿ã TCPã«ãŒã«
ãããã³ã«ïŒTCP
ããŒãç¯å²ïŒ1024-65535
ãœãŒã¹ïŒ0.0.0.0/0
ã»ãã¥ãªãã£äžã®çç±ãããããå³å¯ãªã«ãŒã«ãèšå®ã§ããŸããããã¢ã§ã¯ããã§ååã§ãã
ããã§ã¯ãããŒã«ã«ã³ã³ãã¥ãŒã¿ãŒããè±èªã®ä»®æ³ãµãŒããŒã«æ¥ç¶ããæ¹æ³ã®èª¬æãèªãããšãã§ããŸãïŒè±èªïŒã
Windowsã³ã³ãã¥ãŒã¿ãŒããå®çšŒåãµãŒããŒãšéä¿¡ããã«ã¯Puttyã䜿çšãããã¡ã€ã«ã転éããã«ã¯WinSCPã䜿çšããŸããã ããã§ã¯ãAmazonãµãŒãã¹ã§åäœããããã«ããããæ§æããæ¹æ³ã«é¢ããæ瀺ãèªãããšãã§ããŸãïŒè±èªïŒã
次ã®ã¹ãããã¯ãSSHãæ§æããããšã§ãã å ¬ééµèªèšŒã䜿çšããŠãã¹ã¯ãŒããªãã®SSHãæ§æããã«ã¯ã次ã®æé ãå®è¡ããå¿ èŠããããŸãã
- åãã¹ãã§ssh-keygenãŠãŒãã£ãªãã£ãå®è¡ããŸã-$ HOME / .sshãã£ã¬ã¯ããªã«ç§å¯éµãšå ¬ééµã®ãã¢ãäœæããŸãã
- 1ã€ã®ãµãŒããŒããå ¬ééµïŒæ¡åŒµå.pubã®ãã¡ã€ã«ïŒã®å 容ãååŸãããããå¥ã®ãµãŒããŒã®ãã¡ã€ã«$ HOME / .ssh / authorized_keysã«è¿œå ããŸãã
- äž¡æ¹ã®ãµãŒããŒã«å¯ŸããŠãã®æé ãå®è¡ããŸãã
- SSHèšå®ã®æ£ç¢ºæ§ã確èªããããã«ãSSHãä»ããŠ1ã€ã®ãµãŒããŒããå¥ã®ãµãŒããŒã«ããŸãã¯ãã®éã«åå ããŠã¿ãŸãããã æåã®æ¥ç¶ã§ããªã¢ãŒããã¹ãã®å ¬éããŒããªã¹ã$ HOME / .ssh / known_hostsã«è¿œå ããå¿ èŠãããå ŽåããããŸãã
MPIã©ã€ãã©ãªã®æ§æ
ããã§ãäœæ¥ç°å¢ãæ§æãããŸããã MPIãã€ã³ã¹ããŒã«ããæéã
ãã¢ãªãã·ã§ã³ãšããŠã30æ¥éã®ã€ã³ãã«MPIã©ã€ãã©ãªã®è©ŠçšçïŒçŽ300 MBïŒã䜿çšããŠã¿ãŸãããã å¿ èŠã«å¿ããŠãä»ã®MPIå®è£ ãããšãã°MPICHã䜿çšã§ããŸãã èšäº5.0.3.048ãæžããŠããæç¹ã§å ¥æå¯èœãªææ°ããŒãžã§ã³ã®ã€ã³ãã«MPIã©ã€ãã©ãªãŒããããå®éšã«äœ¿çšããŸãã
çµã¿èŸŒã¿ã€ã³ã¹ããŒã©ãŒã®æ瀺ã«åŸã£ãŠã€ã³ãã«MPIã©ã€ãã©ãªãŒãã€ã³ã¹ããŒã«ããŸãïŒã¹ãŒããŒãŠãŒã¶ãŒç¹æš©ãå¿ èŠãªå ŽåããããŸãïŒã
$ tar xvfz l_mpi_p_5.0.3.048.tgz
$ cd l_mpi_p_5.0.3.048
$ ./install.sh
äž¡æ¹ã®ããŒãã§åãã€ã³ã¹ããŒã«ãã¹ã䜿çšããŠãåãã¹ãã§ã€ã³ã¹ããŒã«ãå®è¡ããŸãã MPIãå±éããããæšæºçãªæ¹æ³ã¯ãåäœæ¥ããŒãã§å©çšå¯èœãªãããã¯ãŒã¯ã¹ãã¬ãŒãžã«ã€ã³ã¹ããŒã«ããããšã§ããããã®ãããªã¹ãã¬ãŒãžã®ã»ããã¢ããã®èª¬æã¯èšäºã®ç¯å²ãè¶ ããŠãããããããåçŽãªãªãã·ã§ã³ã«å¶éããŸãã
MPIãã¢ããã°ã©ã ãã³ã³ãã€ã«ããã«ã¯ãGNU Cã³ã³ãã€ã©ïŒgccïŒã䜿çšããŸãã
Amazonã¯ãRHELããã°ã©ã ã®æšæºã»ããã«ã€ã¡ãŒãžããªããããã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã
$ sudo yum install gcc
ãã¢MPIããã°ã©ã ãšããŠãIntel MPI Libraryãµã³ãã«ã®æšæºã»ããããtest.cãååŸããŸãïŒintel / impi / 5.0.3.048 / testãã©ã«ããŒã«ãããŸãïŒã
ã³ã³ãã€ã«ããããã®æåã®ã¹ãããã¯ãã€ã³ãã«Â®MPIã©ã€ãã©ãªãŒç°å¢ãå ¬éããããšã§ãã
$ã /home/ec2-user/intel/impi/5.0.3.048/intel64/bin/mpivars.sh
次ã«ãã€ã³ãã«Â®MPIã©ã€ãã©ãªãŒã®ã¹ã¯ãªããã䜿çšããŠãã¹ãããã°ã©ã ãã³ã³ãã€ã«ããŸãïŒå¿ èŠãªMPIäŸåé¢ä¿ã¯ãã¹ãŠãã³ã³ãã€ã«æã«èªåçã«èšå®ãããŸãïŒã
$ cd /home/ec2-user/intel/impi/5.0.3.048/test
$ mpicc -o test.exe ./test.c
çµæã®test.exeã2çªç®ã®ããŒãã«ã³ããŒãããŸãã
$ scp test.exe ip-172-31-47-24ïŒ/home/ec2-user/intel/impi/5.0.3.048/test/
MPIããã°ã©ã ãéå§ããåã«ããhostnameããªã©ã®æšæºçãªLinuxãŠãŒãã£ãªãã£ãè©ŠããŠã¿ããšäŸ¿å©ã§ãã
$ mpirun -ppn 1 -n 2 -hosts ip-172-31-47-25ãip-172-31-47-24ãã¹ãå
ip-172-31-47-25
ip-172-31-47-24
ãmpirunããŠãŒãã£ãªãã£ã¯ãMPIã¢ããªã±ãŒã·ã§ã³ãå®è¡ããããã«èšèšãããIntel MPIã©ã€ãã©ãªã®ããã°ã©ã ã§ãã ããã¯äžçš®ã®ãã©ã³ãã£ãŒãã§ãã åŒæ°ã«ãªã¹ããããŠããåããŒãã§MPIããã°ã©ã ã®ã€ã³ã¹ã¿ã³ã¹ãèµ·åããã®ã¯ããã®ããã°ã©ã ã§ãã
ãªãã·ã§ã³ã«é¢ããŠã¯ãã-ppnãã¯åããŒãã§éå§ããããã»ã¹ã®æ°ãã-nãã¯éå§ããããã»ã¹ã®åèšæ°ãã-hostsãã¯æå®ããã¢ããªã±ãŒã·ã§ã³ãèµ·åããããŒãã®ãªã¹ããæåŸã®åŒæ°ã¯å®è¡å¯èœãã¡ã€ã«ãžã®ãã¹ã§ãïŒããã¯ããã³MPIã®ãªãã¢ããªã±ãŒã·ã§ã³ïŒã
ãã®äŸã§ã¯ããã¹ãåãŠãŒãã£ãªãã£ãå®è¡ãããšãã«ãäž¡æ¹ã®ä»®æ³ãµãŒããŒãããã®åºåïŒã³ã³ãã¥ãŒãã£ã³ã°ããŒãã®ååïŒãååŸããå¿ èŠããããMPIããã»ã¹ãããŒãžã£ãŒã¯æ£åžžã«åäœããŠãããšèšããŸãã
MPIã䜿çšãããHello Worldã
ãã¢MPIã¢ããªã±ãŒã·ã§ã³ãšããŠãã€ã³ãã«MPIã©ã€ãã©ãªã®ãµã³ãã«ã®æšæºã»ããããtest.cãååŸããŸããã
ãã¢MPIã¢ããªã±ãŒã·ã§ã³ã¯ãå䞊åMPIããã»ã¹ããããã»ã¹ãšãããå®è¡ãããŠããã³ã³ãã¥ãŒãã£ã³ã°ããŒãã«é¢ããæ å ±ãåéãããã®æ å ±ããããããŒãã«åºåããŸãã
å žåçãªMPIããã°ã©ã ã®äž»èŠãªã³ã³ããŒãã³ããããã«è©³ããèããŠã¿ãŸãããã
#include "mpi.h"
åºæ¬çãªMPIé¢æ°ãšå®æ°ã®å®£èšãå«ãmpi.hããããŒãã¡ã€ã«ãå«ãŸããŠããŸãã
ã€ã³ãã«Â®MPIã©ã€ãã©ãªãŒã®ç¹å¥ãªã¹ã¯ãªããïŒmpiccãmpiiccãªã©ïŒã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ãã³ã³ãã€ã«ãããšãmpi.hãžã®ãã¹ãèªåçã«æžã蟌ãŸããŸãã ããã§ãªãå Žåãã³ã³ãã€ã«æã«ã€ã³ã¯ã«ãŒããã©ã«ããŒãžã®ãã¹ãæå®ããå¿ èŠããããŸãã
MPI_Init (&argc, &argv); ... MPI_Finalize ();
MPIããã°ã©ã ã®å®è¡ç°å¢ãåæåããã«ã¯ãMPI_InitïŒïŒã®åŒã³åºããå¿
èŠã§ãã ãã®åŒã³åºãã®åŸãæ®ãã®MPIé¢æ°ã䜿çšã§ããŸãã
MPIããã°ã©ã ã®æåŸã®åŒã³åºãã¯MPI_FinalizeïŒïŒã§ãã MPIããã°ã©ã ãæ£åžžã«å®äºãããšãèµ·åãããåMPIããã»ã¹ã¯MPI_FinalizeïŒïŒåŒã³åºããè¡ããå éšã®MPIãªãœãŒã¹ãæ¶å»ãããŸãã MPI_FinalizeïŒïŒã®åŸã«MPIé¢æ°ãåŒã³åºãããšã¯èš±å¯ãããŠããŸããã
MPIããã°ã©ã ã®æ®ãã®éšåã説æããã«ã¯ãMPIããã°ã©ãã³ã°ã§äœ¿çšãããåºæ¬çãªçšèªãèæ ®ããå¿ èŠããããŸãã
MPIããã°ã©ã ã¯ãããŸããŸãªMPIé¢æ°ãä»ããŠäºãã«ã¡ãã»ãŒãžãéä¿¡ã§ããããã»ã¹ã®ã»ããã§ãã åããã»ã¹ã«ã¯ç¹å¥ãªèå¥å-ã©ã³ã¯ããããŸãã ããã»ã¹ã©ã³ã¯ã¯ãMPIã¡ãã»ãŒãžãéä¿¡ããããŸããŸãªæäœã§äœ¿çšã§ããŸããããšãã°ãã©ã³ã¯ã¯ã¡ãã»ãŒãžåä¿¡è ã®èå¥åãšããŠæå®ã§ããŸãã
ããã«ãMPIã«ã¯ãããã»ã¹ã®ã°ã«ãŒããèšè¿°ããã³ãã¥ãã±ãŒã¿ãŒãšåŒã°ããç¹å¥ãªãªããžã§ã¯ãããããŸãã åäžã®ã³ãã¥ãã±ãŒã¿ãŒå ã®åããã»ã¹ã«ã¯ãäžæã®ã©ã³ã¯ããããŸãã åãããã»ã¹ãç°ãªãã³ãã¥ãã±ãŒã¿ãŒã«é¢é£ããå¯èœæ§ããããããç°ãªãã³ãã¥ãã±ãŒã¿ãŒå ã§ç°ãªãã©ã³ã¯ãæã€ããšãã§ããŸãã ããŒã¿ãMPIã«éä¿¡ããåæäœã¯ãã³ãã¥ãã±ãŒã¿ãŒã®ãã¬ãŒã ã¯ãŒã¯å ã§å®è¡ããå¿ èŠããããŸãã ããã©ã«ãã§ã¯ã䜿çšå¯èœãªãã¹ãŠã®ããã»ã¹ãå«ãã³ãã¥ãã±ãŒã¿ãŒMPI_COMM_WORLDãåžžã«äœæãããŸãã
test.cã«æ»ãïŒ
MPI_Comm_size (MPI_COMM_WORLD, &size); MPI_Comm_rank (MPI_COMM_WORLD, &rank);
MPI_Comm_sizeïŒïŒåŒã³åºãã¯ãçŸåšã®MPI_COMM_WORLDã³ãã¥ãã±ãŒã¿ãŒã®å€æ°ãµã€ãºïŒãµã€ãºïŒïŒmpirunãªãã·ã§ã³ '-n'ã§æå®ããããã»ã¹ã®ç·æ°ïŒã«æžã蟌ã¿ãŸãã
MPI_Comm_rankïŒïŒã¯ãã³ãã¥ãã±ãŒã¿ãŒMPI_COMM_WORLDå ã®çŸåšã®MPIããã»ã¹ã®å€æ°ã©ã³ã¯ïŒã©ã³ã¯ïŒã«æžã蟌ã¿ãŸãã
MPI_Get_processor_name (name, &namelen);
MPI_Get_processor_nameïŒïŒãåŒã³åºããšã察å¿ããããã»ã¹ãèµ·åãããã³ã³ãã¥ãŒãã£ã³ã°ããŒãã®æååèå¥åïŒååïŒãå€æ°åã«æžã蟌ãŸããŸãã
åéãããæ å ±ïŒããã»ã¹ã©ã³ã¯ããã£ã¡ã³ã·ã§ã³MPI_COMM_WORLDãããã»ããµåïŒã¯ãMPI_SendïŒïŒé¢æ°ã䜿çšããŠããã¹ãŠã®éãŒãã©ã³ã¯ãããŒãã«éä¿¡ãããŸãã
MPI_Send (&rank, 1, MPI_INT, 0, 1, MPI_COMM_WORLD); MPI_Send (&size, 1, MPI_INT, 0, 1, MPI_COMM_WORLD); MPI_Send (&namelen, 1, MPI_INT, 0, 1, MPI_COMM_WORLD); MPI_Send (name, namelen + 1, MPI_CHAR, 0, 1, MPI_COMM_WORLD);
MPI_SendïŒïŒé¢æ°ã®åœ¢åŒã¯æ¬¡ã®ãšããã§ãã
MPI_SendïŒbufãcountãtypeãdestãtagãcommïŒMPI_SendïŒïŒé¢æ°ãšãã®åŒæ°ãããã³ãã®ä»ã®MPIé¢æ°ã®ãã詳现ãªèª¬æã¯ã MPIæšæºã«ãããŸã ïŒããã¥ã¡ã³ãã®èšèªã¯è±èªã§ãïŒã
buf-éä¿¡ããŒã¿ãé 眮ãããŠããã¡ã¢ãªãããã¡ã®ã¢ãã¬ã¹ã
count-ã¡ãã»ãŒãžå ã®ããŒã¿èŠçŽ ã®æ°ã
type-転éãããã¡ãã»ãŒãžã®ããŒã¿èŠçŽ ã®ã¿ã€ãã
dest-ã¡ãã»ãŒãžåä¿¡è ã®ããã»ã¹ã®ã©ã³ã¯ã
tag-ã¡ãã»ãŒãžãèå¥ããããã®ç¹å¥ãªã¿ã°ã
comm-ã¡ãã»ãŒãžãéä¿¡ãããã³ãã¥ãã±ãŒã¿ãŒã
ã©ã³ã¯0ã§ã¯ãä»ã®ã©ã³ã¯ããéä¿¡ãããã¡ãã»ãŒãžãåä¿¡ãããç»é¢ã«åºåãããŸãã
printf ("Hello world: rank %d of %d running on %s\n", rank, size, name); for (i = 1; i < size; i++) { MPI_Recv (&rank, 1, MPI_INT, i, 1, MPI_COMM_WORLD, &stat); MPI_Recv (&size, 1, MPI_INT, i, 1, MPI_COMM_WORLD, &stat); MPI_Recv (&namelen, 1, MPI_INT, i, 1, MPI_COMM_WORLD, &stat); MPI_Recv (name, namelen + 1, MPI_CHAR, i, 1, MPI_COMM_WORLD, &stat); printf ("Hello world: rank %d of %d running on %s\n", rank, size, name); }
æ確ã«ããããã«ããŒãã©ã³ã¯ã¯ããã«ããªã¢ãŒãã©ã³ã¯ããåä¿¡ããããŒã¿ã®ããã«ããŒã¿ãå°å·ããŸãã
MPI_RecvïŒïŒé¢æ°ã®åœ¢åŒã¯æ¬¡ã®ãšããã§ãã
MPI_RecvïŒbufãcountãtypeãsourceãtagãcommãstatusïŒ
bufãcountãtype-ã¡ãã»ãŒãžãåä¿¡ããããã®ã¡ã¢ãªãããã¡ã
source-ã¡ãã»ãŒãžãåä¿¡ããããã»ã¹ã®ã©ã³ã¯ã
tag-åä¿¡ããã¡ãã»ãŒãžã®ã¿ã°ã
comm-ããŒã¿ãåä¿¡ãããã¬ãŒã ã¯ãŒã¯å ã®ã³ãã¥ãã±ãŒã¿ãŒã
status-ããŒã¿åä¿¡æäœã®çµæã«é¢ããæ å ±ãå«ãç¹å¥ãªMPIããŒã¿æ§é ãžã®ãã€ã³ã¿ãŒã
ãã®èšäºã§ã¯ãMPI_SendïŒïŒ/ MPI_RecvïŒïŒé¢æ°ã®è€éãã«ã€ããŠã¯æãäžããŸããã ããŸããŸãªã¿ã€ãã®MPIæäœãšãããã®äœæ¥ã®è€éãã®èª¬æã¯ãå¥ã®èšäºã®ãããã¯ã§ãã ããã°ã©ã ã®ãŒãã©ã³ã¯ã¯ãæåã®ã©ã³ã¯ããå§ãŸããå¢å ããïŒ1ãããµã€ãºãŸã§å€åããMPI_RecvïŒïŒé¢æ°ã®ãœãŒã¹ãã£ãŒã«ãã«ãã£ãŠæ±ºå®ãããïŒå³å¯ã«ç¹å®ã®é åºã§ä»ã®ããã»ã¹ããã¡ãã»ãŒãžãåä¿¡ããããšã«æ³šæããŠãã ããã
説æãããŠããé¢æ°MPI_SendïŒïŒ/ MPI_RecvïŒïŒã¯ããããããã€ã³ãããŒãã€ã³ãMPIæäœã®äŸã§ãã ãã®ãããªæäœã§ã¯ãç¹å®ã®ã³ãã¥ãã±ãŒã¿ãŒã®ãã¬ãŒã ã¯ãŒã¯å ã§ãããã©ã³ã¯ãå¥ã®ã©ã³ã¯ãšã¡ãã»ãŒãžã亀æããŸãã 3ã€ä»¥äžã®ã©ã³ã¯ãããŒã¿äº€æã«åå ã§ããéåçãªMPIæäœããããŸãã éåçãªMPIæäœã¯ãå¥ã®ïŒããã³å Žåã«ãã£ãŠã¯è€æ°ã®ïŒèšäºã®ãããã¯ã§ãã
ãã¢MPIããã°ã©ã ã®çµæã以äžãåŸãããŸãã
$ mpirun -ppn 1 -n 2 -hosts ip-172-31-47-25ãip-172-31-47-24 /home/ec2-user/intel/impi/5.0.3.048/test/test.exe
Hello WorldïŒIP-172-31-47-25ã§å®è¡ãããŠããã©ã³ã¯0ã®2
Hello WorldïŒIP-172-31-47-24ã§å®è¡ãããŠãã2ã€ã®ã©ã³ã¯1
ãã®æçš¿ã§èšãããããšã«èå³ããããMPIãã¯ãããžãŒã®éçºã«åå ããããšæããŸããïŒ ã€ã³ãã«MPIã©ã€ãã©ãªéçºããŒã ïŒããžãããŽãŽããïŒã¯çŸåšãç©æ¥µçã«ã¢ãœã·ãšã€ããšã³ãžãã¢ãåéããŠããŸãã 詳现ã«ã€ããŠã¯ã Intelã®å ¬åŒ Webãµã€ãããã³BrainStorage Webãµã€ããåç §ããŠãã ããã
ãããŠæåŸã«ãé«æ§èœã³ã³ãã¥ãŒãã£ã³ã°ã«é¢ããå°æ¥ã®åºçç©ã®å¯èœæ§ã®ãããããã¯ã«é¢ããå°ããªæ祚ã