ã¯ããã«
ããç¥ãããŠããããã«ãäžè¬çãªå Žåã®èšç®ã¿ã¹ã¯ã¯ãç°ãªãã¿ã¹ã¯ã«ãã£ãŠäžŠåã«å®è¡ããããµãã¿ã¹ã¯ïŒå解ïŒã«åå²ã§ããŸãã ã¿ã¹ã¯ãŸãã¯å ¥åããŒã¿ã®ã¿ã€ãã«å¿ããŠãããŒã¿ãŸãã¯ã¿ã¹ã¯èªäœã«å解ãé©çšã§ããŸãã ç°¡åã«èšãã°ãããŒã¿å解ã¯ãåãèšç®ã¢ã«ãŽãªãºã ã§ç°ãªãèšç®æ©ã§åŠçããããã«å ¥åããŒã¿ã»ãããåå²ããããšãšèããããšãã§ããŸãã ã¿ã¹ã¯ã«ããå解-å察ã«ãåãããŒã¿ãŸãã¯ç°ãªãéšåã§ç°ãªãããã€ã¹ã«ãã£ãŠå®è¡ãããããã€ãã®ç°ãªãã¢ã«ãŽãªãºã ã ã³ã³ãã¥ãŒãã£ã³ã°ããã€ã¹ã®å解ã®äž»ãªç®çã¯ãã¿ã¹ã¯ã®èšç®äžã䜿çšå¯èœãªãã¹ãŠã®ããã€ã¹ãå¯èœãªéãããžãŒã§ããããšã確èªããããšã§ãã ããã«ããããã®ã¿ã¹ã¯ãå®è¡ãããšãã«æ¢åã®ããã€ã¹ã»ããã®ããã©ãŒãã³ã¹ãæ倧ã«ãªããå®äºãããŸã§ã®æéãççž®ãããŸãã ãã®ç¹ã§ãã¢ã«ãŽãªãºã ãæé©åããããã«ã¯ãã³ã³ãã¥ãŒã¿ãŒã·ã¹ãã å ã®ã¿ã¹ã¯ã®åéšåãšã¿ã¹ã¯å šäœã®äž¡æ¹ã®å®è¡ãåæããèœåãéåžžã«éèŠã§ãã ãã®èšäºã§ã¯ãæ°ããããŒãžã§ã³ã®VTune Amplifier XE 2013ãããã¡ã€ã©ãŒã䜿çšããŠãã€ã³ãã«TBBã©ã€ãã©ãªãŒã䜿çšããŠäžŠååãããèšç®åé¡ãåæããå¯èœæ§ãæ€èšããŸãã
ããã«ã翻蚳ãªãã§è±å¯ãªè±èªã®çšèªã倱瀌ãããããé¡ãããŸãã ããã¯æå³çã«è¡ããããã®ã§ããããŒã«ã䜿çšãããšãã¯ãŸã 䜿çšããå¿ èŠãããããããããã·ã¢èªã«ç¿»èš³ããããšããŠãèªè ãæ··ä¹±ãããã ãã§ãã ïŒUPDïŒåçã®ç¿»èš³ãããŠããªãããã¹ããç®ãçãããšèšãããŸãã-ç§ã¯ç¿»èš³ã«åãçµãã§ãããããã«åçãæŽæ°ããŸãïŒ
ã¯ããã«ãã³ã³ãã¥ãŒã¿ãŒã·ã¹ãã ãããŒã¿ã»ãããªã©ãäžè¬åãããè¡šçŸãè±å¯ã«å«ãŸããŠããããšã¯å¶ç¶ã§ã¯ãªããããå®éã®ã¿ã¹ã¯ãšã¯ã»ãšãã©é¢ä¿ã®ãªãäžè¬åãããäŸããå§ãããã®åŸãåæããå®äŸã«åŸã ã«é²ã¿ãŸãã ã ç空ã§å®è¡ãããçé¢ã¢ã«ãŽãªãºã ãèããŠã¿ãŸãããããåæã«ããããœãŒã¹ããããŒã¿ãååŸãããã®ããŒã¿ã«å¯ŸããŠããã€ãã®äžŠã¹æ¿ãæé ãå®è¡ããåŠçãããããŒã¿ãåä¿¡æ©ã«æžã蟌ããšããå®éã®ã¿ã¹ã¯ã«ãã䌌ãŠããŸãïŒå³1ïŒã ãã®ãããªæ§é ã¯ãã³ãŒããã¯ããã£ã«ã¿ãŒããŸãã¯éä¿¡ãããã³ã«ãæãæ©ãé ã«æµ®ãã¶å€ãã®ã¢ããªã±ãŒã·ã§ã³ã§éåžžã«äžè¬çã§ãã
å³1
ç空ã®æ·±ããç¶æããäŸãåçŽåããããã«ããœãŒã¹ããã®ããŒã¿ã®éšåéã®å¯èœãªé¢ä¿ãèæ ®ããŸããã ããã¯æ£ãããããŸããããããšãã°ãã³ãŒããã¯ã§ãããªãã¬ãŒã ãåŠçããå Žåãé£æ¥ãããã¯ã»ã«ã®äŸåé¢ä¿ãã¢ã«ãŽãªãºã ã«ãã£ãŠèæ ®ãããããã§ãã ãã ããäžè¬çãªã±ãŒã¹ã§ã¯ãååã«å€§ããªããŒã¿é åããã€ã§ãéžæã§ããŸããããã¯ãä»ã®é åããç¬ç«ããŠãããšèŠãªãããšãã§ããŸãã åæã«ãå解ãããªãå®å šã«äœ¿çšããŠãããŒã¿ã®ããŸããŸãªéšåã§äžŠåã«èšç®ã¢ã«ãŽãªãºã ãå®è¡ããããšãã§ããŸããããã«ãããã¢ã«ãŽãªãºã ã®çç床ãæªããããå³2ã«ç€ºãåè·¯ã«äŒŒããã®ã«ãªããŸãïŒããŒã¿ã¯ãœãŒã¹ããé 次èªã¿åããã䞊åãããã¯ã§åŠçãããŸãïŒPïŒ ããããŠåã³é£ç¶ããŠåä¿¡æ©ã«æžã蟌ãŸããŸãïŒWïŒã
å³2
ããŒã¿ãœãŒã¹ããã£ã¹ã¯ããããã¯ãŒã¯ã€ã³ã¿ãŒãã§ã€ã¹ãªã©ã®ã·ãªã¢ã«ããã€ã¹ã§ããå Žåãèªã¿åããšæžã蟌ã¿ã®ããã»ã¹ãã·ãŒã±ã³ã·ã£ã«ã«ãªããŸãã ã·ã¹ãã ã«ç¡æã®ã³ã³ãã¥ãŒãã£ã³ã°ã¹ã¬ãããããå Žåã§ãã䞊ååã§ããå®è¡ã¹ããŒãžã¯ã¢ã«ãŽãªãºã ã®å®è¡ãã§ãŒãºã®ã¿ã§ãã ã¢ã ããŒã«ã®æ³åã«ãããšã䞊ååã«ããã¿ã¹ã¯å šäœã®ããã©ãŒãã³ã¹ã®åäžã¯ããããã®é£ç¶ãããã§ãŒãºã«éå®ãããŸãã
ãã®å¶éãå æããããã«ããã¹ãŠã®ãšã°ãŒã¯ãã£ããããŒããã®å®è£ ã§åžžã«ããžãŒã«ãªãããã«ãã¿ã¹ã¯ã®äžéšãåé åžã§ããŸãã ããã¯ãããŒã¿éšåãç¬ç«ããŠããããã®åŠçé åºãéèŠã§ãªãå ŽåããŸãã¯åºåã«åŸ©å ã§ããå Žåã«å¯èœã§ãã ãããè¡ãããã«ãåã¹ã¬ããã§å®è¡ãããåãèªã¿åã/ããã»ã¹/æžã蟌ã¿ã¹ããŒãžã§æ§æãããåçŽãªãã€ãã©ã€ã³ãæ§ç¯ããŸãïŒå³3ïŒã èªã¿åãããã³æžã蟌ã¿ã¹ããŒãžã¯åŒãç¶ãã·ãŒã±ã³ã·ã£ã«ã®ãŸãŸã§ãããã¹ã¬ããéã§åæ£ãããŸãã ä»ã®ã¹ããªãŒã ãåãã¹ããŒãžãå®è¡ããŠããéãã¹ããªãŒã ã¯èªã¿åããŸãã¯æžã蟌ã¿ã¹ããŒãžãéå§ã§ããªãããšã«çæããå¿ èŠããããŸãã ãã ãã2ã€ã®ç°ãªãã¹ããªãŒã ã¯ãç°ãªãããŒã¿ãåæã«èªã¿æžãã§ããŸãã
å³3
ãã®æ¹æ³ã§ã¢ã«ãŽãªãºã ãåæ§ç¯ããããã«ãã¿ã¹ã¯å解ãæ£åŒã«äœ¿çšããŸãããã€ãŸããã¿ã¹ã¯ã®ç°ãªããã§ãŒãºãç°ãªãã¹ã¬ããã«ãã£ãŠåæã«å®è¡ãããŸããã åæã«ãããŒã¿ãããŒãã«åå²ãããããã«å¯ŸããŠç°ãªãã¹ããªãŒã ã§åãæäœãå®è¡ããããã«ãããŒã¿å解ã䜿çšããŸãã ãã®çµã¿åããã¢ãããŒãã«ãããã¹ã¬ãããåžžã«ä»äºã§å¿ãããªããã¿ã¹ã¯å šäœã®å¹çãæ倧åãããããã«ãªããŸãã ãã ããèªã¿åã/æžã蟌ã¿ããã€ã¹ã®é 延ã®å¯èœæ§ãèæ ®ããŠããªããããã¢ã«ãŽãªãºã ã®ç圢æ§ã¯äŸç¶ãšããŠç¶æãããŸãããŸããããŒã¿å ¥åã®äžèŠåæ§ãå¹³æ»åããããã®ã³ã³ãã¥ãŒãã£ã³ã°ãããŒã«ã¯å€ãã®äœæ¥ããããã³ã³ãã¥ãŒãã£ã³ã°ããã€ã¹ã¯åžžã«å®è¡å¯èœã§ãã¢ã«ãŽãªãºã ã
å®éã«ã¯ãäºæ ã¯ããã«è€éã«ãªãå¯èœæ§ããããŸãã ããšãã°ãããŒã¿ãéä¿¡ããããã«å ¥å/åºåããã€ã¹ãè²»ããæéã®å®å®ããå€ãä¿èšŒããããããã»ããµãŒãçŸæç¹ã§ç©ºãã§ãã£ãããããŒã¿ãåçš®ã§ãããåãã¢ã«ãŽãªãºã ã«ããåŠçã«åãæéãå¿ èŠãšããããšãä¿èšŒãããã®ã¯ãããŸããã ã»ãšãã©ã®å ŽåããœãŒã¹ã®ç¹æ§ã«ãããå ¥åããŒã¿ãé ããŠå°çããå ŽåããããŸãã ããã»ããµã¯ãåªå 床ã®é«ãä»ã®ã¿ã¹ã¯ã§ããžãŒç¶æ ã«ãªã£ãŠããå¯èœæ§ããããŸãã ããŒã¿ã«ãã£ãŠã¯ãåŠçæéãé·ããªãå ŽåããããŸããããšãã°ã詳现ãå°ãããã¬ãŒã ã¯ãåäžãªèæ¯ãæã€ãã¬ãŒã ãããå§çž®ã¢ã«ãŽãªãºã ã«ãã£ãŠã¯ããã«é·ãåŠçãããŸãã ååãšããŠãæžã蟌ã¿æäœã¯åé¡ã§ã¯ãããŸãããã»ãšãã©ã®ã·ã¹ãã ã§ã¯ãããã¡ãªã³ã°ãããŠãããã¬ã·ãŒããŒãžã®ç©ççãªããŒã¿ã®æžã蟌ã¿ãé ããªãå¯èœæ§ãããããã§ãã ããã¯ãåºåãå ¥åã§åã³äœ¿çšãããªãå Žåã«ã®ã¿æ©èœããŸããã äžè¬ã«ãçé¢ç空ã¢ãã«ããæ¢åã®ã·ã¹ãã ã®åé¡ã®å®éã®å®è£ ã«ç§»è¡ãããšãã³ã³ãã€ãŒã®èšç»ãããå¹çã¯ãã¹ãŠç¡é§ã«ãªãå¯èœæ§ããããè€éãªã¹ããŒã ã¯å ã®åçŽãªã¹ããŒã ãšåæ§ã«éå¹çã®ãŸãŸã§ãïŒå³4ïŒã
å³4
è² è·ã®äžåè¡¡ã«ãã£ãŠåŒãèµ·ããããéå¹çæ§ãæé€ããããã«ãåã¹ã¬ããã«ãã£ãŠå®è¡ãããäœæ¥ãåçã«åæ£ãããããšãã§ããŸãã ããã«ã¯ãããžãŒã¹ã¬ããã®ç¶æ ãç£èŠããã¢ã«ãŽãªãºã ã«ãã£ãŠåŠçãããããŒã¿ã®ãµã€ãºãå¶åŸ¡ãã空ãã¹ã¬ããéã§ãµãã¿ã¹ã¯ãåæ£ããå¿ èŠããããŸãã ãã®ãããªã€ã³ãã©ã¹ãã©ã¯ãã£ã®å®è£ ã¯ãç°¡åãªå Žåã«ã®ã¿ãã»ãšãã©åŽåãå¿ èŠãšããã«å¯èœã§ãã äžè¬ã«ããã®ãããªã€ã³ãã©ã¹ãã©ã¯ãã£ããŒãããéçºããããšã¯éåžžã«å°é£ã§ãã ãããŠãã¹ã¬ããéã®åçãªè² è·åæ£ã®ããã®ã¡ã«ããºã ãæ¢ã«å«ãã§ããIntel TBBã©ã€ãã©ãªã®æ©èœãã¢ããã¿ã€ãºããæã§ãã ãŸãããã®äŸã§ã¯ãTBBã«ã¯ã ãã€ãã©ã€ã³ã¯ã©ã¹ãšåŒã°ããçµã¿èŸŒã¿ãã€ãã©ã€ã³ã¢ã«ãŽãªãºã ãå«ãŸããŠããŸããããã¯ãã¿ã¹ã¯ã§ã®äœ¿çšã«é©ããŠããŸãã
äŸ
ãªãŒãã³ãœãŒã¹ã³ãŒããå«ããã¹ãŠã®æ å ±ã¯threadingbuildingblocks.orgã«ãããããTBBã§ã®ãã€ãã©ã€ã³ã¢ã«ãŽãªãºã ã®å®è£ ã«ã€ããŠã¯è©³ãã説æããŸããã 以äžã«ãã¿ã¹ã¯ã®äŸãTBBã䜿çšããŠãã€ãã©ã€ã³ãäœæããæ¹æ³ã瀺ããŸãã ãµã³ãã«ã³ãŒãã¯ãã©ã€ãã©ãªãã£ã¬ã¯ããªãŸãã¯Webãµã€ãã«ãããŸãã
ç°¡åã«èšãã°ããã€ãã©ã€ã³ãšã¯ãäžé£ã®å®è¡ãŠãããããªããžã§ã¯ãã®ã¹ããªãŒã ã«é©çšããããšã§ãã ãšã°ãŒã¯ãã£ããŠãããã¯ãããŒã¿ã¹ããªãŒã ã«å¯ŸããŠç¹å®ã®ã¢ã¯ã·ã§ã³ãå®è¡ããã¿ã¹ã¯ã¹ããŒãžãå®è£ ã§ããŸãã TBBã©ã€ãã©ãªã§ã¯ããããã®ã¹ããŒãžã¯ãã£ã«ã¿ãŒã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãšããŠå®çŸ©ã§ããŸãã ãããã£ãŠãã³ã³ãã¢ã¯äžé£ã®ãã£ã«ã¿ãŒãšããŠæ§ç¯ãããŸãã äžéšã®ã¹ããŒãžïŒProcessingãªã©ïŒã¯ãç°ãªãããŒã¿ãæã€è€æ°ã®ã¹ããªãŒã ã§äžŠè¡ããŠåäœããããã ãã©ã¬ã«ãã£ã«ã¿ãŒã¯ã©ã¹ãšããŠå®çŸ©ããå¿ èŠããããŸãã èªã¿åããæžã蟌ã¿ãªã©ã®æ®ãã®æ®µéã¯ãé çªã«ç¹å®ã®é åºã§å®è¡ããå¿ èŠãããïŒé åºãå€æŽããªãå ŽåïŒã serial_in_orderãã£ã«ã¿ãŒã¯ã©ã¹ãšããŠå®çŸ©ãããŸãã ã©ã€ãã©ãªã«ã¯ãããã®åã®æœè±¡ã¯ã©ã¹ãå«ãŸããŠããããããããã¯ã©ã¹ãç¶æ¿ããå¿ èŠããããŸãã 以äžã¯ãç¹å®ã®åçŽåã䜿çšããŠããããè¡ãæ¹æ³ã瀺ãäŸã§ãã
| |
| |
ãã®äŸã§ã¯ãããŒã¿ã¯ãã¡ã€ã«ã«å«ãŸããŠããããããã¡ã€ã«ãã€ã³ã¿ãŒã®ãã©ã€ããŒãã¯ã©ã¹ã¡ã³ããŒãå®çŸ©ããå¿ èŠããããŸãã åæ§ã«ãèšé²ã¹ããŒãžã®MyWriteFilterã¯ã©ã¹ãå®çŸ©ããåºåãã¡ã€ã«ãžã®ãã€ã³ã¿ãŒãä¿åããŸãã ãããã®ã¯ã©ã¹ã¯ãããŒã¿ããã³ãã€ãã³ã°ãªããžã§ã¯ãçšã®ã¡ã¢ãªã®å²ãåœãŠãæ åœããŸãã äž»ãªäœæ¥ã¯ãåºæ¬ã¯ã©ã¹ã§å®çŸ©ãããoperatorïŒïŒã¡ãœããã§å®è¡ãããŸãã å ¥åãã¡ã€ã«ããã³ã³ãããžã®ããŒã¿ã®èªã¿åããšãã³ã³ããããåºåãã¡ã€ã«ãžã®ããŒã¿ã®æžã蟌ã¿ãããããå®è£ ããããšã«ããããããã®ã¡ãœãããåå®çŸ©ããã ãã§ãã
| |
Processã¹ããŒãžã¯ã¹ã¬ããã§äžŠåã«å®è¡ã§ããããã 䞊åãã£ã«ã¿ãŒã¯ã©ã¹ãšããŠå®çŸ©ãã operatorïŒïŒã¡ãœããã«ã¯ããŒã¿ãããŒåŠçã¢ã«ãŽãªãºã ã®ãèããå«ããå¿ èŠããããŸãã
| |
æçµçã«ãã€ãã©ã€ã³ãçµã¿ç«ãŠãã ãã§æžã¿ãŸãã ãã£ã«ã¿ãŒã¯ã©ã¹ã®ãªããžã§ã¯ãã ãã€ãã©ã€ã³ã¯ã©ã¹ã®ãªããžã§ã¯ããäœæãããã¹ãŠã®ã¹ããŒãžãæ¥ç¶ããŸãã ãã€ãã©ã€ã³ãæ§ç¯ããåŸãããŒã¯ã³ã®æ°ã瀺ããã€ãã©ã€ã³ã¯ã©ã¹ã®runïŒïŒã¡ãœãããåŒã³åºãå¿ èŠããããŸãïŒãã®ãããªè»¢éã¯ããããªããïŒã ãã®å ŽåãããŒã¯ã³ã®æ°ã¯ããã€ãã©ã€ã³ã§åæã«å®è¡ã§ããããŒã¿ãªããžã§ã¯ãã®æ°ãæå³ããŸãã é©åãªéââãéžæããããšã¯ãè°è«ã®ããã®å¥ã®ãããã¯ã«ãªãå¯èœæ§ããããŸããTBBææžã®æšå¥šäºé ã«åŸã£ãŠãã·ã¹ãã ã§äœ¿çšå¯èœãªã¹ã¬ããæ°ã®2åã«çããæ°ãéžæããŸãã ããã«ããããã€ãã©ã€ã³ãããžãŒç¶æ ã«ä¿ã€ã®ã«ååãªããŒã¿ãªããžã§ã¯ããçšæãããšåæã«ãæåã®æ®µéã§åŸç¶ã®ãªããžã§ã¯ããããã¯ããã«é«éã«ããŒã¿ãªããžã§ã¯ããåŠçããå ŽåãããŒã¿ãªããžã§ã¯ãã®ãã¥ãŒãæ¡å€§ããªãããšãä¿èšŒã§ããŸãã
tbb::pipeline pipeline; MyReadFilter r_filter( input_file ); pipeline.add_filter( r_filter ); MyProcessFilter p_filter; pipeline.add_filter(p_filter ); MyWriteFilter w_filter( output_file ); pipeline.add_filter( w_filter ); pipeline.run(2*nthreads)
ãããã£ãŠããã€ãã©ã€ã³ã«3ã€ã®ãµãã¿ã¹ã¯ãäœæããŸããããããã¯ãã·ã¹ãã ã§å©çšå¯èœãªããã»ããµãŒã®äœ¿çšãæ倧åããããã«TBBã©ã€ãã©ãªã«ãã£ãŠç®¡çãããŸããããã»ã¹ãµãã¿ã¹ã¯ã¯äžŠååãããæ®ãã®ãµãã¿ã¹ã¯ã¯å¯çšæ§ã«å¿ããŠã¹ã¬ããéã§åçã«åæ£ãããŸãã ãããã®ã¹ããŒãžãæ£ããæ¥ç¶ããã ãã§æžã¿ãŸããã ã芧ã®ãšããããã®äŸã§ã¯ãããŒå¶åŸ¡ã³ãŒãã¯ãããŸãããããã¯ãã¹ãŠã©ã€ãã©ãªã¿ã¹ã¯ã¹ã±ãžã¥ãŒã©ã«é ãããŠããŸãã
ããããããšã§ãããæåŸãã2çªç®ã®è¡ïŒãŸãã¯éã«æåã®è¡ïŒããæãæããŠãéåžžã«çŽ°å¿ã®æ³šæãæã£ããªã¹ããŒãéåžžã«è¯ã質åãããŸããæ§ç¯ãããã³ã³ãã¢ãå¹æçã§ããããšãã©ã®ããã«ç¢ºèªã§ããŸããïŒ ããã«æ·±ãæãäžããå Žåããµãã¿ã¹ã¯ããã€ãã©ã€ã³ã§ã©ã®ããã«å®è¡ããããããµãã¿ã¹ã¯ã管çãããªãŒããŒãããã¯ã©ã®ããã«ãªã£ãŠããã®ãããããŠå®è£ ã«ã®ã£ãããããã®ãââãæ£ç¢ºã«ç¥ãã«ã¯ã©ãããã°ããã§ããïŒ
ã¢ã«ãŽãªãºã ã®å®è£ ãåæã®éå¹ççãªå®è£ ãšæ¯èŒããããšãææ¡ããããšã¯ç¡æå³ã§ãã ãŸããããé«éã«åäœããããšä»¥å€ã¯äœãç解ã§ããŸããã ãããŠç¬¬äºã«ãããããããã¯ããéãåäœããåäœããŸããã
ã€ãŸãããããã®è³ªåã«å¯ŸããåçŽãªçãã¯ãããŸããã 枬å®ããã³åæããå¿ èŠããããŸãã VTune Amplifier XEã䜿çšãããããã¡ã€ãªã³ã°ã«ããããã®ããã»ã¹ãããç°¡åã«ãããçŽæçã«ããããŠæãéèŠãªããšãšããŠããé«éã«ãªããŸãã VTuneã¢ã³ãã¯ãã·ã¹ãã ã«ããã»ããµãŒãããŒãããå¹çãå€æããTBBã©ã€ãã©ãªã®ã¿ã¹ã¯ç®¡çã¹ããŒã ãæ確ã«ç€ºãããã€ãã©ã€ã³ã®æ§ç¯äžã«ã¢ã«ãŽãªãºã ã®ããã©ãŒãã³ã¹ã«åœ±é¿ãäžããå¯èœæ§ã®ãããšã©ãŒãæ€åºããã®ã«åœ¹ç«ã¡ãŸãã
æè²ç®çã®ããã«ããããã¹ãããåæããå§ããŸãããã ãã¡ã€ã«ããããã¹ã圢åŒã§æŽæ°å€ãèªã¿åã[èªã¿åãã¹ããŒãž]ããããã2ä¹ããŠ[ããã»ã¹]ãããã¹ã圢åŒã§å床æ°å€ã[æžã蟌ã¿]åºåãã¡ã€ã«ã«æžã蟌ãã³ãŒãã®äŸãåæããŸãã èªè ã¯VTuneãããã¡ã€ã©ãŒã®æäœã®åºæ¬ã«ç²ŸéããŠãããšæ³å®ãããããã¡ã€ãªã³ã°ãéå§ããããã«ã©ã®ãã¿ã³ãæŒããã«ã€ããŠã¯è©³ãã説æããŸããã
å³5
ãããã¹ãããåæã®çµæïŒå³5ïŒã¯éåžžã«æåŸ ãããŠããŸã-ãã¹ãããã°ã©ã ã¯4ã³ã¢ããã»ããµäžã®4ã€ã®ã¹ã¬ããã«ãã£ãŠå®è¡ãããŸããã TBBãã€ãã©ã€ã³ããåŒã³åºãããMyProcessClass :: operatorïŒïŒã¡ãœããã¯ãããã¹ãããæŽæ°ã«å€æããå€ã®2ä¹ãèšç®ããããã¹ããžã®éå€æãå®è¡ãããããæãããããªé¢æ°ã§ãã èå³æ·±ãããšã«ãäžéšã®é¢æ°[TBB Dispatch Loop] ïŒå®éã«ã¯é¢æ°ã§ã¯ãªããTBBã¹ã±ãžã¥ãŒã©ã®ãå éšããé ãæ¡ä»¶åïŒãããããªã¹ãã«å«ãŸããŠãããèšç»ã®ãªãŒããŒããããååšããå¯èœæ§ã瀺ããŠããŸãã 䞊è¡æ§åæãç¶ããŠãã¢ã«ãŽãªãºã ã®äžŠååã®æå¹æ§ãå€æããŸãããã
å³6
çµæã®ããã°ã©ã ã®äžŠåãã¹ãã°ã©ã ãããæ倧å¹çã«ã¯ã»ã©é ãããšãããããŸããåºæ¬çã«ãã¢ããªã±ãŒã·ã§ã³ã¯4ã¹ã¬ããæªæºã§å®è¡ãããŸããã ïŒãã¹ãã°ã©ã ã®éãããŒã¯ãã¢ããªã±ãŒã·ã§ã³ãY軞ã«æ²¿ã£ãŠXã¹ã¬ããã§äœæ¥ããæéã瀺ããŸããçæ³çã«ã¯ãåæå®è¡ã¬ãã«4 [4]ã®åäžã®åã衚瀺ãããã§ãã ã
ããã ã¢ãããã¥ãŒã®çµæãäžç®èŠãã ãã§ããã¹ã¬ããéã§çºçããéå°ãªåæã確èªããã®ã«ååã§ãïŒå³7ïŒã é»è²ã®ãã©ã³ãžã·ã§ã³ã«ã«ãŒãœã«ãåããããšããããã¢ãããŠã£ã³ããŠã«ãã®åæã®ãœãŒã¹ãžã®ãªã³ã¯ã衚瀺ãããŸãã
å³7
ãã®æç¹ã§ãæãå¿è匷ããŠãŒã¶ãŒã§ããããããªã調æ»ããããããå¶ç¶ã«ãã©ã€ãã©ãªã®éå¹ççãªå®è£ ãTBBéçºè ã®ããã«ããŸãã ã¹ã±ãžã¥ãŒã©ã®äœæ¥ãåæããããŒã«ãæå ã«ãªãã£ãããåãããšãããŠããã§ãããã çè«çã«ã¯ããœãŒã¹ã³ãŒãã®ã€ã³ã¹ãã«ã¡ã³ããŒã·ã§ã³ã䜿çšããŠã¿ã¹ã¯ãç¬ç«ããŠãã¬ãŒã¹ãããæåãã§ãã¬ãŒã¹ã解æããããã¿ã¹ã¯ã®ã¿ã€ãã³ã°ãç¹å®ããã¹ã¯ãªãããæ³åã§ããŸãã ãã ããçµã¿ç«ãŠããããã©ãã¯ã®åŠçãè€éã§ããããããã®ãã¹ã¯é åçã«èŠããŸããã ãããã£ãŠããã§ã«VTuneã¢ã³ãã«å«ãŸããŠããããŒã«ã䜿çšããããšããå§ãããŸãããããã®ããŒã«ã䜿çšãããšã䟿å©ãªã°ã©ãã£ãã¯åœ¢åŒã§ãŠãŒã¶ãŒã¿ã¹ã¯ãå®è¡ããæ§é ããã°ãã埩å ã§ããŸãã
ã¿ã¹ã¯ã¢ãã©ã€ã¶ãŒãæå¹ã«ããã«ã¯ãVTune Amplifierã§å©çšå¯èœãªã¿ã¹ã¯APIã®ç¹å¥ãªæ©èœã䜿çšããŠãœãŒã¹ã³ãŒããã€ã³ã¹ãã«ã¡ã³ãããå¿ èŠããããŸãã ãããè¡ãã«ã¯ã次ã®æé ãå®è¡ããå¿ èŠããããŸãã
- ãœãŒã¹ã«ãŠãŒã¶ãŒAPIã®ããããŒãã¡ã€ã«ãå«ããŸã
#include "ittnotify.h"
- ã¿ã¹ã¯ã®ãã¡ã€ã³ãå®çŸ©ããŸãã ç°ãªã䞊åã€ã³ãã©ã¹ãã©ã¯ãã£ïŒTBBãOpenMPãªã©ïŒã®ã¹ã¬ãããªã©ãç°ãªããã¡ã€ã³ã§å®è¡ãããã¿ã¹ã¯ãåé¢ããããšã¯éåžžã«äŸ¿å©ã§ãã
__itt_domain* domain = __itt_domain_create("PipelineTaskDomain");
- ã¹ããŒãžãèšè¿°ããã¿ã¹ã¯ãã³ãã«ãå®çŸ©ããŸãã
__itt_string_handle* hFileReadSubtask = __itt_string_handle_create("Read"); __itt_string_handle* hFileWriteSubtask = __itt_string_handle_create("Write"); __itt_string_handle* hDoSquareSubtask = __itt_string_handle_create("Do Square");
- 次ã«ãã¿ã¹ã¯ã®æ®µéã§å®è¡ããããœãŒã¹ã³ãŒãããèšæž¬APIé¢æ°__itt_task_beginããã³__itt_task_endãžã® åŒã³åºãã§ã©ããããŸãã ããšãã°ãèªã¿åããšæžã蟌ã¿ã®æ®µéã¯æ¬¡ã®ããã«çŽæçã§ãã
void* MyReadFilter::operator()(void*) { __itt_task_begin(domain, __itt_null, __itt_null, hFileReadSubtask); // ALLOCATE MEMORY // READ A DATA ITEM FROM FILE // PUT DATA ITEM TO CONTAINER __itt_task_end(domain); }
void* MyWriteFilter::operator()(void*) { __itt_task_begin(domain, __itt_null, __itt_null, hFileWriteSubtask); // GET DATA ITEM FROM CONTAINER // WRITE THE DATA ITEM TO FILE // DEALLOCATE MEMORY __itt_task_end(domain); }
åæ§ã«ãããã»ã¹æ®µéãã©ããããããšãã§ããŸãã ïŒãŠãŒã¶ãŒAPIé¢æ°ã®è©³çŽ°ã«ã€ããŠã¯ã補åã®ããã¥ã¡ã³ããåç §ããŠãã ããïŒã
void* MyProcessFilter::operator()( void* item ) { __itt_task_begin(domain, __itt_null, __itt_null, hDoSquareSubtask); // FIND A CURRENT DATA ITEM IN CONTAINER // PROCESS THE ITEM __itt_task_end(domain); }
- VTune AmplifierããããŒãã¡ã€ã«ãžã®ãã¹ããããžã§ã¯ãã«è¿œå ããããšãå¿ããªãã§ãã ããã
$ïŒVTUNE_AMPLIFIER_XE_2013_DIRïŒãå«ã - å®è¡å¯èœã¢ãžã¥ãŒã«ãlibittnotify.libã©ã€ãã©ãªã«ãã¹ãéçã«ãªã³ã¯ããŸã
$ïŒVTUNE_AMPLIFIER_XE_2013_DIRïŒlib [32 | 64]ã·ã¹ãã ã®ãããããã¹ãã«äŸåããŸãã
ãããŠæåŸã«ãåææ§æãŠã£ã³ããŠïŒå³8ïŒã§ãŠãŒã¶ãŒã¿ã¹ã¯ã®åæãæå¹ã«ããå¿ èŠãªãããã¡ã€ãªã³ã°ãéå§ããããšãæ®ã£ãŠããŸãã
å³8
åæå®è¡ã®ãããã¡ã€ãªã³ã°ãå®äºãããã[ã¿ã¹ã¯ãã¥ãŒ]ã¿ãã«åãæ¿ããŸãïŒå³9ïŒã ããã§ããããŒå¶åŸ¡ã®é·ç§»ã®é»è²ã®ç·ã¯ãå€å°å¹²æžããŸã-å³åŽã®ããã«ã§ç¡å¹ã«ããããšãã§ããŸãããŸããå¿ èŠãªæ å ±ãã«ããŒããCPUæéã°ã©ããç¡å¹ã«ããããšãã§ããŸãã ãã ããããã§ããã¿ã¹ã¯ã¯ã¿ã€ã ã©ã€ã³äžã§ã»ãšãã©åºå¥ã§ããŸããã ã¿ã¹ã¯ã®ã°ã©ãã£ãã¯è¡šçŸãè¡šãã«ã©ãŒããŒã¯çŽ°ãããŠåºå¥ã§ããŸããã ãã®å Žåãããçãæéééãéžæããå³ã¯ãªãã¯ã³ã³ããã¹ãã¡ãã¥ãŒãŸãã¯ããŒã«ããŒã䜿çšããŠã¹ã±ãŒã«ïŒæ¡å€§ïŒãå¢ãããŸãã
å³9
ã¿ã¹ã¯ã®æ¡å€§ç»åã§ã¯ãããã€ãã®åé¡ã«æ°ä»ãããšãã§ããŸãïŒå³10ïŒã 1ã€ç®ã¯ãã¹ã¬ãããéã¢ã¯ãã£ãã§ãããã€ãŸãããã»ããµãã¢ã€ãã«ç¶æ ã§ãåæã€ãã³ããåŸ æ©ããŠããã¿ã¹ã¯éã®ééã§ãïŒã¿ã¹ã¯èªäœã®æéãšæ¯èŒããŠïŒã 2çªç®ã®åé¡ã¯ãã¿ã¹ã¯ãã§ãŒãºã®æéã§ãã ããšãã°ããDo Squireããµãã¿ã¹ã¯ã«ã¯çŽ0.1ããªç§ããããããŸããã ã¿ã¹ã¯ã¯TBBã¹ã±ãžã¥ãŒã©ã«ãã£ãŠç®¡çãããŠãããããããã¯éåžžã«çãå®è¡ééã§ãããã¿ã¹ã¯ãã¹ã±ãžã¥ãŒã«ããŠTBBã¯ãŒã«ãŒã¹ã¬ããã«ãã£ãŠå®è¡ãããããã«å²ãåœãŠãã«ã¯æéãããããŸãã ã€ãŸãããµãã¿ã¹ã¯ã管çãããªãŒããŒãããã¯ãã¿ã¹ã¯èªäœãå®äºããã®ã«ãããæéãšé£ãåã£ãŠããããšãããããŸãã ããã¯èš±å¯ãããªãããããµãã¿ã¹ã¯ã§ã®äœæ¥ã«è²»ããæéãå¢ããå¿ èŠããããŸããã€ãŸããããå€ãã®äœæ¥ãäžããå¿ èŠããããŸãã
å³ 10ã
ãã®äŸã§ã¯ãã³ãŒãå ã®ã©ã®é¢æ°ãã©ã®ã¿ã¹ã¯ãå®è¡ãããã¯ãã§ã«æ確ã«ãªã£ãŠããŸãããããã¯èšäºã®ãã¬ãŒã³ããŒã·ã§ã³ãç°¡çŽ åããããã«æå³çã«è¡ããããã®ã§ãã å®éã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãå€æ°ã®æ©èœãã¿ã¹ã¯ã®å®è¡ã«é¢äžããå¯èœæ§ããããŸãã ã¿ã¹ã¯ã®å®è¡ã«åœ±é¿ãäžããè² è·ãå¢å ããããã¹ãŠã®æ©èœãèŠã€ããããã«ãåæå®è¡ãŸãã¯ãããã¹ããããããã¡ã€ãªã³ã°ã®çµæã®ããã ã¢ãããã¥ãŒã«åãæ¿ããããšãã§ããŸãã ã¿ã¹ã¯ã®ã¿ã€ãïŒTaskType / FunctionïŒã«ããé¢æ°ã®ã°ã«ãŒãåãå€æŽããã¢ããªã±ãŒã·ã§ã³ãã€ã³ã¹ãã«ã¡ã³ãããããšã§äœæãããµãã¿ã¹ã¯ã®ãªã¹ããããŒãã«ã«ååŸããŸãã ã¿ã¹ã¯ãéããã+ãã¢ã€ã³ã³ãã¯ãªãã¯ãããšããã®ãµãã¿ã¹ã¯ã®å®è¡ã«åå ããé¢æ°ã®åŒã³åºãã®ãªã¹ããšããªãŒã衚瀺ãããçµ±èšçã«ææãªããã»ããµæéãæ¶è²»ãããŸãïŒå³11ïŒã
å³11
次ã«ãããã«ã¯ãªãã¯ããŠããããé¢æ°MyProcessFilter ::æŒç®åïŒïŒã®ãœãŒã¹ã³ãŒãã«ç§»åããæž¡ãããããã¹ãïŒããã¹ãã¹ã©ã€ã¹ïŒã§æ©èœããããšã確èªããŸãïŒå³12ïŒã ãã®é¢æ°å ã§ã¯ãããã¹ãå ã®æåãå埩åŠçããæŽæ°åã«å€æããå€ãããèªäœã§ä¹ç®ããããã¹ãæåã«æ»ããŸãã ç¹å®ã®ãµãã¿ã¹ã¯ã®è² è·ãå¢ããæãæçœãªæ¹æ³ã¯ãããã¹ãã®ãµã€ãºãå¢ããããšã§ããããã«ããããã®ãµãã¿ã¹ã¯ã§å®è¡ãããæäœã®æ°ãçŽç·çã«å¢ããŸãã ã»ã°ã¡ã³ãMAX_CHAR_PER_INPUT_SLICEã®æ倧æåæ°ã®æ°ãããµã€ãºãéžæããŸããããã¯ãããšãã°ããããã¡ã€ãªã³ã°äžã«åãåã£ãæéã€ã³ãžã±ãŒã¿ãŒã«åºã¥ããŠãå ã®100åã«ãªããŸãã ãŸãã1ã€ã®ãªããžã§ã¯ãã®ããŒã¿ãµã€ãºã倧ãããªããšãèªã¿åãããã³æžã蟌ã¿æäœã®å¹çãåäžãããšæ³å®ããŠããŸãã
å³12
ã¢ããªã±ãŒã·ã§ã³ãåã³ã³ãã€ã«ããã¿ã¹ã¯åæã䜿çšããŠå床ãããã¡ã€ã«ããŸãïŒå³13ïŒã Do Squareãµãã¿ã¹ã¯ã¯çŽ10ããªç§ã§å®è¡ãããããã«ãªããŸããïŒã¿ã¹ã¯ã®ç»åã«ã«ãŒãœã«ãåãããŠæ°å€ç¹æ§ãååŸããŸãïŒã ãŸãããµãã¿ã¹ã¯éã«ãã®ã£ããããå®è³ªçã«ãªããããã¹ã¬ãããé·æéããžãŒã«ãªããŸãã ãŸããTBBã¹ã±ãžã¥ãŒã©ããæžã蟌ã¿ãã§ãŒãºãªã©ã®åãã ãçããµãã¿ã¹ã¯ãé 眮ããããããããé·ããã¥ãŒã«æ¥ç¶ããåãã¹ã¬ããã§å®è¡ãããããã«å²ãåœãŠãããšã§ãè¿œå ã®åæã®ã³ã¹ããåæžããæ¹æ³ã«æ°ä»ãããšãã§ããŸãã
å³13
ãŸããããã°ã©ã å šäœã®å®å šãªäžŠåæ§ã確èªããããšãèå³æ·±ãã§ãããã å³14ãããããããã«ãã¢ããªã±ãŒã·ã§ã³ã¯äž»ã«3ã¹ã¬ãããŸãã¯4ã¹ã¬ããã§å®è¡ãããŸãããããã¯ãæåã®çµæãšæ¯èŒããŠå€§ããªææã§ãã åæå®è¡ã¬ãã«ã®å¹³åå€ãæ¯èŒããããšãã§ããŸããã䞊ååããŠããªãéšåãå«ããŠãã¢ããªã±ãŒã·ã§ã³ã®ã·ãŒã±ã³ã·ã£ã«éšåã«åœ±é¿ããããšãèŠããŠããå¿ èŠããããŸãã
ã¯ããããã°ã©ã ã®ã·ãªã¢ã«éšåã¯æ®ããŸããã1/3æžå°ããŸããã ã¿ã€ã ã©ã€ã³ãã¥ãŒã®çµæã«ã衚瀺ãããŸãã ãã®é£ç¶éšåãéžæãããæ®ãã®æéã§é€å€ãããå Žåãã¡ã€ã³ã¹ã¬ããã®ã¢ããªã±ãŒã·ã§ã³å šäœã®åæåãã§ãŒãºã«å¯Ÿå¿ããããšãããããŸãã ã©ã®éšåããã€ãã©ã€ã³ã®æäœã«å¯Ÿå¿ããåæåã«é¢é£ããŠããªãããæ£ç¢ºã«å€æãããå Žåããããã¡ã€ãªã³ã°ãå¶åŸ¡ãããŠãŒã¶ãŒAPIé¢æ°ã䜿çšã§ããŸã-ãã€ãã©ã€ã³ãäœæããçŽåã«ã³ã¬ã¯ã·ã§ã³ãéå§ããäœæ¥ãå®äºããåŸã«ã³ã¬ã¯ã·ã§ã³ãçµäºããŸãã
å³14
å®è£ å¹çãæ¹åããããã®æšå®ã¢ã€ãã¢ãæäŸããã°ã©ãã«å ããŠãã¢ããªã±ãŒã·ã§ã³ã®æ°å€ããã©ãŒãã³ã¹ææšã調ã¹ãŠæ¯èŒã§ããŸãã VTune Amplifierã®ãã¹ãŠã®çµæã¯ãé©åãªæ¯èŒæ©èœã䜿çšããŠæ¯èŒã§ããŸãã æåã®ãããã¹ãããåæã®çµæãšãã³ãŒããå€æŽããåŸã«åŸãããçµæã®å¯Ÿå¿é¢ä¿ãããããç解ããããã«ãåçŽã«2ã€ã®ç»åã䞊ã¹ãŠè¡šç€ºããŸãïŒå³15ïŒã èå³æ·±ãããšã«ãããã°ã©ã ã®å®è¡æéïŒElapsed TimeïŒã¯æžå°ããŸããããé¢æ°MyProcessFilter :: operatorïŒïŒã§è²»ããããæéã¯å€æŽãããŠããŸãããããã¯ãç·äœæ¥éãå€æŽãããåã«åé åžããããã§ãã åæã«ãTBBã¿ã¹ã¯ãã©ã³ãã³ã°ã®ã³ã¹ããå€§å¹ ã«åæžãããŸããã ããã«ãããã¹ãã®å€§ããªã»ã¯ã·ã§ã³ã§ã®äœæ¥ãããå¹ççã«ãªããããããŒã¿ã®èªã¿åããšæžã蟌ã¿ã®åèšæéãæããã«æžå°ããŸããã
å³15
ãããã«
ããŒã¿ãšã¿ã¹ã¯ã«å¿ããå解ã¯ãã¢ã«ãŽãªãºã ã®äžŠååã«å¹æçã«äœ¿çšãããŸãã ã¢ã«ãŽãªãºã ã®äžéšã®ã¯ã©ã¹ã¯ãé 次å®è¡ãã§ãŒãºãšäžŠåå®è¡ãã§ãŒãºã®ãã€ãã©ã€ã³æè¡ã䜿çšããŠæ¹åã§ããŸãã ã€ã³ãã«Â®TBBã©ã€ãã©ãªãŒã¯ãã¢ã«ãŽãªãºã ã®ãã€ãã©ã€ã³åã®å®è£ ã«ãããæéãå€§å¹ ã«åæžãããšåæã«ãã·ã¹ãã ã§å©çšå¯èœãªã¹ã¬ããã§ã¿ã¹ã¯ã®ã¹ã±ãžã¥ãŒãªã³ã°ãšå®è¡ã®ãã©ã³ã¹ããšãã¿ã¹ã¯ãåŒãåããŸãã ã¢ã«ãŽãªãºã ã®ãã§ãŒãºã«åºã¥ããã¿ã¹ã¯ã®åœ¢æã¯ãå®è£ ãããŠããã¢ã«ãŽãªãºã ã®è€éãã«å¿ããŠéèŠãªã¿ã¹ã¯ã«ãªãå¯èœæ§ããããã¿ã¹ã¯ã®å®è¡ã®ç®¡çã¯ããã«å°é£ã«ãªãå¯èœæ§ããããŸãã VTune Amplifierã®ã¿ã¹ã¯åæããŒã«ãããã䜿çšãããšãéçºè ã¯ãã«ãã¹ã¬ããç°å¢ã§ã®ã¿ã¹ã¯ã®å®è¡ã䟿å©ãªã°ã©ãã£ã«ã«åœ¢åŒã§èŠèŠåã§ãããããåæå¹çãåäžããã¢ããªã±ãŒã·ã§ã³éçºæéãå€§å¹ ã«ççž®ãããŸãã