C#ã§ã®SIMDã®å©ç¨æ¹æ³
æ¨æ¥ Visual Studio 2015 RC ããªãªã¼ã¹ããã¾ããã64ãããç°å¢ã§ã¯ RyuJIT ãæè¼ãããããã«éããªãã¾ãããC# ã®å®è¡é度ã¯ããªãéããªã£ã¦ããããããVisual C++ ã¨å¤§å·®ããªãããã«ããæãã¾ãã
ããã¦ããããªãé«éåã®ãããSIMD (SSE2) ã使ããããã«ãªãã¾ãããç»åå¦çé¢ä¿ã»ãã«ãã¡ãã£ã¢å¦çé¢ä¿ã§é«éåãåºæ¥ã¾ãã
SIMD é¢ä¿ãéçºä¸ã¯ä»æ§ãå°ããã¤å¤ãã£ã¦ãã¾ããããã RC ã§ãããããã§ç¢ºå®ãªã®ã§ããããã°ã°ã£ã¦åºã¦ããæ å ±ãéçºä¸ã®ä»æ§ã大åã®ãããè¦æ³¨æã§ãã
å ã«æ³¨æç¹
- ãã¤ã¯ãã½ãããå®é¨çã«æ¸ãã¦ãããµã³ãã«ã¯ãç¾å¨ã®ãã¼ã¸ã§ã³ã§ã¯åããªãç©ãããã¾ãã
- ç°å¢å¤æ° COMPLUS_AltJit ã¨ã COMPLUS_FeatureSIMD ãã¬ã¸ã¹ããªããã£ããã¨ãã¯ç¾å¨ã¯ä¸è¦ã§ãã
- Vector ã¯ã©ã¹ã public ã§ã¯ãªããªã£ãããããã¼ãã¦ã§ã¢ã¢ã¯ã»ã©ã¬ã¼ã·ã§ã³ãæå¹ã«ãªã£ã¦ãããåå¾ãã API ãéå ¬éã«ãªãã¾ããã
使ãæ¹
ããã¸ã§ã¯ãã®è¨å®ã¯ãããå¤æ´ãã¾ãã
- ã32ãããã®åªå ãã«ãã§ãã¯ãå¤ãã¾ãããããããªã㨠RyuJIT ã使ãããªãã®ã§ãããã
- ãã³ã¼ãã®æé©åãã«ãã§ãã¯ãå ¥ãã¾ãã
ã対象ã®ãã¬ã¼ã ã¯ã¼ã¯ã㯠.NET Framework 4.5 ã®ã¾ã¾ã§å¤§ä¸å¤«ã§ãããã ããé«éã«å®è¡ãããã«ã¯ .NET Framework 4.6 ãå¿ è¦ãªã¯ãã§ããVisual Studio 㯠2013 ã§ãè¡ããã®ã試ãã¦ãªãã§ãã
NuGet ããã±ã¼ã¸ããã¼ã¸ã£ã¼ã§ System.Numerics.Vectors ã追å ãã¾ãã
ã³ã¼ãã®æ¸ãæ¹
ã³ã¼ãã®æ¸ãæ¹ã¯ãããªæãã§ãã
var v1 = new Vector4(1, 2, 3, 4); var v2 = new Vector4(5, 6, 7, 8); var v3 = v1 + v2; Console.Out.WriteLine("v3 = {0}", v3);
ãã³ããã¼ã¯çµæ
足ãç®ã®ãã³ããã¼ã¯ã§ããVector4[1024] 㨠float[4096] ãæ¯è¼ãã¦ãã¾ããå®è¡æé㯠for ã«ã¼ãã®å¦çãå«ãã§ããã®ã§åç´ã«4åã«ã¯ãªãã¾ããã
ç°å¢ | å®è¡æé |
---|---|
Vector4[] (32ããã) | 1,418 |
float[] (32ããã) | 1,252 |
Vector4[] (64ããã) | 407 |
float[] (64ããã) | 874 |
ã32ãããã®åªå ãã«ãã§ãã¯ãä»ãããã©ããã§å¤§ããå®è¡æéãå¤ããã¾ããä¸è¨ãå ¨ã¦ãã³ã¼ãã®æé©åãã¯æå¹ã«ãªã£ã¦ãã¾ãã
ããã¥ã¡ã³ã
API ã®ãªãã¡ã¬ã³ã¹ã¯ããã§ãã https://msdn.microsoft.com/ja-jp/library/system.numerics(v=vs.111).aspx
åçè¨ç»æ³ã®åé¡ãæ©æ¢°çã«è§£ãæ¹æ³
æ å ±ãªãªã³ããã¯ã¨ããä¸é«çåãã®ç«¶æããã°ã©ãã³ã°ã®å¤§ä¼ãããã¾ããå½å äºé¸ã»é¸æã3åãããæå¾ã«ä¸ç大ä¼ãããã¾ããã¢ã«ã´ãªãºã ã®åé¡ãåºé¡ããã¾ããäºé¸ã®æ¯å¹´ã®ãã¿ã¼ã³ã¯å1, 2ã¯åé¡æãã³ã¼ãã«èµ·ãã ãã®åé¡ã§ãå3ã¯ã¢ã«ã´ãªãºã ã®åé¡ã ã£ãããä¸å¦åé¨çãªç®æ°ã®åé¡ã ã£ãããã¾ããå4ã¯ãã¤ãåçè¨ç»æ³ã®åé¡ãåºã¾ãã競æããã°ã©ãã³ã°ã§ã¯åçè¨ç»æ³ãä¸çªã®å ¥éã§ããããããã¹ã¿ã¼ãã©ã¤ã³ã§ããããã解ããªãã¨å§ã¾ãã¾ãããåçè¨ç»æ³ã®åé¡ãæ©æ¢°çã«è§£ããã®ããªã¨æãè²ã ã¨èããã®ã§ãããã§ããããªã®ã§ããã®ããã°è¨äºã«ã¾ã¨ãã¾ãã
åçè¨ç»æ³
åçè¨ç»æ³ã§ããããã¯ãä¸çªãã£ããæ¸ããã¦ããã®ããæ¸ç±ãã¢ã«ã´ãªãºã ã¤ã³ãããã¯ã·ã§ã³ã http://www.amazon.co.jp/dp/476490408X ã§ããåçè¨ç»æ³ã®ç« ã¯çèªã«å¤ããã¨æãã¾ãããåçè¨ç»æ³ãã¨ããè¨èã®å®ç¾©ã¯è¥å¹²äººã«ãã£ã¦ãã¬ãããã®ã§ãããã¢ã«ã´ãªãºã ã¤ã³ãããã¯ã·ã§ã³ã®å®ç¾©ã«å¾ãã¾ãã¨ã以ä¸ã®2ã¤ãè¡ãã¢ã«ã´ãªãºã ã®ç·ç§°ã§ãã
- é¨ååé¡ã解ãã¦ããã®è¨ç®çµæãå©ç¨ãã¦ãå ¨ä½åé¡ã解ãã
- é¨ååé¡ã®è¨ç®çµæãåå©ç¨ãã¦è¨ç®éãæ¸ãããã¡ã¢åã
ãªããããããã¦ã³ï¼å ¨ä½åé¡ã解ãã¦ããé¨ååé¡ã解ãï¼ã¨ããã ã¢ããï¼é¨ååé¡ã解ãã¦ããå ¨ä½åé¡ã解ãï¼ã¨ãã2ã¤ã®å®è£ æ¹æ³ãããã®ã§ãããããã¯ãããã¾ã§ãå®è£ æ¹æ³ã®è©±ã§ãããããããã¦ã³ãããã ã¢ããã«ç½®ãæããã®ã¯æ©æ¢°çãªä½æ¥ã§ãããæ¬ããã°è¨äºã§ã¯ããããã¦ã³ã§è¨äºãæ¸ãã¾ããããããã¦ã³ã¯ã¡ã¢åå帰ã¨ãå¼ã°ãã¾ãã
ããã¦ããã®ããã«å®ç¾©ã¯åºãã«ãããããããå®éã«åºé¡ãããã®ã¯ããã£ã¨çãç¯å²ã§åºé¡ããã¾ããåé¡æã¯ãã®ãã¿ã¼ã³ã°ããã§ãã
ãã«ã«ãåª(ãªã¹ã, N).filter(list -> åé¡æã®æ¡ä»¶ã«åããªã¹ããçµãè¾¼ã ).mapToInt(list -> list ãæ´æ°ã«å¤æ ).éç´é¢æ°()
ä¸è¨ãå«ãã以ä¸ãJava 8 風ã®æ¬ä¼¼ã³ã¼ãã使ãã¾ãããªãã1..3 ã¨ãã表è¨ã¯ [1, 2, 3] ã®ãªã¹ãã¨ãã表è¨ã§ããrangeClosed(1, 3) ã®äºã§ãããã¨ãè¨äºã®æ¸ããããã®é½åä¸ããªã¹ãã®æ·»ãå㯠1 ããå§ã¾ãã¨è¨ããã¨ã«ããã¦ãã ããã
ãã«ã«ãåªã®å®ç¾©ã¯ 直積集合 - Wikipedia ã«æ¸ãã¦ããã¾ãããä¾ãã°ããã«ã«ãåª(1..2, 3) == [ [1, 1, 1], [1, 1, 2], [1, 2, 1], [1, 2, 2], [2, 1, 1], [2, 1, 2], [2, 2, 1], [2, 2, 2] ] ã§ãããªã¹ãã®ãªã¹ãã§ãã
éç´é¢æ°ã¯ max(), min(), sum() ã®ã©ããã§ããå ´åã®æ°ãæ°ããåé¡ãè¯ãåºã¾ããããã®é㯠mapToInt(list -> 1).sum() ã«ããã¨ãçµ±ä¸çã«ãã®è¡¨è¨ã«ãªãã¾ãã
解æ³ã®æé
解æ³ã®æé ã¯ä»¥ä¸ã®éãã§ãã詳ããã¯å ·ä½ä¾ã§èª¬æãã¦ããã¾ãã
- ãªã¹ãæ«å°¾ k åãå®æ°åãã¾ãï¼k ã¯é常 1ã3 ã§ãï¼ãfilter å ã®å®æ°ãã¾ã¨ããmapToInt å ã®å®æ°ã¯éç´é¢æ°ã®å¤ã«åºãã¾ãã
- ã«ã¼ã1ã¤åã®ãªã¹ãæ«å°¾ k - 1 åãå®æ°åãã¾ãã
- 1 㨠2ãæ¯è¼ãã¦ãä»£å ¥ãã¾ãã
å®æ°åããã¨ããã®ã¯å ´ååããããã¨ããæå³ã§ãã以ä¸ãèªãã§ããã¨ãã®æå³ãåããã¨æãã¾ããã¾ããåºé¡ãã¿ã¼ã³ã¨ãã¦ãé¨ååé¡ã«åããéã¯ãN ã 1 㨠N - 1 ã«åããåé¡ã°ã£ããã§ãã
0-1ããããµãã¯åé¡
åçè¨ç»æ³ã®ä¸çªåºæ¬çãªåé¡ã¯ã0-1ããããµãã¯åé¡ã§ããããã®æ´¾çå½¢ã§åºé¡ããã¾ããåé¡æ㯠ナップサック問題 - Wikipedia ãèªãã§ãã ããããããæ¬ä¼¼ã³ã¼ãã«ãããã¨ä»¥ä¸ã®ããã«ãªãã¾ãã
çã(N) = ãã«ã«ãåª(0..1, N).filter(list -> (1..N).mapToInt(i -> c[i] * list[i]).sum() <= C ).mapToInt(list -> (1..N).mapToInt(i -> p[i] * list[i]).sum() ).max()
é å c ã p ã¯åé¡ããä¸ããããå®æ°é åã§ããN ã C ã int å®æ°ã
ã§ã¯ã解æ³ããã®åé¡ã§ã¯ããªã¹ãã®æ«å°¾1ã¤ãå®æ°åãã¾ããX = list[N] ã¨ç½®ãã¾ããããã¨ãããå¤å½¢ã§ãã¾ãã
f1(N, X) = ãã«ã«ãåª(0..1, N - 1).filter(list -> (1..(N - 1)).mapToInt(i -> c[i] * list[i]).sum() + c[N] * X <= C ).mapToInt(list -> (1..(N - 1)).mapToInt(i -> p[i] * list[i]).sum() + p[N] * X ).max()
ããã§ãc[N] * X ã p[N] * X ãå®æ°ã§ããfilter ã«ããã¦ãC ãå®æ°ãªã®ã§ãå¼ãç®ãã¦ä¸ã¤ã«ã¾ã¨ãã¾ããã¾ããmapToInt ã®æ¹ã¯ãå®æ°ã®è¶³ãç®ãéç´é¢æ°ã®å¤ã«åºããã¨ãã§ãã¾ãããã®æé ããæ¯åæ¯åè¡ããã¿ã¼ã³ã§ãããã®å¤å½¢ãè¡ãã¨ã以ä¸ã®ããã«ãªãã¾ãã
f1(N, X) = ãã«ã«ãåª(0..1, N - 1).filter(list -> (1..(N - 1)).mapToInt(i -> c[i] * list[i]).sum() <= C - c[N] * X ).mapToInt(list -> (1..(N - 1)).mapToInt(i -> p[i] * list[i]).sum() ).max() + p[N] * X
次ã«ãã«ã¼ãåæ°ãä¸ã¤æ¸ãããç©ãèãã¾ããä¸è¨ã§ããªã¹ãæ«å°¾ k åãå®æ°åããã¨ãã¯ããã¡ãã§ã¯ k - 1 åãå®æ°åããå¿ è¦ããã®ã§ãããããã§ã¯ãk = 1 ã ã£ãã®ã§ãä¸ã¤ãå®æ°åãã¾ããã k >= 2 ã®ä¾ã¯ãã®å ãå¥ãªåé¡ã§ããã¾ãã
çã(N - 1) = ãã«ã«ãåª(0..1, N - 1).filter(list -> (1..(N - 1)).mapToInt(i -> c[i] * list[i]).sum() <= C ).mapToInt(list -> (1..(N - 1)).mapToInt(i -> p[i] * list[i]).sum() ).max()
ã§ããã®2ã¤ã®æ¬ä¼¼ã³ã¼ããæ¯ã¹ãã¨ãã»ã¨ãã©åãå½¢ã§ããC 㨠C - c[N] * X ã®éããããã®ã§ããã®é¨åãå¤æ° y ã¨ç½®ãã¾ãã
f2(N - 1, y) = ãã«ã«ãåª(0..1, N - 1).filter(list -> (1..(N - 1)).mapToInt(i -> c[i] * list[i]).sum() <= y ).mapToInt(list -> (1..(N - 1)).mapToInt(i -> p[i] * list[i]).sum() ).max()
f1 ã®æ¹ããC ãå¼æ°ã«å ¥ãã¡ããã¾ãã
f1(N, X, C) = ãã«ã«ãåª(0..1, N - 1).filter(list -> (1..(N - 1)).mapToInt(i -> c[i] * list[i]).sum() <= C - c[N] * X ).mapToInt(list -> (1..(N - 1)).mapToInt(i -> p[i] * list[i]).sum() ).max() + p[N] * X
ããã¨ã
f1(N, X, C) = f2(N - 1, C - c[N] * X) + p[N] * X
ã«ãªãã¾ããã¾ããçã(N - 1) = f2(N - 1, C) ã¤ã¾ã çã(N) = f2(N, C) ã§ãã
ããã¦ãX = list[N] ã¯æ«å°¾1ã¤ãå®æ°åãã¦ä½ã£ãç©ãªã®ã§ã以ä¸ã®çå¼ãæç«ãã¾ãã
çã(N) = (0..1).mapToInt(x -> f1(N, x, C)).max()
ã¾ã¨ããã¨ã以ä¸ã®å¼ãã§ãã¾ããã
çã(N) = f2(N, C) = (0..1).mapToInt(x -> f1(N, x, C)).max() f1(N, x, C) = f2(N - 1, C - c[N] * x) + p[N] * x
ä¸ã®å¼ãä¸ã®å¼ã«ä»£å ¥ãã¦ã以ä¸ã®éãã§ãã
çã(N) = f2(N, C) = (0..1).mapToInt(x -> f2(N - 1, C - c[N] * x) + p[N] * x).max()
f2 ã® N ã1ãã¤æ¸ã£ã¦ããã«ã¼ãã«ãªã£ã¦ãã¾ãã
ãã ããã«ã¼ãã®æå¾ãf2(1, ?) ã¯ãçç¥ãã¦ãã¾ã£ãã®ã§ãããå¥æ±ãã§æ¸ãã¦ãã ãããæåã®åé¡æã« N = 1 ãä»£å ¥ããã¨åºã¾ãã
çã(1) = ãã«ã«ãåª(0..1, 1).filter(list -> (1..1).mapToInt(i -> c[i] * list[i]).sum() <= C ).mapToInt(list -> (1..1).mapToInt(i -> p[i] * list[i]).sum() ).max()
æ´çããã¨ã以ä¸ã®ããã«ãªãã¾ãã
çã(1) = ãã«ã«ãåª(0..1, 1).filter(list -> c[1] * list[1] <= C ).mapToInt(list -> p[1] * list[1] ).max()
ãã£ã¨æ´çããã¨ã以ä¸ã®ããã«ãªãã¾ãã-âã¯è©°ããããªããã¿ã¼ã³ã§ãã空ãªã¹ã.max() == -â ã¨ãã¾ããã
çã(1) = c[1] <= C ? p[1] : (0 <= C ? 0 : -â)
ããã¦ããã¨ã¯ãf2 ã®å¼æ°ãåããªããè¿ãå¤ã¯å¸¸ã«ä¸ç·ãªã®ã§ãã¡ã¢åããã°OKã§ããããã ã¢ãããªãé åã«æ¸ãã°è¯ãã§ããããããæ´ã«æ´çãããé«éåãããå°ã ã§ãã¾ããæèæ«ç¯ãªã®ã§çç¥ãã¾ãã
JOI 2014å¹´äºé¸å4
ãã¦ã2013å¹´12æã«éå¬ãããã2014å¹´äºé¸å4ã§ããåé¡æ㯠http://www.ioi-jp.org/joi/2013/2014-yo/2014-yo-t4/2014-yo-t4.html ãæ¬ä¼¼ã³ã¼ãã«ãããã¨ä»¥ä¸ã®éãã§ããallMatch() ã¡ã½ããã¯å ¨ã¦ true ã®æã« true ã«ãªãã¨ãã Java 8 ã®ã¡ã½ããã§ããåé¡æã¯éµã«é¢ããé¨åãããã®ã§ãããã®é¨åã¯é£ç¶åã人ãåºå¸ããå¿ è¦ãããã¨ããå½¢ã§æ´çæ¸ã¿ã§ãã
çã(N) = ãã«ã«ãåª(0..7, N).filter(list -> (list[1] & 1 != 0) && (2..N).allMatch(i -> list[i] & list[i - 1] != 0) && (1..N).allMatch(i -> list[i] & P[i] != 0) ).mapToInt(list -> 1 ).sum()
ãã®ããã«ãlist[i] & list[i - 1] ã®ããã«é åã®2ã¤ã®è¦ç´ ã«ã¢ã¯ã»ã¹ãã¦ããã¨ãã¯ãå®æ°åãã¹ã㯠2 åã«ãªãã¾ããå ¨ãåãæé ã§ãããã¾ããããªã¹ãæ«å°¾2ã¤ãå®æ°åããX1 = list[N], X2 = list[N - 1] ã¨ãã¾ãã
f1(N, X1, X2) = ãã«ã«ãåª(0..7, N - 2).filter(list -> (list[1] & 1 != 0) && (2..(N - 2)).allMatch(i -> list[i] & list[i - 1] != 0) && (X2 & list[N - 2] != 0) && (X1 & X2 != 0) && (1..(N - 2)).allMatch(i -> list[i] & P[i] != 0) && (X2 & P[N - 1] != 0) && (X1 & P[N] != 0) ).mapToInt(list -> 1 ).sum()
ã«ã¼ãã®1ã¤åã«ãªã¹ãæ«å°¾1ã¤ãã¤ã¾ããX2 = list[N - 1] ã ããå®æ°åããç©ã¯ãã®ããã«ãªãã¾ãã
f2(N - 1, X2) = ãã«ã«ãåª(0..7, N - 2).filter(list -> (list[1] & 1 != 0) && (2..(N - 2)).allMatch(i -> list[i] & list[i - 1] != 0) && (X2 & list[N - 2] != 0) && (1..(N - 2)).allMatch(i -> list[i] & P[i] != 0) && (X2 & P[N - 1] != 0) ).mapToInt(list -> 1 ).sum()
è¨äºã®é½åä¸ãN ãå ·ä½åãã¦ããªãã®ã§ããã3 ã¨ã 4 ã¨ãå ·ä½çãªæ°åãå ¥ãã¦åãæ±ãã¨ãããåããããããç°¡åã«ãªãã¾ãã
ã§ããã¤ãéãããã®2ã¤ãæ¯è¼ããã¨ã(X1 & X2 != 0) 㨠(X1 & P[N] != 0) ã¨ããå®æ°ãå¢ãã¦ãã¦ããã¤ããããã false ã ã¨ãfilter ã®ã¯ãã¼ã¸ã£ã常㫠false ã«ãªããå ¨ä½ã 0 ã«ãªãã®ã§ã
f1(N, X1, X2) = (X1 & X2 != 0) && (X1 & P[N] != 0) ? f2(N - 1, X2) : 0
ã¨åããã¾ãã
ã¾ããæ«å°¾å®æ°åã«ãããçããf2ã¯ä»¥ä¸ã®å½¢ã§è¡¨ç¾ã§ãã¾ãã
çã(N) = (0..7).mapToInt(x1 -> f2(N - 1, x1)).sum() f2(N - 1, x1) = (0..7).mapToInt(x2 -> f1(N - 1, x1, x2)).sum()
ãã¨ã¯ããã£ãã®å¼ã§ f1 ã f2 ããæ±ã¾ããf1, f2, f1, f2 ã¨è¡ã£ããæ¥ããããã«ã¼ããåºæ¥ä¸ããã¾ããããã¦ãã«ã¼ãã®æå¾ã¯ãçã(2) ãæ´çããã°ï¼¯ï¼«ã§ããå ãã¦ã¡ã¢åããã¾ãã
JOI 2013å¹´äºé¸å4
æ¬å½ã«ã¯ã³ãã¿ã¼ã³ã§ãããä¸å¿è»½ã2012å¹´12æã®2013å¹´äºé¸4ã触ãã¾ããåé¡æ㯠http://www.ioi-jp.org/joi/2012/2013-yo/2013-yo-t4/2013-yo-t4.html ãæ¬ä¼¼ã³ã¼ãã«ãããã¨ä»¥ä¸ã®éãã§ãã
çã(D) = ãã«ã«ãåª(1..N, D).filter(list -> (1..D).allMatch(i -> A[list[i]] <= T[i] && T[i] <= B[list[i]]) ).mapToInt(list -> (2..D).mapToInt(i-> abs(C[list[i - 1]] - C[list[i]])).sum() ).max()
ä»åã¯ã«ã¼ãå¤æ°ã¯ D ã§ããããã¦ãlist[i - 1] 㨠list[i] ã使ã£ã¦ãã®ã§ãå®æ°åã¯2åã§ãã
f1(D, X1, X2) = ãã«ã«ãåª(1..N, D - 2).filter(list -> (1..(D - 2)).allMatch(i -> A[list[i]] <= T[i] && T[i] <= B[list[i]]) && A[X2] <= T[D - 1] && T[D - 1] <= B[X2] && A[X1] <= T[D] && T[D] <= B[X1] ).mapToInt(list -> (2..(D - 2)).mapToInt(i -> abs(C[list[i - 1]] - C[list[i]])).sum() + abs(C[list[D - 2]] - C[X2]) + abs(C[X2] - C[X1]) ).max()
mapToInt ã®ä¸ã®å®æ° abs(C[X2] - C[X1]) ã¯éç´é¢æ° max ã®å¤åºãã§ããã§ãã«ã¼ã1ã¤åã®æ«å°¾1ã¤ã ãå®æ°åããã®ã¯ã
f2(D - 1, X2) = ãã«ã«ãåª(1..N, D - 2).filter(list -> (1..(D - 2)).allMatch(i -> A[list[i]] <= T[i] && T[i] <= B[list[i]]) && A[X2] <= T[D - 1] && T[D - 1] <= B[X2] ).mapToInt(list -> (2..(D - 2)).mapToInt(i -> abs(C[list[i - 1]] - C[list[i]])).sum() + abs(C[list[D - 2]] - C[X2]) ).max()
ä»£å ¥ããã¨ã以ä¸ã®éãã§ãã空ãªã¹ã.max() == -â ã¨ãã¾ããã
f1(D, X1, X2) = A[X1] <= T[D] && T[D] <= B[X1] ? f2(D - 1, X2) + abs(C[X2] - C[X1]) : -â
æ«å°¾å®æ°åããã¨è¨ããã¨ããã
çã(D) = (1..N).mapToInt(x1 -> f2(D - 1, x1)).max() f2(D - 1, x1) = (1..N).mapToInt(x2 -> f1(D - 1, x1, x2)).max()
ã¨åã話ãç¶ããã«ã¼ãã®æå¾ã® çã(2) ã¯å¥æ ã§æ´çãããã¡ã¢åãã¦å®æã§ãã
2012å¹´äºé¸4ã2011å¹´äºé¸4ãåã解æ³ã§è§£ããã¨ãã§ãã¾ãã
QEMUã§ARMçUbuntuã®åä½æ¹æ³
QEMUã§ARMçUbuntuã®åä½ãããã¨ãããªæãã§åãã¾ããé度çã«ã2ã³ã¢ã®ãã¼ããã½ã³ã³ã®ç¬¬3ä¸ä»£Core i5ã§åããã¦ããã¶ãPentium 3ãããã®æãã«ãªãã¾ãããã¼ãã¼ãããã¦ã¹ããã¦ã¹ãã¤ã¼ã«ããããã¯ã¼ã¯ãåé¡ãªãã§ããgcc ã apt-get ã§ã¤ã³ã¹ãã¼ã«ã§ãã¾ãã
Ubuntu å´ã§ããä½æ¥
VMware ä¸ã® Ubuntu 12.04 ã§è¡ãã¾ãããSDã«ã¼ãã®ã¤ã¡ã¼ã¸ããã¦ã³ãã¼ããã¦å±éãã¦ããã ãã§ããyukoba:yukoba ã«ãªã£ã¦ããã¨ããã¯é©å½ã«å¤ãã¦ãã ããã
wget http://releases.linaro.org/13.06/ubuntu/vexpress/vexpress-raring_alip_20130625-379.img.gz gunzip vexpress-raring_alip_20130625-379.img.gz sudo mkdir /mnt/mnt (IMG=vexpress-raring_alip_20130625-379.img ; if [ -e "$IMG" ] ; then sudo mount -o loop,offset="$(file "$IMG" | awk 'BEGIN { RS=";"; } /partition 2/ { print $7*512; }')" -t auto "$IMG" /mnt/mnt; else echo "$IMG not found"; fi ) sudo cp -vr /mnt/mnt/boot . sudo chown -R yukoba:yukoba boot sudo umount /mnt/mnt mv vexpress-raring_alip_20130625-379.img boot/
Windows å´ã§ããä½æ¥
ä¸è¨ã® boot ãã©ã«ãã Windows å´ã«ã³ãã¼ãã¦ãã ãããããã¦ãhttp://lassauge.free.fr/qemu/ (QEMU on Windows) ãã QEMU ããã¦ã³ãã¼ããã¦ãC:\Program Files\Qemu-windows-1.5.1 ã¨ãã«å±éãã¾ãã
boot ãã©ã«ãã«ç§»åãã¦ã以ä¸ã®ã³ãã³ãã§å®è¡ã§ãã¾ãã
"C:\Program Files\Qemu-windows-1.5.1\qemu-system-armw.exe" -kernel vmlinuz-3.10.0-1-linaro-vexpress -M vexpress-a9 -cpu cortex-a9 -serial stdio -m 1024 -initrd initrd.img-3.10.0-1-linaro-vexpress -append "root=/dev/mmcblk0p2 rw mem=1024M raid=noautodetect console=ttyAMA0,38400n8 rootwait vmalloc=256MB devtmpfs.mount=0" -sd vexpress-raring_alip_20130625-379.img
以ä¸ã®ããæ¹ã¯ãhttps://wiki.linaro.org/PeterMaydell/QemuVersatileExpress ããä¿®æ£ã
æµ·å¤èªç©ºå¸ã®å¤æ®µã®æ¯è¼
æµ·å¤èªç©ºå¸ã®å¤æ®µã調ã¹ã¦ã¿ã¾ãããæ±äº¬ããµã³ãã©ã³ã·ã¹ã³ãå¾å¾©ï¼æææ¥åºçºãå·çæã¯æ¥ææ¥ï¼ã
ããã | ææ¥oræå¾æ¥ | 1é±éå¾ | 2é±éå¾ |
---|---|---|---|
HIS ã | 111,200 | 90,680 | 75,670 |
JTB | 117,550 | 97,950 | 74,650 |
ANA | 110,000 | 99,000 | 99,000 |
楽天ããã | ããã | 99,675 | |
KAYAK | 103,880 | ||
Expedia | 105,000 | ||
ãã«ã¿èªç©º | 110,150 | 126,150 | 105,150 |
ã¹ã«ã¤ã²ã¼ã | 113,825 | 110,465 | 108,825 |
éªæ¥äº¤é | 123,420 | 102,330 | |
JAL | 331,210 | 119,210 | |
ã¦ãã¤ãããèªç©º | 120,790 |
å ¨ã¦ãçæ²¹ã»è«¸ç¨è¾¼ã
Yahoo, ãã©ãã«ã³, AB-ROAD ã¯ããåãããªãã®ã§é¤å¤ãKAYAK ã¯ç±³ãã«ããæ¥æ¬åã«æç®ï¼ã«ã¼ã決æ¸ã ã¨ãã£ã¨é«ããªãã¯ãï¼ã
ã¹ã«ã¤ã²ã¼ã, JTB 1é±éå¾ãéç´è¡ ã§ãã
ä»ã®å°åã§ãããããããHIS ããã ãããæå®ã§ãã
JNA ã Android ã§ä½¿ãæ¹æ³
Cè¨èªã®ã©ã¤ãã©ãªã Java ãã使ãã¨ãã«ä¾¿å©ãª https://github.com/twall/jna (JNA) ã Android ã§ä½¿ãæ¹æ³ã®ã¡ã¢ã§ããï¼è¿½è¨ï¼JNA 4.0.0 ã«åããã¦å¤§å¹ ã«æ¸ãæãã¾ããï¼
JNA 㯠4.0.0 ç¾å¨ãAndroid ã«å¯¾å¿ãã¦ãã¾ãããããã¥ã¡ã³ãããªãã§ãã3.4.0 å½æãAndroid 対å¿ããããã¨ãã¦ãä¸éå端ã«ãªã£ã¦ãã¦ã3.5.1 ã§ãã®æ®éª¸ãæ®ã£ã¦ãã¾ãããã4.0.0 ã§ã¯ã¡ããã¨å¯¾å¿ãã¦ãã¾ãã
æé
- https://github.com/twall/jna/raw/master/dist/android-arm.jar ããã¦ã³ãã¼ããã¦ã解åãã¦ãlibjnidispatch.so ãåãåºãã¾ãã
- libjnidispatch.so ãèªåã® Android ã¢ããªã®ããã¸ã§ã¯ããã©ã«ãã® libs/armeabi ã«ç½®ãã¾ãã
注æç¹
注æç¹ã¯ãä¸è¨ã®ããã« Structure ã«ã¯ãã£ã¼ã«ãã®é çªãæå®ããªãã¨ãããªãã§ããï¼è¿½è¨ï¼æã®JNAã¯ãããå¿ é ã§ã¯ãªãã£ãã®ã§ãããJNA 3.5.0 ããããããå¿ é ã§ããï¼
@Override protected List getFieldOrder() { return Arrays.asList("x", "y"); }
Androidã§Cè¨èªã®ã©ã¤ãã©ãªã®ãã«ãæ¹æ³ã®ã¾ã¨ã
Android 㯠Linux ã®ä¸ç¨®ã§ããããARM ã§åã Linux åãã®Cè¨èªã§æ¸ãããã©ã¤ãã©ãªã®å¤ããåãã¾ããï¼å¤å°éãã®ã§ãåããªãå ´åãããï¼ããã ãããã«ãæ¹æ³ãæé»ã®äºè§£äºé ã«ãªã£ã¦ãããã¦ãAndroid NDK ã«ã¡ããã¨æ¸ããã¦ããªãã£ããããã®ã§ãããã«ã¾ã¨ãã¾ãï¼
以ä¸ãæ¶ç©ºã® libhoge ããã«ããããã¨ã¨ãã¾ãã
ãã«ã対象ã¯ä¸è¬çã«éçã©ã¤ãã©ãª (.a) ãã¡ã¤ã«ã«ãã¦ããã¨åã§ããèªåã§ä½¿ãéã¯ãèªåã® Android.mk ã«ä»¥ä¸ã®ç©ã追å ãã¾ãã
- LOCAL_CFLAGS ã« -Ihoge-1.0/include ã¿ããã®ã追å
- LOCAL_LDLIBS ã« -Lhoge-1.0-android-build/$(TARGET_ARCH_ABI) 㨠-l hoge ã追å
ã©ã¤ãã©ãªããã«ããã¦ã§ãã libhoge.a ã¯ãã®ãã©ã«ãã«ç½®ãã¦ããã¾ãã
å¿ è¦ãªç©ï¼
- Android NDK: http://developer.android.com/tools/sdk/ndk/index.html ãããã¦ã³ãã¼ããã¤ã³ã¹ãã¼ã«å 㯠~/android-ndk-r9c ã¨ãã¾ãã
- Linux: Linux ãªãã¦ãã»ã¨ãã©ã®ã±ã¼ã¹ã§å¤§ä¸å¤«ã§ããããã«ãç¨ã« Linux ãã£ãã»ãã楽ã§ãã
æé ã¯ä»¥ä¸ã®é çªã§æ¤è¨ãã¦ããã¨è¯ãã§ãã
ï¼ï¼Android ã§ã®ãã«ãæ¹æ³ãã©ã¤ãã©ãªã«æ示ããã¦ããå ´å
å½ç¶ããã®ã±ã¼ã¹ã¯ãã©ã¤ãã©ãªã«å¾ãã¨ãã«ãã§ããã¯ãã§ãã
ï¼ï¼Android.mk ã ããç¨æããã¦ããå ´å
export NDK_ROOT=~/android-ndk-r9c cd ~/hoge-1.0 $NDK_ROOT/ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_ABI=armeabi obj/local/armeabi/libhoge.a $NDK_ROOT/ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_ABI=armeabi-v7a obj/local/armeabi-v7a/libhoge.a $NDK_ROOT/ndk-build NDK_PROJECT_PATH=. APP_BUILD_SCRIPT=./Android.mk APP_ABI=x86 obj/local/x86/libhoge.a
obj/local ã«ã§ãããã¤ãã³ã³ãã¤ã«çµæã§ãã
ï¼ï¼ãªã«ããªãã¦ãgcc ã®æ¨æºã®ãã«ãã¹ã¿ã¤ã«ã®å ´å
./configure â make â make install ã®ãã¿ã¼ã³ã®å ´åã§ãã
ã¾ããã¹ã¿ã³ãã¢ãã¼ã³ãã¼ã«ãã§ã¤ã³ãã¤ã³ã¹ãã¼ã«ããå¿ è¦ãããã¾ããAndroid NDK ã® docs/STANDALONE-TOOLCHAIN.html ã«èª¬æãæ¸ãã¦ããã¾ãã以ä¸ãandroid-9 ã«ããã®ã§ãAndroid 2.3 ç¨ã§ãã
export NDK_ROOT=~/android-ndk-r9c $NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=arm-linux-androideabi-4.6 --install-dir=$HOME/android-toolchain-arm-4.6 $NDK_ROOT/build/tools/make-standalone-toolchain.sh --platform=android-9 --toolchain=x86-4.6 --install-dir=$HOME/android-toolchain-x86-4.6
ãã¦ããã«ãæ¹æ³ã以ä¸ãconfigure ãç½®ãã¦ããå ã®ã½ã¼ã¹ãã©ã«ããæ±ããªãããã«å¥ã®ãã©ã«ããä½ã£ã¦ãã«ããã¾ããã½ã¼ã¹ã¯ ~/hoge-1.0 ã¨ãã«å±éãã¦ããã¨ãã¾ãã
export ANDROID_TOOLCHAIN=~/android-toolchain-arm-4.6 export BUILD_HOST=arm-linux-androideabi export PATH=$ANDROID_TOOLCHAIN/bin:$PATH export CC=$BUILD_HOST-gcc export CFLAGS="-mthumb -march=armv7-a -mfloat-abi=softfp -I$ANDROID_TOOLCHAIN/include" export LDFLAGS="-Wl,--fix-cortex-a8" mkdir ~/hoge-1.0-android cd ~/hoge-1.0-android ../hoge-1.0/configure --host=$BUILD_HOST --prefix=$PWD/build-result make -j 4 make install
ããã¨ã~/hoge-1.0-android/build-result ã«ãã«ãçµæãä½ãããã®ã§ãlib/libhoge.a ãæ¢ãã¦ãã ããã
ä¸è¨ã®æ¹æ³ã¯ãarmeabi-v7a ã®æ¹ã§ Cortex-A ã·ãªã¼ãºã§ããåããªãããã®ããã«ããã¨ãarmeabi ã«ãªããå ¨ã¦ã® Android ã§åãããã«ãªãã¾ãã
export CFLAGS="-mthumb -march=armv5te -I$ANDROID_TOOLCHAIN/include"
ã¾ããNEON (Advanced SIMD) ãæå¹ã«ããã«ã¯ããã®ããã«ãã¾ããNVIDIA Tegra 2 ã§åããªããªãã¾ãã
export CFLAGS="-mthumb -march=armv7-a -mfloat-abi=softfp -mfpu=neon -I$ANDROID_TOOLCHAIN/include"
ã¡ãªã¿ã«ãconfigure ã® --hostãarm-linux-androideabi ($BUILD_HOST) ã§ãããarm-linux ã«ã㦠Android ã§ãããã¨ãé ãã¦ãã¾ãã¨ãã¾ãããå ´åããã£ãããªãã£ãããã¾ããAndroid NDK r8b ç¾å¨ãElf32_auxv_t ãæªå®ç¾©ã ã£ãããå¾®å¦ã« Android 㯠Linux ã¨å·®ããããã§ããâ¦
export ANDROID_TOOLCHAIN=~/android-toolchain-x86-4.6 export BUILD_HOST=i686-linux-android export PATH=$ANDROID_TOOLCHAIN/bin:$PATH export CC=$BUILD_HOST-gcc export CFLAGS="-I$ANDROID_TOOLCHAIN/include" export LDFLAGS="" mkdir ~/hoge-1.0-android-x86 cd ~/hoge-1.0-android-x86 ../hoge-1.0/configure --host=$BUILD_HOST --prefix=$PWD/build-result make -j 4 make install
åããã~/hoge-1.0-android-x86/build-result ã«ãã«ãçµæãä½ãããã®ã§ãlib/libhoge.a ãæ¢ãã¦ãã ããã
GMOã¯ã©ã¦ã Public APIã®Javaã¯ã©ã¤ã¢ã³ã
GMOã¯ã©ã¦ã Public APIã®Javaã¯ã©ã¤ã¢ã³ããä½ãã¾ããã
https://github.com/yukoba/GmoCloudAPI
使ãæ¹
GmoCloud gmoCloud = new GmoCloud(ACCESS_KEY_ID, SECRET_KEY, "jp002"); String json = gmoCloud.listNodesJson();