找回密码
 欢迎注册
楼主: 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. const
  6. Ten6 = 1000000;
  7. StatusFileName = 'Square.Status';
  8. LogFileName = 'Square.Log';
  9. type
  10. TStatus = record
  11. S: array[0..439] of byte; //448 Byte
  12. Sum: array[0..7] of integer; //32 Byte
  13. SumMax: integer; //4 byte;
  14. Delta: array[0..7] of integer; //32 Byte
  15. DeltaMax: integer; //4 byte
  16. end;
  17. var
  18. Status: TStatus;
  19. StatusFile: File of TStatus;
  20. LogFile: TextFile;
  21. SumOfDigit6: array[0..999999] of integer;
  22. ExeFilePath: string;
  23. Counter: Int64;
  24. procedure WriteLog(s: string);
  25. begin
  26. AssignFile(LogFile, ExeFilePath + LogFileName);
  27. if FileExists(ExeFilePath + LogFileName) then
  28. Append(LogFile)
  29. else
  30. Rewrite(LogFile);
  31. writeln(LogFile, s);
  32. Close(LogFile);
  33. end;
  34. procedure InitStatus;
  35. var
  36. i: integer;
  37. begin
  38. for I := 0 to 447 do
  39. Status.s[i] := 0;
  40. for i := 0 to 7 do
  41. begin
  42. status.sum[i] := 0;
  43. status.delta[i] := 0;
  44. end;
  45. Status.Delta[0] := 1;
  46. Status.SumMax := 0;
  47. Status.DeltaMax := 0;
  48. end;
  49. procedure ReadStatus;
  50. begin
  51. AssignFile(StatusFile, ExeFilePath + StatusFileName);
  52. if FileExists(ExeFilePath + StatusFileName) then
  53. begin
  54. Reset(StatusFile);
  55. Read(StatusFile, Status);
  56. Close(StatusFile);
  57. end
  58. else
  59. InitStatus;
  60. end;
  61. procedure WriteStatus;
  62. begin
  63. AssignFile(StatusFile, ExeFilePath + StatusFileName);
  64. if FileExists(ExeFilePath + StatusFileName) then
  65. Rewrite(StatusFile)
  66. else
  67. Reset(StatusFile);
  68. Write(StatusFile, Status);
  69. Close(StatusFile);
  70. end;
  71. procedure AddDelta;
  72. var
  73. i: integer;
  74. begin
  75. for I := 0 to Status.SumMax do
  76. begin
  77. Status.Sum[i] := Status.Sum[i] + Status.Delta[i];
  78. end;
  79. for I := 0 to Status.SumMax do
  80. if Status.Sum[i] >= TEN6 then
  81. if i <= 7 then
  82. begin
  83. Status.Sum[i] := Status.Sum[i] - TEN6;
  84. INC(Status.Sum[i+1]);
  85. end
  86. else
  87. begin
  88. WriteLog(DateTimeToStr(now) + ': SUM is TOO Big!!');
  89. exit;
  90. end;
  91. if Status.Sum[Status.SumMax+1] > 0 then
  92. INC(Status.SumMax);
  93. end;
  94. procedure IncDelta;
  95. var
  96. i: integer;
  97. begin
  98. Status.Delta[0] := Status.Delta[0] + 2;
  99. for I := 0 to Status.DeltaMax do
  100. if Status.Delta[i] >= TEN6 then
  101. begin
  102. if i < 7 then
  103. begin
  104. Status.Delta[i] := Status.Delta[i] - TEN6;
  105. INC(Status.Delta[i + 1]);
  106. end
  107. else
  108. begin
  109. WriteLog('Delta is TOO Big!');
  110. exit;
  111. end;
  112. end;
  113. end;
  114. procedure InitSumOfDigit6;
  115. var
  116. i5, i4, i3, i2, i1, i0, k: integer;
  117. begin
  118. k := 0;
  119. for I5 := 0 to 9 do
  120. for I4 := 0 to 9 do
  121. for I3 := 0 to 9 do
  122. for I2 := 0 to 9 do
  123. for I1 := 0 to 9 do
  124. for I0 := 0 to 9 do
  125. begin
  126. SumOfDigit6[k] := i5 + i4 + i3 + i2 + i1 + i0;
  127. INC(k);
  128. end;
  129. end;
  130. procedure ProgressSum;
  131. var
  132. i: integer;
  133. s: integer;
  134. Str: String;
  135. begin
  136. s := 0;
  137. for I := 0 to Status.SumMax do
  138. s := s + SumOfDigit6[Status.Sum[i]];
  139. if (Status.S[s] = 0) then
  140. begin
  141. Status.S[s] := 1;
  142. for I := Status.SumMax downto 0 do
  143. Str := str + Format('%06d', [Status.Sum[i]]);
  144. writeln(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
  145. writelog(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
  146. end;
  147. end;
  148. procedure TEST;
  149. begin
  150. AddDelta;
  151. ProgressSum;
  152. IncDelta;
  153. end;
  154. begin
  155. { TODO -oUser -cConsole Main : Insert code here }
  156. //
  157. WriteLog('程序启动: ' + DateTimeToStr(now));
  158. WriteLn('程序启动: ' + DateTimeToStr(now));
  159. ExeFilePath := ExtractFilePath(ParamStr(0));
  160. Counter := 0;
  161. InitSumOfDigit6;
  162. ReadStatus;
  163. WriteLog('完成初始化: ' + DateTimeToStr(now));
  164. WriteLn('完成初始化: ' + DateTimeToStr(now));
  165. repeat
  166. TEST;
  167. INC(Counter);
  168. if Counter >= 10000000000 then
  169. begin
  170. WriteStatus;
  171. Counter := 0;
  172. end;
  173. until FALSE;
  174. 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-11-15 06:50 , Processed in 0.025430 second(s), 15 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

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