å®éãã¡ã¢ãªã·ã¹ãã ã¯ã容éãã³ã¹ããã¢ã¯ã»ã¹æéãç°ãªãã¹ãã¬ãŒãžããã€ã¹ã®éå±€ã圢æããŸã ã ããã»ããµã¬ãžã¹ã¿ã«ã¯ãæãäžè¬çã«äœ¿çšãããããŒã¿ãæ ŒçŽãããŸãã ããã»ããµã®è¿ãã«ããå°ããªé«éãã£ãã·ã¥ã¯ãæ¯èŒçäœéã®RAMã«ããããŒã¿ã®äžéšãæ ŒçŽãããããã¡ãŸãŒã³ãšããŠæ©èœããŸãã RAMã¯ãäœéã®ããŒã«ã«ãã©ã€ãã®ãããã¡ãŒãšããŠæ©èœããŸãã ãŸããããŒã«ã«ãã©ã€ãã¯ããããã¯ãŒã¯ã§æ¥ç¶ããããªã¢ãŒããã·ã³ããã®ããŒã¿ã®ãããã¡ãŒãšããŠæ©èœããŸãã
ããæžãããããã°ã©ã ã¯ãäžäœã¬ãã«ã®ã¹ãã¢ãããç¹å®ã¬ãã«ã®ã¹ãã¢ã«é »ç¹ã«ã¢ã¯ã»ã¹ããåŸåããããããã¡ã¢ãªéå±€ãæ©èœããŸãã ãããã£ãŠãäœã¬ãã«ã®ã¹ãã¬ãŒãžã¯ãããé ãã倧ãããå®äŸ¡ã«ãªããŸãã ãã®çµæã倧éã®ã¡ã¢ãªãååŸããŸããããã¯ãéå±€ã®æäžéšã§ã¹ãã¬ãŒãžã®ã³ã¹ããããããŸãããéå±€ã®æäžéšã§é«éã¹ãã¬ãŒãžã®é床ã§ããã°ã©ã ã«ããŒã¿ãé ä¿¡ããŸãã
ããã°ã©ããŒãšããŠã¯ãã¡ã¢ãªãŒã®éå±€ãç解ããå¿ èŠããããŸããããã¯ãããã°ã©ã ã®ããã©ãŒãã³ã¹ã«å€§ãã圱é¿ããããã§ãã ã·ã¹ãã ãããŒã¿ãéå±€å ã§äžäžã«ç§»åããæ¹æ³ãç解ããŠããå Žåãããã»ããµãããŒã¿ã«é«éã«ã¢ã¯ã»ã¹ã§ããããã«ãããŒã¿ãéå±€ã®äžäœã«é 眮ããããã°ã©ã ãäœæã§ããŸãã
ãã®èšäºã§ã¯ãã¹ãã¬ãŒãžããã€ã¹ãéå±€æ§é ã§ã©ã®ããã«ç·šæãããŠãããã説æããŸãã ç¹ã«ãããã»ããµãšRAMã®éã®ãããã¡ãŸãŒã³ãšããŠæ©èœãããã£ãã·ã¥ã¡ã¢ãªã«éäžããŸãã ããã°ã©ã ã®ããã©ãŒãã³ã¹ã«æã倧ããªåœ±é¿ãäžããŸãã ããŒã«ãªãã£ã®éèŠãªæŠå¿µã玹ä»ãã ããŒã«ãªãã£ã®ããã°ã©ã ãåæããæ¹æ³ãåŠã³ããŸããããã°ã©ã ã®ããŒã«ãªãã£ãé«ããã®ã«åœ¹ç«ã€ãã¯ããã¯ãåŠã³ãŸãã
ãã®èšäºã¯ãã ã³ã³ãã¥ãŒã¿ãŒã·ã¹ãã ïŒããã°ã©ããŒã®èŠç¹ãã®ç¬¬6ç« ã«è§ŠçºãããŸããã ãã®ã·ãªãŒãºã®å¥ã®èšäºãã³ãŒãã®æé©åïŒããã»ããµãã§ã¯ ãããã»ããµãµã€ã¯ã«ã«ã€ããŠãæŠããŸãã
èšæ¶ãéèŠ
è¡åã®èŠçŽ ãèŠçŽãã2ã€ã®é¢æ°ãèããŸãã ãããã¯ã»ãšãã©åãã§ããæåã®é¢æ°ã®ã¿ãè¡åã®èŠçŽ ãè¡ããšã«ãã€ãã¹ãã2çªç®ã®é¢æ°ã¯ååäœã§ãã€ãã¹ããŸãã
int matrixsum1(int size, int M[][size]) { int sum = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { sum += M[i][j]; // } } return sum; } int matrixsum2(int size, int M[][size]) { int sum = 0; for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { sum += M[j][i]; // } } return sum; }
äž¡æ¹ã®æ©èœã¯ãåãæ°ã®ããã»ããµåœä»€ãå®è¡ããŸãã ãã ãã Core i7 HaswellãæèŒãããã·ã³ã§ã¯ãæåã®é¢æ°ã¯å€§ããªè¡åã«å¯ŸããŠ25åé«éã§ãã ãã®äŸã¯ã ã¡ã¢ãªãéèŠã§ããããšããã瀺ããŠããŸã ã å®è¡ããåœä»€ã®æ°ã«é¢ããŠã®ã¿ããã°ã©ã ã®æå¹æ§ãè©äŸ¡ããå Žåãéåžžã«é ãããã°ã©ã ãäœæã§ããŸãã
ããŒã¿ã«ã¯ã localityãšåŒã°ããéèŠãªããããã£ããããŸãã ããŒã¿ã«åãçµãã§ãããšããããããè¿ãã®ã¡ã¢ãªã«ããããšãæãŸããã§ãã è¡åãè¡ããšã«ã¡ã¢ãªã«ä¿åããããããåããšã«è¡åããã€ãã¹ãããšå±ææ§ãäœäžããŸãã 以äžã«å°åæ§ã«ã€ããŠèª¬æããŸãã
èšæ¶ã®éå±€
ææ°ã®ã¡ã¢ãªã·ã¹ãã ã¯ãé«éã®å°ããªã¿ã€ãã®ã¡ã¢ãªããäœéã®å€§ããªã¿ã€ãã®ã¡ã¢ãªãŸã§ã®éå±€ã圢æããŸãã ç¹å®ã®éå±€ã¬ãã«ã¯ãããäœãã¬ãã«ã«ããããŒã¿ã®ãã£ãã·ã¥ãŸãã¯ãã£ãã·ã¥ã§ãã ããã¯ãäžäœã¬ãã«ã®ããŒã¿ã®ã³ããŒãå«ãŸããããšãæå³ããŸãã ããã»ããµãããŒã¿ãåä¿¡ããå Žåãæåã«æé«éã§æ€çŽ¢ããŸãã ãããŠããããèŠã€ãããªãå Žåã¯ãäžäœã®ãã®ã«äžãããŸãã
éå±€ã®æäžéšã«ã¯ããã»ããµã¬ãžã¹ã¿ããããŸãã ããããžã®ã¢ã¯ã»ã¹ã«ã¯0ã®æ段ãå¿ èŠã§ããããããã®æ°ã¯ãããã§ãã 次ã«ãæ°ãããã€ãã®ç¬¬1ã¬ãã«ã®ãã£ãã·ã¥ããããã¢ã¯ã»ã¹ã«ã¯çŽ4ã¯ããã¯ãµã€ã¯ã«ããããŸãã ãã®åŸãæ°çŸãããã€ãã®äœéãªã»ã«ã³ãã¬ãã«ãã£ãã·ã¥ãè¿œå ãããŸãã 次ã«ãæ°ã¡ã¬ãã€ãã®L3ãã£ãã·ã¥ã ããã¯ãã£ãšé ãã§ãããããã§ãRAMããéãã§ãã 次ã¯æ¯èŒçé ãRAMã§ãã
RAMã¯ãããŒã«ã«ãã£ã¹ã¯ã®ãã£ãã·ã¥ãšèŠãªãããšãã§ããŸãã ãã£ã¹ã¯ã¯ã¹ãã¬ãŒãžããã€ã¹ã®äž»å補åã§ãã ãããã¯å€§ãããé ããå®äŸ¡ã§ãã ã³ã³ãã¥ãŒã¿ãŒã¯ããã¡ã€ã«ãåŠçãããšãã«ããã£ã¹ã¯ããRAMã«ãã¡ã€ã«ãããŒãããŸãã RAMãšãã©ã€ãéã®ã¢ã¯ã»ã¹æéã®ã®ã£ããã¯èšå€§ã§ãã ãã©ã€ãã¯RAMãããæ°äžåé ããäžæ¬¡ãã£ãã·ã¥ãããæ°çŸåé ãã§ãã ãã£ã¹ã¯ã1å䜿çšãããããRAMãæ°åå䜿çšããæ¹ãæå©ã§ãã ãã®ç¥èã¯ã BããªãŒãªã©ã®ããŒã¿æ§é ã«åºã¥ããŠããŸããBããªãŒã¯ ãRAMã«ããå€ãã®æ å ±ãé 眮ãããã£ã¹ã¯ãžã®ã¢ã¯ã»ã¹ãäžååé¿ããããšããŸãã
ããŒã«ã«ãã£ã¹ã¯èªäœã¯ããªã¢ãŒããµãŒããŒã«ããããŒã¿ã®ãã£ãã·ã¥ãšèŠãªãããšãã§ããŸãã ãŠã§ããµã€ãã«ã¢ã¯ã»ã¹ãããšããã©ãŠã¶ã¯ãŠã§ãããŒãžã®ç»åããã£ã¹ã¯ã«ä¿åãããããå床ã¢ã¯ã»ã¹ãããšãã«ããŠã³ããŒãããå¿ èŠã¯ãããŸããã ã¡ã¢ãªã®äžäœéå±€ããããŸãã Googleãªã©ã®å€§èŠæš¡ãªããŒã¿ã»ã³ã¿ãŒã§ã¯ã倧éã®ããŒã¿ãããŒãã«ä¿åããŸãããããã®ããŒã¿ã¯å庫ã®ã©ããã«ä¿åãããå¿ èŠã«å¿ããŠæåãŸãã¯ããããã§æ¥ç¶ããå¿ èŠããããŸãã
ææ°ã®ã·ã¹ãã ã«ã¯ãã»ãŒæ¬¡ã®ç¹æ§ããããŸãã
ãã£ãã·ã¥ã¿ã€ã | ã¢ã¯ã»ã¹æéïŒãã£ãã¯ïŒ | ãã£ãã·ã¥ãµã€ãº |
---|---|---|
ç»é² | 0 | æ°åå |
L1ãã£ãã·ã¥ | 4 | 32 KB |
L2ãã£ãã·ã¥ | 10 | 256 KB |
L3ãã£ãã·ã¥ | 50 | 8 MB |
RAM | 200 | 8 GB |
ãã£ã¹ã¯ãããã¡ | 100'000 | 64 MB |
ããŒã«ã«ãã£ã¹ã¯ | 10'000'000 | 1000 GB |
ãªã¢ãŒããµãŒã㌠| 1'000'000'000 | â |
é«éã¡ã¢ãªã¯éåžžã«é«äŸ¡ã§ãããäœéã¡ã¢ãªã¯éåžžã«å®äŸ¡ã§ãã ã·ã¹ãã èšèšè ã«ãšã£ãŠãäœéã§å®äŸ¡ãªã¡ã¢ãªã®å€§ããªãµã€ãºãšé«éã§é«äŸ¡ãªå°ããªãµã€ãºãçµã¿åãããã®ã¯çŽ æŽãããã¢ã€ãã¢ã§ãã ãããã£ãŠãã·ã¹ãã ã¯é«éã®ã¡ã¢ãªé床ã§å®è¡ã§ããã³ã¹ããããããŸãã ãããã©ã®ããã«æ©èœããããèŠãŠã¿ãŸãããã
ã³ã³ãã¥ãŒã¿ãŒã«8 GBã®RAMãš1000 GBã®ãã£ã¹ã¯ããããšããŸãã ãã ãããã£ã¹ã¯äžã®ãã¹ãŠã®ããŒã¿ãäžåºŠã«åŠçããŠããããã§ã¯ãªããšèããŠãã ããã ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãããŒãããWebãã©ãŠã¶ãŒãããã¹ããšãã£ã¿ãŒãä»ã®ããã€ãã®ã¢ããªã±ãŒã·ã§ã³ãéããŠãæ°æéããããæäœããŸãã ãããã®ã¢ããªã±ãŒã·ã§ã³ã¯ãã¹ãŠRAMã«é 眮ããããããã·ã¹ãã ããã£ã¹ã¯ã«ã¢ã¯ã»ã¹ããå¿ èŠã¯ãããŸããã 次ã«ããã¡ããã1ã€ã®ã¢ããªã±ãŒã·ã§ã³ãéããŠããå¥ã®ã¢ããªã±ãŒã·ã§ã³ãéããŸããããããã£ã¹ã¯ããRAMã«ããŒãããå¿ èŠããããŸãã ãã ããæ°ç§ãããããã®åŸããã£ã¹ã¯ã«ã¢ã¯ã»ã¹ããã«ãã®ã¢ããªã±ãŒã·ã§ã³ãæ°æé䜿çšããŸãã äžæçã«RAMã«ãã£ãã·ã¥ãããŠããå°éã®ããŒã¿ã®ã¿ã§äœæ¥ããŠãããããå®éã«é ããã£ã¹ã¯ã«æ°ä»ãããšã¯ãããŸããã ãã£ã¹ã¯å šäœã®å 容ãããŒãã§ãã1024 GBã®RAMã®ã€ã³ã¹ããŒã«ã«å€é¡ã®è²»çšããããå¿ èŠã¯ãããŸããã ãããè¡ã£ãå Žåãä»äºã®éãã«ã»ãšãã©æ°ä»ããªãã§ããããããã¯ããéãç¡é§é£ããããã§ãããã
ããã¯ãå°ããªããã»ããµãã£ãã·ã¥ã®å Žåã«ãåœãŠã¯ãŸããŸãã intåã®1000åã®èŠçŽ ãå«ãé åã§èšç®ãå®è¡ããå¿ èŠããããšããŸãã ãã®ãããªã¢ã¬ã€ã¯4 KBãå æãã32 KBã®ç¬¬1ã¬ãã«ãã£ãã·ã¥ã«å®å šã«åãŸããŸãã ã·ã¹ãã ã¯ãç¹å®ã®RAMã§äœæ¥ãéå§ããããšãç解ããŠããŸãã ãã®ããŒã¹ããã£ãã·ã¥ã«ã³ããŒããããã»ããµãŒã¯ãã®ã¢ã¬ã€ã§æäœããã°ããå®è¡ãããã£ãã·ã¥ã®é床ã享åããŸãã 次ã«ããã£ãã·ã¥ããå€æŽãããé åãRAMã«ã³ããŒãããŸãã ãã£ãã·ã¥ã®é床ãäžããããã«RAMã®é床ãäžããŠããç®ã«èŠããããã©ãŒãã³ã¹ã®åäžã¯åŸãããŸããããã·ã¹ãã ã®ã³ã¹ãã¯æ°çŸãæ°ååã«ãªããŸãã ããããããããã¹ãŠã¯ãããã°ã©ã ã®ããŒã«ãªãã£ãè¯å¥œãªå Žåã«ã®ã¿åœãŠã¯ãŸããŸãã
å±ææ§
å±ææ§ã¯ããã®èšäºã®åºæ¬æŠå¿µã§ãã ååãšããŠãããŒã«ãªãã£ãè¯å¥œãªããã°ã©ã ã¯ãããŒã«ãªãã£ãäœãããã°ã©ã ãããéãå®è¡ãããŸãã å±ææ§ã«ã¯2ã€ã®ã¿ã€ãããããŸãã ã¡ã¢ãªå ã®åãå Žæã«äœåºŠãã¢ã¯ã»ã¹ãããšãããã¯äžæçãªå Žæã«ãªããŸãã ããŒã¿ã«ã¢ã¯ã»ã¹ããå ã®ã¡ã¢ãªã®é£ã«ããä»ã®ããŒã¿ãåç §ããå Žåãããã¯ç©ºéçå±ææ§ã§ã ã
é åã®èŠçŽ ãåèšããããã°ã©ã ãèããŠã¿ãŸãããã
int sum(int size, int A[]) { int i, sum = 0; for (i = 0; i < size; i++) sum += A[i]; return sum; }
ãã®ããã°ã©ã ã§ã¯ãã«ãŒãã®åå埩ã§sumããã³iå€æ°ã«ã¢ã¯ã»ã¹ããŸãã ãããã¯è¯å¥œãªæéçå±ææ§ãæã¡ãé«éããã»ããµã¬ãžã¹ã¿ã«é 眮ãããŸãã é åAã®èŠçŽ ã¯ãåèŠçŽ ã«1åããã¢ã¯ã»ã¹ããªããããæéçãªå±ææ§ãäžååã§ãã ãããããã®åŸã圌ãã¯è¯ã空éçå±ææ§ãæã£ãŠããŸã-1ã€ã®èŠçŽ ã«è§ŠããåŸããã®é£ã®èŠçŽ ã«è§ŠããŸãã ãã®ããã°ã©ã ã®ãã¹ãŠã®ããŒã¿ã¯ãè¯å¥œãªæéçå±ææ§ãŸãã¯è¯å¥œãªç©ºéçå±ææ§ãæã£ãŠãããããããã°ã©ã ã¯äžè¬çã«è¯å¥œãªå±ææ§ãæã£ãŠãããšèšããŸãã
ããã»ããµãã¡ã¢ãªããããŒã¿ãèªã¿åããšãããã£ãã·ã¥ããä»ã®ããŒã¿ãåé€ããªããããã£ãã·ã¥ã«ããŒã¿ãã³ããŒããŸãã 圌ããããã¯ãåé€ããããã«éžæããããŒã¿ã¯è€éã§ãã ãããããã®çµæãäžéšã®ããŒã¿ã«é »ç¹ã«ã¢ã¯ã»ã¹ãããšããã£ãã·ã¥ã«æ®ãå¯èœæ§ãé«ããªããŸãã ããã¯ãæéçå±ææ§ã®å©ç¹ã§ãã ããã°ã©ã ã¯ãããå°ãªãå€æ°ã§äœæ¥ããããé »ç¹ã«ã¢ã¯ã»ã¹ããæ¹ãé©åã§ãã
éå±€ã¬ãã«éã®ããŒã¿ç§»åã¯ãç¹å®ã®ãµã€ãºã®ãããã¯ã«ãã£ãŠå®è¡ãããŸãã ããšãã°ã Core i7 Haswellããã»ããµã¯ã64ãã€ãã®ãããã¯ã§ãã£ãã·ã¥éã§ããŒã¿ã移åããŸãã ç¹å®ã®äŸãèããŠã¿ãŸãããã äžèšã®ããã»ããµãæèŒãããã·ã³ã§ããã°ã©ã ãå®è¡ããŸãã longåã®8ãã€ãèŠçŽ ãå«ãvé åããããŸãã ãããŠããã®é åã®èŠçŽ ãã«ãŒãã§é çªã«ã«ãŒãããŸãã v [0]ãèªã¿åããšãããã£ãã·ã¥ã«ã¯ãããŸãããããã»ããµã¯ãRAMãã64ãã€ãã®ãããã¯ã§ãã£ãã·ã¥ã«èªã¿åããŸãã ã€ãŸããèŠçŽ v [0] -v [7]ããã£ãã·ã¥ã«éä¿¡ãããŸãã 次ã«ãèŠçŽ v [1] ã v [2] ã...ã v [7]ãå·¡åããŸãã ãããã¯ãã¹ãŠãã£ãã·ã¥å ã«ãããããã«ã¢ã¯ã»ã¹ã§ããŸãã 次ã«ããã£ãã·ã¥ã«ãªãèŠçŽ v [8]ãèªã¿åããŸãã ããã»ããµã¯ãèŠçŽ v [8] -v [15]ããã£ãã·ã¥ã«ã³ããŒããŸãã ãããã®èŠçŽ ããã°ãã調ã¹ãŸããããã£ãã·ã¥å ã§vèŠçŽ ãèŠã€ããããšãã§ããŸãã[16] ã ãªã©ãªã©ã
ãããã£ãŠãã¡ã¢ãªããããã€ãã®ãã€ããèªã¿åãããããã®é£ã®ãã€ããèªã¿åãå Žåããããããã£ãã·ã¥ã«ãããŸãã ããã空éçå±ææ§ã®å©ç¹ã§ãã è¿ãã®ã¡ã¢ãªã«ããããŒã¿ãæäœããã«ã¯ãèšç®ã®å段éã§åªåããå¿ èŠããããŸãã
é åãé çªã«èµ°æ»ããèŠçŽ ã1ã€ãã€èªã¿åãããšããå§ãããŸãã ãããªãã¯ã¹ã®èŠçŽ ããã€ãã¹ããå¿ èŠãããå Žåã¯ãåã§ã¯ãªãè¡ããšã«ãããªãã¯ã¹ãèµ°æ»ããããšããå§ãããŸãã ããã«ããã空éçãªå±ææ§ãåäžããŸãã ããã§ã matrixsum2é¢æ°ãmatrixsum1é¢æ°ãããé ãçç±ãç解ã§ããŸãã 2次å é åã¯ãã¡ã¢ãªå ã®è¡ããšã«é 眮ãããŸããæåã®è¡ã¯æåã«é 眮ããã2çªç®ã®è¡ã®çŽåŸã«é 眮ãããŸãã æåã®é¢æ°ã¯ã1ã€ã®å€§ããª1次å é åããã€ãã¹ãããã®ããã«ãè¡åèŠçŽ ãè¡ããšã«èªã¿åããã¡ã¢ãªå ãé çªã«ç§»åããŸãã ãã®é¢æ°ã¯ãäž»ã«ãã£ãã·ã¥ããããŒã¿ãèªã¿åããŸãã 2çªç®ã®é¢æ°ã¯è¡ããè¡ãžãšé²ã¿ãäžåºŠã«1ã€ã®èŠçŽ ãèªã¿åããŸããã 圌女ã¯èšæ¶ããå·Šããå³ãžãžã£ã³ãããæåã«æ»ã£ãŠåã³å·Šããå³ãžãžã£ã³ããå§ããããã§ããã åå埩ã®çµäºæã«ãæåŸã®è¡ã§ãã£ãã·ã¥ãè©°ãŸã£ãããã次ã®å埩ã®éå§æã«ãã£ãã·ã¥ã¯æåã®è¡ãèŠã€ããããŸããã§ããã ãã®é¢æ°ã¯ãäž»ã«RAMããããŒã¿ãèªã¿åããŸãã
ãã£ãã·ã¥ãã¬ã³ããªãŒãªã³ãŒã
ããã°ã©ããŒãšããŠã ãã£ãã·ã¥ã« åªãããšèšãããŠããã³ãŒããæžãããã«ããŠãã ããã ååãšããŠã倧éšåã®èšç®ã¯ããã°ã©ã å ã®æ°ç®æã§ã®ã¿å®è¡ãããŸãã éåžžããããã¯ããã€ãã®éèŠãªæ©èœãšãµã€ã¯ã«ã§ãã ãã¹ããããã«ãŒããããå Žåãã³ãŒãã¯æãé »ç¹ã«å®è¡ããããããæãå åŽã®ã«ãŒãã«æ³šæãåããå¿ èŠããããŸãã ãããã®ããã°ã©ã ã®å Žæã¯ãå°åæ§ãæ¹åããããã«æé©åããå¿ èŠããããŸãã
ãããªãã¯ã¹èšç®ã¯ãä¿¡å·è§£æã¢ããªã±ãŒã·ã§ã³ããã³ç§åŠèšç®ã§éåžžã«éèŠã§ãã ããã°ã©ããŒã®ã¿ã¹ã¯ãè¡åä¹ç®é¢æ°ãäœæããããšã§ããå Žåã99.9ïŒ ã次ã®ããã«æžã蟌ã¿ãŸãã
void matrixmult1(int size, double A[][size], double B[][size], double C[][size]) { double sum; for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) { sum = 0.0; for (int k = 0; k < size; k++) sum += A[i][k]*B[k][j]; C[i][j] = sum; } }
ãã®ã³ãŒãã¯ãè¡åä¹ç®ã®æ°åŠçãªå®çŸ©ãéèªçã«ç¹°ãè¿ããŸãã æçµãããªãã¯ã¹ã®ãã¹ãŠã®èŠçŽ ãè¡ããšã«èª¿ã¹ãããããã1ã€ãã€èšç®ããŸãã ã³ãŒãã«ã¯1ã€ã®éå¹çæ§ããããŸããããã¯ãæãå åŽã®ã«ãŒãã®åŒB [k] [j]ã§ãã åã§è¡åBãå·¡åããŸãã ããã«ã€ããŠã¯äœãã§ããªãããã«æããã劥åããå¿ èŠããããŸãã ããããæ¹æ³ããããŸãã åãèšç®ãå¥ã®æ¹æ³ã§æžãæããããšãã§ããŸãã
void matrixmult2(int size, double A[][size], double B[][size], double C[][size]) { double r; for (int i = 0; i < size; i++) for (int k = 0; k < size; k++) { r = A[i][k]; for (int j = 0; j < size; j++) C[i][j] += r*B[k][j]; } }
ãã®é¢æ°ã¯éåžžã«å¥åŠã«èŠããŸãã ãããã圌女ã¯ãŸã£ããåãããšãããŸãã æçµãããªãã¯ã¹ã®åèŠçŽ ãäžåºŠã«èšç®ããã®ã§ã¯ãªããåå埩ã§éšåçã«èŠçŽ ãèšç®ããããã§ãã ãããããã®ã³ãŒãã®éèŠãªç¹æ§ã¯ãå åŽã®ã«ãŒãã§äž¡æ¹ã®è¡åãè¡ããšã«ã«ãŒãããããšã§ãã Core i7 HaswellãæèŒãããã·ã³ã§ã¯ã 2çªç®ã®é¢æ°ã¯å€§ããªãããªãã¯ã¹ã«å¯ŸããŠ12åé«éã«åäœããŸãã ãã®ããã«ã³ãŒããæŽçããã«ã¯ãæ¬åœã«è³¢æãªããã°ã©ããŒã§ããå¿ èŠããããŸãã
ããããã³ã°
ããããã³ã°ãšåŒã°ãããã¯ããã¯ããããŸãã ãã¹ãŠãé«ã¬ãã«ã®ãã£ãã·ã¥ã«åãŸããªã倧éã®ããŒã¿ã«å¯ŸããŠèšç®ãå®è¡ããå¿ èŠããããšããŸãã ãã®ããŒã¿ãå°ããªãããã¯ã«åå²ããåãããã¯ããã£ãã·ã¥ããŸãã ãããã®ãããã¯ã«å¯ŸããŠåå¥ã«èšç®ãå®è¡ããçµæãçµã¿åãããŸãã
ãããäŸã§ç€ºãããšãã§ããŸãã é£æ¥è¡åãšããŠè¡šãããæåã°ã©ãããããšããŸãã ããã¯ãŒããš1ã®æ£æ¹è¡åã§ãããããã€ã³ããã¯ã¹ïŒiãjïŒã®è¡åèŠçŽ ã1ã«çããå Žåãã°ã©ãiã®é ç¹ããé ç¹jãŸã§ã®é¢ããããŸãã ãã®æåã°ã©ããéæåã°ã©ãã«å€ããããšæããŸãã ã€ãŸããé¢ïŒiãjïŒãããå Žåãå察åŽã®é¢ïŒjãiïŒã衚瀺ãããŸãã è¡åãèŠèŠåããå ŽåãèŠçŽ ïŒiãjïŒãšïŒjãiïŒã¯å¯Ÿè§ç·ã«é¢ããŠå¯Ÿç§°ã§ããããšã«æ³šæããŠãã ããã ãã®å€æã¯ãã³ãŒãã«ç°¡åã«å®è£ ã§ããŸãã
void convert1(int size, int G[][size]) { for (int i = 0; i < size; i++) for (int j = 0; j < size; j++) G[i][j] = G[i][j] | G[j][i]; }
ããããã³ã°ã¯èªç¶ã«çŸããŸãã 倧ããªæ£æ¹è¡åãæ³åããŠãã ããã 次ã«ããã®è¡åãæ°Žå¹³ç·ãšåçŽç·ã§åãåããããšãã°16ã®çãããããã¯ïŒ4è¡4åïŒã«åå²ããŸãã ä»»æã®2ã€ã®å¯Ÿç§°ãããã¯ãéžæããŸãã ãããããã¯å ã®ãã¹ãŠã®èŠçŽ ã«ã¯ãå¥ã®ãããã¯å ã«ç¬èªã®å¯Ÿç§°èŠçŽ ãããããšã«æ³šæããŠãã ããã ããã¯ããããã®ãããã¯ã«å¯ŸããŠåãæäœãé çªã«å®è¡ã§ããããšã瀺åããŠããŸãã ãã®å Žåãå段éã§2ã€ã®ãããã¯ã®ã¿ã§äœæ¥ããŸãã ãããã¯ãååã«å°ãããããšãé«ã¬ãã«ã®ãã£ãã·ã¥ã«åãŸããŸãã ãã®ã¢ã€ãã¢ãã³ãŒãã§è¡šçŸããŠãã ããïŒ
void convert2(int size, int G[][size]) { int block_size = size / 12; // 12*12 // , for (int ii = 0; ii < size; ii += block_size) { for (int jj = 0; jj < size; jj += block_size) { int i_start = ii; // i [ii, ii + block_size) int i_end = ii + block_size; int j_start = jj; // j [jj, jj + block_size) int j_end = jj + block_size; // for (int i = i_start; i < i_end; i++) for (int j = j_start; j < j_end; j++) G[i][j] = G[i][j] | G[j][i]; } } }
ããããã³ã°ã¯ãåªããããªãã§ãããå®è¡ãã匷åãªããã»ããµãåããã·ã¹ãã ã®ããã©ãŒãã³ã¹ãæ¹åããªãããšã«æ³šæããŠãã ããã ããªãã§ããããªãã·ã¹ãã ã§ã¯ãããããã³ã°ã«ããããã©ãŒãã³ã¹ãå€§å¹ ã«åäžããŸãã
Core i7 Haswellããã»ããµãæèŒãããã·ã³ã§ã¯ã 2çªç®ã®æ©èœã¯é«éã§ã¯ãããŸããã ããåçŽãªPentium 2117Uããã»ããµãæèŒãããã·ã³ã§ã¯ã 2çªç®ã®æ©èœã¯2åé«éã§ãã ããªãã§ããããªããã·ã³ã§ã¯ãçç£æ§ãããã«åäžããŸãã
ããé«éãªã¢ã«ãŽãªãºã
ã¢ã«ãŽãªãºã ã®ã³ãŒã¹ããã¯ã誰ããæå°ã®è€éãã§è¯ãã¢ã«ãŽãªãºã ãéžæããé«ãè€éãã§æªãã¢ã«ãŽãªãºã ãé¿ããå¿ èŠãããããšãç¥ã£ãŠããŸãã ãããããããã®å°é£ã¯ãç§ãã¡ã®èãã«ãã£ãŠäœæãããçè«çãªãã·ã³ã§ã®ã¢ã«ãŽãªãºã ã®å®è¡ãè©äŸ¡ããŸãã å®éã®ãã·ã³ã§ã¯ãçè«çã«æªãã¢ã«ãŽãªãºã ã¯ãçè«çã«è¯ãã¢ã«ãŽãªãºã ãããéãå®è¡ã§ããŸãã RAMããã®ããŒã¿ã®ååŸã«ã¯200ãµã€ã¯ã«ããããæåã®ã¬ãã«ã®ãã£ãã·ã¥ããã¯4ãµã€ã¯ã«-50åé«éã§ããããšãæãåºããŠãã ããã è¯ãã¢ã«ãŽãªãºã ãã¡ã¢ãªã«é »ç¹ã«ã¢ã¯ã»ã¹ããæªãã¢ã«ãŽãªãºã ããã£ãã·ã¥ã«ããŒã¿ãé 眮ããå Žåãè¯ãã¢ã«ãŽãªãºã ã¯æªãã¢ã«ãŽãªãºã ãããå®è¡é床ãé ããªããŸãã ãŸããè¯ãã¢ã«ãŽãªãºã ã¯ãæªãã¢ã«ãŽãªãºã ãããããã»ããµãŒäžã§åäœãæªãå ŽåããããŸãã ããšãã°ãåªããã¢ã«ãŽãªãºã ã¯ããŒã¿ã«äŸåããããã»ããµãã€ãã©ã€ã³ãããŒãã§ããŸããã ãããŠãæªãã¢ã«ãŽãªãºã ã¯ãã®åé¡ã奪ãããåãµã€ã¯ã«ã§ãã€ãã©ã€ã³ã«æ°ããåœä»€ãéããŸãã ã€ãŸããã¢ã«ãŽãªãºã ã®è€éãã ãã§ã¯ãããŸããã ç¹å®ã®ããŒã¿ã䜿çšããŠç¹å®ã®ãã·ã³ã§ã¢ã«ãŽãªãºã ãå®è¡ããæ¹æ³ãéèŠã§ãã
æŽæ°ã®ãã¥ãŒãå®è£ ããå¿ èŠããããæ°ããèŠçŽ ããã¥ãŒå ã®ä»»æã®äœçœ®ã«è¿œå ã§ãããšæ³åããŠãã ããã é åãšãªã³ã¯ãªã¹ãã®2ã€ã®å®è£ ããéžæããŸãã é åã®äžå€®ã«èŠçŽ ãè¿œå ããã«ã¯ãé åã®å³ååã«ã·ããããå¿ èŠããããŸãããããã«ã¯çŽç·çãªæéãããããŸãã ãªã¹ãã®äžå€®ã«ã¢ã€ãã ãè¿œå ããã«ã¯ããªã¹ããäžå€®ã«ç§»åããå¿ èŠããããŸããããããçŽç·çãªæéãããããŸãã 圌ãã¯åãå°é£ãæ±ããŠããã®ã§ããªã¹ããéžã¶æ¹ãè¯ããšæããŸãã ããã«ããªã¹ãã«ã¯1ã€ã®åªããããããã£ããããŸãã ãªã¹ãã¯å¶éãªãæ¡å€§ã§ããŸããé åããã£ã±ãã«ãªããšãé åãæ¡åŒµããå¿ èŠããããŸãã
äž¡æ¹ã®æ¹æ³ã§1000èŠçŽ ã®ãã¥ãŒãå®è£ ãããšããŸãã ãããŠããã¥ãŒã®äžå€®ã«èŠçŽ ãæ¿å ¥ããå¿ èŠããããŸãã ãªã¹ãã¢ã€ãã ã¯ã¡ã¢ãªå šäœã«ã©ã³ãã ã«æ£ãã°ã£ãŠããã®ã§ã500ã¢ã€ãã ããã€ãã¹ããã«ã¯ã500 * 200 = 100'000ã¡ãžã£ãŒãå¿ èŠã§ãã é åã¯ã¡ã¢ãªå ã«é çªã«é 眮ããããããäžæ¬¡ãã£ãã·ã¥ã®é床ã楜ããããšãã§ããŸãã ããã€ãã®æé©åã䜿çšããŠãèŠçŽ ããšã«1ã4ãµã€ã¯ã«ãè²»ãããŠãé åã®èŠçŽ ã移åã§ããŸãã æ倧500 * 4 = 2000ãµã€ã¯ã«ã§ã¢ã¬ã€ã®ååãã·ããããŸãã ããã¯50åé«éã§ãã
åã®äŸã§ãã¹ãŠã®è¿œå ããã¥ãŒã®å é ã«ããå Žåããªã³ã¯ãªã¹ãã䜿çšããå®è£ ã®æ¹ãå¹ççã§ãã è¿œå ã®äžéšããã¥ãŒã®äžå€®ã«ããå Žåãé åã®å®è£ ãããé©åãªéžæã«ãªãå¯èœæ§ããããŸãã äžéšã®æäœã«ã¯ã¿ã¯ããè²»ãããä»ã®æäœã«ã¯ã¿ã¯ããä¿åããŸãã ãããŠæçµçã«ã圌ãã¯åã£ããããããŸããã
ãããã«
ã¡ã¢ãªã·ã¹ãã ã¯ãéå±€ã®æäžéšã«å°ãããŠé«éãªããã€ã¹ãäžéšã«å€§ãããŠé ãããã€ã¹ãæã€ã¹ãã¬ãŒãžããã€ã¹ã®éå±€ãšããŠç·šæãããŸãã å±ææ§ã®è¯ãããã°ã©ã ã¯ãããã»ããµãã£ãã·ã¥ããã®ããŒã¿ãåŠçããŸãã ããŒã«ãªãã£ã®äœãããã°ã©ã ã¯ãæ¯èŒçé ãRAMã®ããŒã¿ãåŠçããŸãã
ã¡ã¢ãªãŒéå±€ã®æ§è³ªãç解ããŠããããã°ã©ããŒã¯ãããŒã¿ãéå±€å ã§å¯èœãªéãé«ãé 眮ããããã»ããµãŒããããããéãåä¿¡ããããã«ããã°ã©ã ãæ§æã§ããŸãã
ç¹ã«ã次ã®ææ³ãæšå¥šãããŸãã
- å åŽã®ãµã€ã¯ã«ã«æ³šæãåããŠãã ããã æ倧éã®èšç®ãšã¡ã¢ãªã¢ã¯ã»ã¹ãçºçããã®ã¯ããã§ãã
- ãªããžã§ã¯ããã¡ã¢ãªå ã«ããé çªã§é çªã«ã¡ã¢ãªããèªã¿åãããšã«ããã空éçãªå±ææ§ãæ倧åããŠãã ããã
- ããŒã¿ãªããžã§ã¯ããã¡ã¢ãªããèªã¿åã£ãåŸãã§ããéãé »ç¹ã«äœ¿çšããŠãäžæçãªå±ææ§ãæ倧åããŠãã ããã