找回密码
 欢迎注册
楼主: mathe

[擂台] 平方数数字和

[复制链接]
发表于 2008-7-15 08:19:58 | 显示全部楼层


你如果ICC编译你以前的未手工展开的代码
效果如何?

我昨天的测试也说了,icc编译后慢于你以前代码
因为我的代码基本没改你代码结构
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-7-15 08:54:59 | 显示全部楼层
原帖由 无心人 于 2008-7-15 08:19 发表
你如果ICC编译你以前的未手工展开的代码
效果如何?


测试结果如下:
code \ compilerMSCICC
72#405.658378 s309.397843 s
96#213.489686 s285.919940 s

完全遍历 10^20 以内的完全平方数


其中,96# 与 72# 的区别仅在于,前者是将后者代码中的循环手工展开而已。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-7-15 09:24:50 | 显示全部楼层
机器软硬件情况
包括操作系统
编译器版本
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-7-15 09:46:34 | 显示全部楼层
CPU       AMD Athlon(tm) 64 Processor 3200+
指令集     MMX (+), 3DNow! (+), SSE, SSE2, SSE3, x86-64
L1 数据缓存   64 KBytes,2-路设置关联,64-字节行大小
L1 指令缓存   64 KBytes,2-路设置关联,64-字节行大小
L2 缓存     512 KBytes,16-路设置关联,64-字节行大小

内存类型    DDR
通道数     双
内存大小    1024 MBytes
内存频率    200.9 MHz (CPU/5)

Windows 版本  Microsoft Windows XP Professional  Service Pack 2 (Build 2600)

编译器     Microsoft Visual Studio 6.0 + SP5 / Intel C++ Compiler 10.0.027
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-7-15 10:38:58 | 显示全部楼层
AMD的U是不能用ICC编译器的
呵呵
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-7-28 09:33:41 | 显示全部楼层
今天来学校
顺便写了PASCAL代码
挂服务器上的计划任务里了
处理结构化数据,还是PASCAL要比C简单
呵呵
  1. program square;

  2. {\$APPTYPE CONSOLE}

  3. uses
  4.   SysUtils;
  5.   
  6. const
  7.   Ten6 = 1000000;
  8.   StatusFileName = 'Square.Status';
  9.   LogFileName = 'Square.Log';

  10. type
  11.   TStatus = record
  12.     S: array[0..439] of byte; //448 Byte
  13.     Sum: array[0..7] of integer; //32 Byte
  14.     SumMax: integer; //4 byte;
  15.     Delta: array[0..7] of integer;  //32 Byte
  16.     DeltaMax: integer; //4 byte
  17.   end;

  18. var
  19.   Status: TStatus;
  20.   StatusFile: File of TStatus;
  21.   LogFile: TextFile;
  22.   SumOfDigit6: array[0..999999] of integer;
  23.   ExeFilePath: string;
  24.   Counter: Int64;

  25. procedure WriteLog(s: string);
  26. begin
  27.   AssignFile(LogFile, ExeFilePath + LogFileName);
  28.   if FileExists(ExeFilePath + LogFileName) then
  29.     Append(LogFile)
  30.   else
  31.     Rewrite(LogFile);
  32.   writeln(LogFile, s);
  33.   Close(LogFile);
  34. end;

  35. procedure InitStatus;
  36. var
  37.   i: integer;
  38. begin
  39.   for I := 0 to 447 do
  40.     Status.s[i] := 0;
  41.   for i := 0 to 7 do
  42.   begin
  43.     status.sum[i] := 0;
  44.     status.delta[i] := 0;
  45.   end;
  46.   Status.Delta[0] := 1;
  47.   Status.SumMax := 0;
  48.   Status.DeltaMax := 0;
  49. end;

  50. procedure ReadStatus;
  51. begin
  52.   AssignFile(StatusFile, ExeFilePath + StatusFileName);
  53.   if FileExists(ExeFilePath + StatusFileName) then
  54.   begin
  55.     Reset(StatusFile);
  56.     Read(StatusFile, Status);
  57.     Close(StatusFile);
  58.   end
  59.   else
  60.     InitStatus;
  61. end;

  62. procedure WriteStatus;
  63. begin
  64.   AssignFile(StatusFile, ExeFilePath + StatusFileName);
  65.   if FileExists(ExeFilePath + StatusFileName) then
  66.     Rewrite(StatusFile)
  67.   else
  68.     Reset(StatusFile);
  69.   Write(StatusFile, Status);
  70.   Close(StatusFile);
  71. end;

  72. procedure AddDelta;
  73. var
  74.   i: integer;
  75. begin
  76.   for I := 0 to Status.SumMax do
  77.   begin
  78.     Status.Sum[i] := Status.Sum[i] + Status.Delta[i];
  79.   end;

  80.   for I := 0 to Status.SumMax do
  81.     if Status.Sum[i] >= TEN6 then
  82.       if i <= 7 then
  83.       begin
  84.         Status.Sum[i] := Status.Sum[i] - TEN6;
  85.         INC(Status.Sum[i+1]);
  86.       end
  87.       else
  88.       begin
  89.         WriteLog(DateTimeToStr(now) + ': SUM is TOO Big!!');
  90.         exit;
  91.       end;
  92.   if Status.Sum[Status.SumMax+1] > 0 then
  93.     INC(Status.SumMax);
  94. end;

  95. procedure IncDelta;
  96. var
  97.   i: integer;
  98. begin
  99.   Status.Delta[0] := Status.Delta[0] + 2;
  100.   for I := 0 to Status.DeltaMax do
  101.     if Status.Delta[i] >= TEN6 then
  102.     begin
  103.       if i < 7 then
  104.       begin
  105.         Status.Delta[i] := Status.Delta[i] - TEN6;
  106.         INC(Status.Delta[i + 1]);
  107.       end
  108.       else
  109.       begin
  110.         WriteLog('Delta is TOO Big!');
  111.         exit;
  112.       end;
  113.     end;
  114. end;

  115. procedure InitSumOfDigit6;
  116. var
  117.   i5, i4, i3, i2, i1, i0, k: integer;
  118. begin
  119.   k := 0;
  120.   for I5 := 0 to 9 do
  121.     for I4 := 0 to 9 do
  122.       for I3 := 0 to 9 do
  123.         for I2 := 0 to 9 do
  124.           for I1 := 0 to 9 do
  125.             for I0 := 0 to 9 do
  126.             begin
  127.               SumOfDigit6[k] := i5 + i4 + i3 + i2 + i1 + i0;
  128.               INC(k);
  129.             end;
  130. end;

  131. procedure ProgressSum;
  132. var
  133.   i: integer;
  134.   s: integer;
  135.   Str: String;
  136. begin
  137.   s := 0;
  138.   for I := 0 to Status.SumMax do
  139.     s := s + SumOfDigit6[Status.Sum[i]];
  140.   if (Status.S[s] = 0) then
  141.   begin
  142.     Status.S[s] := 1;
  143.     for I := Status.SumMax downto 0 do
  144.       Str := str + Format('%06d', [Status.Sum[i]]);
  145.     writeln(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
  146.     writelog(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
  147.   end;
  148. end;
  149. procedure TEST;
  150. begin
  151.   AddDelta;
  152.   ProgressSum;
  153.   IncDelta;
  154. end;

  155. begin
  156.   { TODO -oUser -cConsole Main : Insert code here }
  157. //
  158.   WriteLog('程序启动: ' + DateTimeToStr(now));
  159.   WriteLn('程序启动: ' + DateTimeToStr(now));
  160.   ExeFilePath := ExtractFilePath(ParamStr(0));
  161.   Counter := 0;
  162.   InitSumOfDigit6;
  163.   ReadStatus;
  164.   WriteLog('完成初始化: ' + DateTimeToStr(now));
  165.   WriteLn('完成初始化: ' + DateTimeToStr(now));
  166.   repeat
  167.     TEST;
  168.     INC(Counter);
  169.     if Counter >= 10000000000 then
  170.     begin
  171.       WriteStatus;
  172.       Counter := 0;
  173.     end;
  174.   until FALSE;
  175. end.
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-7-28 10:05:21 | 显示全部楼层
令人郁闷的是,怎么速度比C代码慢很多啊???
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-7-28 10:34:55 | 显示全部楼层
估计主要原因是你上面用的array太大(1000000个int),
无法一次性装入CPU的cache 所致。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-7-28 11:04:23 | 显示全部楼层
确实是
修改好了
正式挂
呵呵
差点因此失去用Pascal的信心
要知道用C写处理结构存储的
程序就比Pascal麻烦多了
呵呵
  1. program square;

  2. {\$APPTYPE CONSOLE}

  3. uses
  4.   SysUtils;

  5. const
  6.   TenPower = 10000;
  7.   StatusFileName = 'Square.Status';
  8.   LogFileName = 'Square.Log';
  9.   BlockSize = 8;
  10.   BoolSize = 320;

  11. type
  12.   TStatus = record
  13.     S: array[0..BoolSize-1] of byte; //320 Byte
  14.     Sum: array[0..BlockSize-1] of integer; //32 Byte
  15.     SumMax: integer; //4 byte;
  16.     Delta: array[0..BlockSize-1] of integer;  //32 Byte
  17.     DeltaMax: integer; //4 byte
  18.   end;

  19. var
  20.   Status: TStatus;
  21.   StatusFile: File of TStatus;
  22.   LogFile: TextFile;
  23.   SumOfDigit4: array[0..TenPower-1] of byte;
  24.   ExeFilePath: string;
  25.   Counter: Integer;

  26. procedure WriteLog(s: string);
  27. begin
  28.   AssignFile(LogFile, ExeFilePath + LogFileName);
  29.   if FileExists(ExeFilePath + LogFileName) then
  30.     Append(LogFile)
  31.   else
  32.     Rewrite(LogFile);
  33.   writeln(LogFile, s);
  34.   Close(LogFile);
  35. end;

  36. procedure InitStatus;
  37. var
  38.   i: integer;
  39. begin
  40.   for I := 0 to BoolSize-1 do
  41.     Status.s[i] := 0;
  42.   for i := 0 to BlockSize-1 do
  43.   begin
  44.     status.sum[i] := 0;
  45.     status.delta[i] := 0;
  46.   end;
  47.   Status.Delta[0] := 1;
  48.   Status.SumMax := 0;
  49.   Status.DeltaMax := 0;
  50. end;

  51. procedure ReadStatus;
  52. begin
  53.   AssignFile(StatusFile, ExeFilePath + StatusFileName);
  54.   if FileExists(ExeFilePath + StatusFileName) then
  55.   begin
  56.     Reset(StatusFile);
  57.     Read(StatusFile, Status);
  58.     Close(StatusFile);
  59.   end
  60.   else
  61.     InitStatus;
  62. end;

  63. procedure WriteStatus;
  64. begin
  65.   AssignFile(StatusFile, ExeFilePath + StatusFileName);
  66.   Rewrite(StatusFile);
  67.   Write(StatusFile, Status);
  68.   Close(StatusFile);
  69. end;

  70. procedure InitSumOfDigit4;
  71. var
  72.   i3, i2, i1, i0, k: integer;
  73. begin
  74.   k := 0;
  75.   for I3 := 0 to 9 do
  76.     for I2 := 0 to 9 do
  77.       for I1 := 0 to 9 do
  78.         for I0 := 0 to 9 do
  79.         begin
  80.           SumOfDigit4[k] := i3 + i2 + i1 + i0;
  81.           INC(k);
  82.         end;
  83. end;

  84. var
  85.   i, s: integer;
  86.   Str: String;

  87. begin
  88.   { TODO -oUser -cConsole Main : Insert code here }
  89. //
  90.   WriteLog('程序启动: ' + DateTimeToStr(now));
  91.   WriteLn('程序启动: ' + DateTimeToStr(now));
  92.   ExeFilePath := ExtractFilePath(ParamStr(0));
  93.   Counter := 0;
  94.   InitSumOfDigit4;
  95.   ReadStatus;
  96.   WriteLog('完成初始化: ' + DateTimeToStr(now));
  97.   WriteLn('完成初始化: ' + DateTimeToStr(now));
  98.   repeat
  99. //    TEST;
  100. //ADDDelta
  101.     for I := 0 to Status.SumMax do
  102.     begin
  103.       Status.Sum[i] := Status.Sum[i] + Status.Delta[i];
  104.     end;

  105.     for I := 0 to Status.SumMax do
  106.       if Status.Sum[i] >= TenPower then
  107.         if i <= BlockSize-1 then
  108.         begin
  109.           Status.Sum[i] := Status.Sum[i] - TenPower;
  110.           INC(Status.Sum[i+1]);
  111.         end
  112.         else
  113.         begin
  114.           WriteLog(DateTimeToStr(now) + ': 平方和缓冲溢出!!');
  115.           WriteLn(DateTimeToStr(now) + ': 平方和缓冲溢出!!');
  116.           exit;
  117.         end;
  118.     if Status.Sum[Status.SumMax+1] > 0 then
  119.       INC(Status.SumMax);

  120. //  ProgressSum;
  121.     s := 0;
  122.     for I := 0 to Status.SumMax do
  123.       s := s + SumOfDigit4[Status.Sum[i]];
  124.     if (Status.S[s] = 0) then
  125.     begin
  126.       Status.S[s] := 1;
  127.       Str := '';
  128.       for i := Status.SumMax downto 0 do
  129.         Str := str + Format('%04d', [Status.Sum[i]]);
  130.       writeln(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
  131.       writelog(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
  132.     end;

  133. //  IncDelta;
  134.     Status.Delta[0] := Status.Delta[0] + 2;
  135.     for I := 0 to Status.DeltaMax do
  136.       if Status.Delta[i] >= TenPower then
  137.       begin
  138.         Status.Delta[i] := Status.Delta[i] - TenPower;
  139.         INC(Status.Delta[i + 1]);
  140.       end;

  141.     if Status.Delta[Status.DeltaMax + 1] > 0 then
  142.       INC(Status.DeltaMax);

  143.     INC(Counter);
  144.     if Counter = 0 then
  145.       WriteStatus;
  146.   until FALSE;
  147. end.
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2008-7-28 14:56:56 | 显示全部楼层
运行到了181时是3小时10分钟左右吧
看来我要在72小时后再去收集结果
否则不可能超越GxQ
在考虑下是否要加点SSE2
不知Delphi10支持SSE2汇编么?
另外C有否比较简单的结构存盘的方法?
还有,把程序放2003的计划任务里了
设定的是启动后执行
也不知道停电后启动时候是否能如愿执行
也没测试状态恢复得了么?
呵呵,祈祷学校7天不停电
或者我程序能成功恢复状态

  1. 程序启动: 2008-7-28 11:24:29

  2. 完成初始化: 2008-7-28 11:24:29

  3. 2008-7-28 11:24:29: 1    1

  4. 2008-7-28 11:24:29: 4    4

  5. 2008-7-28 11:24:29: 9    9

  6. 2008-7-28 11:24:29: 7   16

  7. 2008-7-28 11:24:29: 13   49

  8. 2008-7-28 11:24:29: 10   64

  9. 2008-7-28 11:24:29: 16  169

  10. 2008-7-28 11:24:29: 19  289

  11. 2008-7-28 11:24:29: 18  576

  12. 2008-7-28 11:24:29: 22 1849

  13. 2008-7-28 11:24:29: 27 3969

  14. 2008-7-28 11:24:29: 25 4489

  15. 2008-7-28 11:24:29: 31 6889

  16. 2008-7-28 11:24:29: 28    17956

  17. 2008-7-28 11:24:29: 34    27889

  18. 2008-7-28 11:24:29: 36    69696

  19. 2008-7-28 11:24:29: 40    97969

  20. 2008-7-28 11:24:29: 37    98596

  21. 2008-7-28 11:24:29: 43   499849

  22. 2008-7-28 11:24:29: 46   698896

  23. 2008-7-28 11:24:29: 45  1887876

  24. 2008-7-28 11:24:29: 49  2778889

  25. 2008-7-28 11:24:29: 52  4999696

  26. 2008-7-28 11:24:29: 54  9696996

  27. 2008-7-28 11:24:29: 55 19998784

  28. 2008-7-28 11:24:29: 58 46689889

  29. 2008-7-28 11:24:29: 61 66699889

  30. 2008-7-28 11:24:29: 63 79869969

  31. 2008-7-28 11:24:29: 64    277788889

  32. 2008-7-28 11:24:29: 67    478996996

  33. 2008-7-28 11:24:29: 70    876988996

  34. 2008-7-28 11:24:29: 73   1749999889

  35. 2008-7-28 11:24:29: 72   3679999569

  36. 2008-7-28 11:24:29: 76   5599977889

  37. 2008-7-28 11:24:29: 79   7998976969

  38. 2008-7-28 11:24:30: 81   8998988769

  39. 2008-7-28 11:24:30: 82  17999978896

  40. 2008-7-28 11:24:30: 85  36799899889

  41. 2008-7-28 11:24:30: 88  88998998929

  42. 2008-7-28 11:24:30: 90 297889998849

  43. 2008-7-28 11:24:30: 91 299879997769

  44. 2008-7-28 11:24:30: 94 897977978689

  45. 2008-7-28 11:24:30: 97 975979998889

  46. 2008-7-28 11:24:30: 100    2699997789889

  47. 2008-7-28 11:24:30: 99    3957779999889

  48. 2008-7-28 11:24:30: 103    9879498789889

  49. 2008-7-28 11:24:30: 106    9998768898889

  50. 2008-7-28 11:24:30: 108   29998985899689

  51. 2008-7-28 11:24:30: 109   85986989688889

  52. 2008-7-28 11:24:30: 112   97888999968769

  53. 2008-7-28 11:24:31: 115  386999898769969

  54. 2008-7-28 11:24:31: 117  429998989997889

  55. 2008-7-28 11:24:31: 118  578889999977689

  56. 2008-7-28 11:24:32: 121  898999897988929

  57. 2008-7-28 11:24:32: 124 1959999889996996

  58. 2008-7-28 11:24:33: 127 3699998989898689

  59. 2008-7-28 11:24:35: 126 6788999798879769

  60. 2008-7-28 11:24:36: 130 9895699989899689

  61. 2008-7-28 11:24:43: 133    38896878989988889

  62. 2008-7-28 11:24:43: 136    38999699989995889

  63. 2008-7-28 11:24:47: 135    67699789959899889

  64. 2008-7-28 11:25:00: 139   188997899869998769

  65. 2008-7-28 11:25:07: 142   279869897899999969

  66. 2008-7-28 11:25:19: 144   498999778899898896

  67. 2008-7-28 11:25:40: 148   989879999979599689

  68. 2008-7-28 11:26:06: 145  1877896979979898969

  69. 2008-7-28 11:27:27: 153  5899989587897999889

  70. 2008-7-28 11:27:44: 151  6979497898999879969

  71. 2008-7-28 11:28:08: 154  8899988895999696889

  72. 2008-7-28 11:30:56: 157 28979978999958969889

  73. 2008-7-28 11:35:38: 160 78897999969769888996

  74. 2008-7-28 11:36:25: 162 87989899898866889889

  75. 2008-7-28 11:42:54: 163    199989299899788979969

  76. 2008-7-28 11:52:44: 166    449998999899988698769

  77. 2008-7-28 12:02:57: 171    789899899796987988996

  78. 2008-7-28 12:07:14: 169    969988797999759789889

  79. 2008-7-28 12:47:35: 172   3599979999987777888889

  80. 2008-7-28 13:01:41: 175   4899976999986989889796

  81. 2008-7-28 13:36:48: 178   8889998799995887887889

  82. 2008-7-28 13:44:25: 180   9899698989999989958489

  83. 2008-7-28 14:33:48: 181  17989999975899879969889
复制代码
刚算的,似乎一秒处理是10000000个数字,少的多
需要52小时达到GxQ的最新的结果,呵呵
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-5-3 19:46 , Processed in 0.056344 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表