ã¯ããã«
ãæ¨ä»ãã«ãã³ã¢CPUã¯ä¸è¬åãã並ååå¦çã®éè¦åº¦ãã©ãã©ãé«ã¾ã£ã¦ãã¾ããããã®æµãã¯ããå¤ãããªãã§ããããã§ããããæã éçºè ã«ã¨ã£ã¦ä¸¦åå¦çã®ç¥èã¯çµ¶å¯¾ã«å¿ è¦ãªãã®ã§ããã¨ã¯ãããæ¥ã ã®æ¥åãããªãã¤ã¤è³æãå°ãªã並ååå¦çã身ã«ã¤ãããã¨ã¯å¤§å¤ã§ãã
ãããã§ä»åçè ã¯ã並ååå¦çãå®ç¾ããOpenMPã®å ¥éè¨äºãæ¸ããã¨ã«ãã¾ãããOpenMPãé¸æããçç±ã¯ãä¸çªå¹çãæ±ãããã¦ããã®ã¯C/C++ããã°ã©ãã¼ã ã¨èããããã§ããC/C++ããã°ã©ãã¼ã®æ¹ã ã並åå¦çãç¿å¾ãããæä¼ããã§ããã°å¹¸ãã§ãã
ããªãããã®é£è¼ã§è§£èª¬ã«ä½¿ç¨ãããµã³ãã«ã³ã¼ãã¯ããã¾ã§ãOpenMPã®åºç¤ãç解ããããã®ä¾¿å®çãªãã®ã§ãããå®åã§OpenMPã使ç¨ããéã«ã¯ããç解ãã¦ããç¨éã«é©ããããã°ã©ãã³ã°ãè¡ã£ã¦ãã ããã
対象èªè
ãçè ãæ³å®ãã¦ããèªè ã¯Cã®åºæ¬çææ³ããã¹ã¿ã¼ãã並ååããã°ã©ãã³ã°ã«èå³ãæã£ã¦ããæ¹ã§ããåã£ããã¯ããã¯ã極åãããåºæ¬çãªææ³ããåããã°èªããããã«æ¥µå注æãã¾ãã®ã§ã並ååã«èå³ãæã£ã¦ããæ¹ã¯ãã²ãã®é£è¼ã«ç®ãéãã¦ä¸ããã
å¿ è¦ãªç°å¢
ãC/C++ã³ã³ãã¤ã©ãå¿ è¦ã§ãããæã¡ã§ãªãæ¹ã¯ç¡åã§æä¾ããã¦ãããã¤ã¯ãã½ãã社ã®ãVisual Studio C++ 2008 Express Editionãããã¦ã³ãã¼ããããªã©ãã¦å ¥æãã¦ãã ããã
ã次ã«ãOpenMPã使ç¨ããããã«ãWindows SDK for Windows Server 2008 and .NET Framework 3.5ããå¿ è¦ã§ãã®ã§ãã¦ã³ãã¼ããã¦ã¤ã³ã¹ãã¼ã«ãã¦ä¸ããï¼â»Visual Studio 2008ã®Professionalãã¼ã¸ã§ã³ä»¥ä¸ããæã¡ã®æ¹ã¯å¿ è¦ããã¾ããï¼ã
ããã®é£è¼ã¯åºæ¬çã«Windowsç°å¢ãæ³å®ãã¦è§£èª¬ãã¾ãããOpenMPãã®ãã®ã¯ä»ã®OSä¸ã§ãåä½ãã¾ãã®ã§ãé©å®èªã¿æ¿ãã¦åèã«ãã¦ãã ããã
OpenMPã®æ¦è¦
ãOpenMPã¨ã¯ãè¤æ°ã®CPUãä¸ã¤ã®ã¡ã¢ãªãå ±æããã¢ã¼ããã¯ãã£ã§ã®ä¸¦åæ§ãè¨è¿°ããããã®APIï¼Application Program Interfaceï¼ä»æ§ã§ãããã®APIä»æ§ããµãã¼ããããã³ãã¼ãä½ã£ãã³ã³ãã¤ã©ã使ãã°ã並åçã«åä½ããã½ããã¦ã§ã¢ãä½ãã¾ãã
ãOpenMPã®è¦ç´ ã¯å¤§ã¾ãã«åããã¨ãæ示æã»ã©ã¤ãã©ãªã«ã¼ãã³ã»ç°å¢å¤æ°ã®3ã¤ãè¦å®ããã¦ãããéçºè
ããããã®è¦ç´ ã使ã£ã¦ä¸¦åå¦çãæ示ããå½¢ã§ä¸¦åçãªã½ããã¦ã§ã¢ãå®è£
ãããã¨ã«ãªãã¾ããTBBã¨æ¯ã¹ãã¨OpenMPã®æ¹ãç´°ããæå®ããå¿
è¦ãããã¾ããã¨ã¯ãããOpenMPã使ç¨ããæ¹ãå¾æ¥ã®ã¹ã¬ããããã°ã©ãã³ã°ãããç°¡æ½ãªè¡¨ç¾ãå¯è½ã§ãã®ã§ãå®å¿ãã ãããOpenMPã¯å¤§å¤è¯ãã§ãã¦ãããæ
£ããã°å¾æ¥ã®ããã°ã©ãã³ã°ææ³ãããç´ æ©ã並åå¦çãå®è£
ãããã¨ãã§ããããã«ãªãã¾ãã
ãä»åã¯OpenMPã®ä¸çªã®åºç¤ã§ãããããªããã»ããµãã£ã¬ã¯ãã£ããæå®ãããã¨ã§è¡ãOpenMPã®ããã°ã©ãã³ã°ã¹ã¿ã¤ã«ã並ååãããã³ã¼ãã®ç¯å²ãã¹ã¬ããæ°ã®ã³ã³ããã¼ã«ã®3ç¹ã«ã¤ãã¦ã®è§£èª¬ããã¾ãã
ãæç« ã§ã®èª¬æã¯éå±ã ã¨æãã¾ãã®ã§ã次é ããæ©éãµã³ãã«ããã°ã©ã ãæ示ãã¦OpenMPã®èª¬æããã¦ããã¾ãã
ã¯ããã¦ã®OpenMP
ãä¸çªæåã¯ç°¡åãªããã°ã©ã ãä½æããã®ãããã§ããããããã§ãOpenMPçã®hello worldããã°ã©ã ãä½æãã¾ããã
#include <stdio.h> #include <omp.h> int main() { #pragma omp parallel printf("Hello, OpenMP!\n"); return 0; }
ããã®ããã°ã©ã ããããã°å®è¡ãã¦ç»é¢ãè¦ã¦ä¸ãããã³ã³ã½ã¼ã«ç»é¢ä¸ã«ãHello, OpenMP!ãã¨è¡¨ç¤ºããã¾ããããããã¡ãã»ã¼ã¸ãä¸ã¤ãã表示ããã¾ããã®ã§ãOpenMPã使ç¨ããã並åå¦çããã¦ããªãäºãåããã¾ãã
ãOpenMPãæå¹åãã並åå¦çãå¯è½ã«ããããã«ãï¼»ããã¸ã§ã¯ãã®ããããã£ï¼½-ï¼»æ§æããããã£ï¼½-ï¼»C++ï¼½-ï¼»è¨èªï¼½ã®ããããã£ãã¼ã¸ã§ããOpenMPã®ãµãã¼ããããã¯ããã«ãã¦ä¸ãããçç±ã¯å¾ã§è¿°ã¹ã¾ããã次ã«ã½ãªã¥ã¼ã·ã§ã³ã®ããããã£ã§ããã®ãµã³ãã«ããã°ã©ã ã®ããã¸ã§ã¯ããæ§æãReleaseã«å¤æ´ãã¦ãããã«ããã¦ä¸ããã
ãããã¦ãå度ãããã°å®è¡ãã¦ä¸ãããä»åº¦ã¯ã³ã³ã½ã¼ã«ç»é¢ä¸ã«Hello, OpenMP!ãCPUã®ã³ã¢æ°ã¨åãã ã表示ããã¾ããããã§ä¸¦åçã«å¦çãããããã¨ãåããã¾ãã
ãå ã»ã©æ§æãReleaseã«å¤ãã¦ãã«ãããçç±ã¯ãDebugã§ãã«ããã¦å®è¡ããã«ã¯ç¹å¥ãªãã¡ã¤ã«ãå¿ è¦ã«ãªãããã§ããOpenMPããããã°æ§æã§ãã«ãããã«ã¯ããMicrosoft.VC90.DebugOpenMP.manifestããã¡ã¤ã«ã¨ãvcomp90d.dllããã¡ã¤ã«ï¼VC2008ã®å ´åï¼ãå¿ è¦ã«ãªãã¾ãããã®ãã¡ã¤ã«ã¯Visual Studio 2008ã®Standardãã¼ã¸ã§ã³ä»¥ä¸ãªãã°ãC:\Program Files\Microsoft Visual Studio 9.0\VC\redist\Debug_NonRedist\x86\Microsoft.VC90.DebugOpenMPãã«ããã¾ãã®ã§ãå®è¡ãã¡ã¤ã«ã¨åãå ´æã«ã³ãã¼ãã¦ä¸ãããããããã°ãDebugæ§æã§ãæ£å¸¸ã«å®è¡ã§ããããã«ãªãã¾ãã
ããªããOpenMPã使ç¨ãã¦ä½ã£ãå®è¡ãã¡ã¤ã«ãä»ã®PCã§ä½¿ç¨ããã«ã¯ãåé å¸ããã±ã¼ã¸ãå¿ è¦ã«ãªãã¾ããOpenMPã§ã½ããã¦ã§ã¢ãä½æããéã«ã¯ãã®ç¹ã¨ã©ã¤ã»ã³ã¹ã«æ°ãã¤ãã¦ä¸ããã
ããã®ãµã³ãã«ããã°ã©ã ã§OpenMPã®åºç¤çãªããã°ã©ãã³ã°ãåããã¾ããã¾ããomp
ããããã¡ã¤ã«ãã¤ã³ã¯ã«ã¼ãããªãã¦ã¯ãªãã¾ããã次ã«ããªããã»ããµãã£ã¬ã¯ãã£ãã®ãã©ã°ã#pragma omp parallel
ã«ãããã³ã³ãã¤ã©ã«ä¸¦åå¦çãæ示ãã¾ãããã©ã°ãã¯ããªããã»ããµãã£ã¬ã¯ãã£ãã®ä¸ç¨®ã§ãã®ã§ãOpenMPããµãã¼ããã¦ããªãã³ã³ãã¤ã©ããOpenMPã使ç¨ããªãå ´åã§ãã³ã³ãã¤ã«ãããã¨ãã§ãã¾ãããã®ä»æ§ã«ãããæ¢åã®ããã°ã©ã ãä¿®æ£ãããããªã£ã¦ãã¾ãã