无心人
发表于 2008-7-15 08:19:58
:)
你如果ICC编译你以前的未手工展开的代码
效果如何?
我昨天的测试也说了,icc编译后慢于你以前代码
因为我的代码基本没改你代码结构
gxqcn
发表于 2008-7-15 08:54:59
原帖由 无心人 于 2008-7-15 08:19 发表 http://bbs.emath.ac.cn/images/common/back.gif
你如果ICC编译你以前的未手工展开的代码
效果如何?
测试结果如下:
code \ compilerMSCICC72#405.658378 s309.397843 s96#213.489686 s285.919940 s
完全遍历 10^20 以内的完全平方数
其中,96# 与 72# 的区别仅在于,前者是将后者代码中的循环手工展开而已。
无心人
发表于 2008-7-15 09:24:50
机器软硬件情况
包括操作系统
编译器版本
gxqcn
发表于 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 ProfessionalService 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简单
呵呵program square;
{\$APPTYPE CONSOLE}
uses
SysUtils;
const
Ten6 = 1000000;
StatusFileName = 'Square.Status';
LogFileName = 'Square.Log';
type
TStatus = record
S: array of byte; //448 Byte
Sum: array of integer; //32 Byte
SumMax: integer; //4 byte;
Delta: array of integer;//32 Byte
DeltaMax: integer; //4 byte
end;
var
Status: TStatus;
StatusFile: File of TStatus;
LogFile: TextFile;
SumOfDigit6: array of integer;
ExeFilePath: string;
Counter: Int64;
procedure WriteLog(s: string);
begin
AssignFile(LogFile, ExeFilePath + LogFileName);
if FileExists(ExeFilePath + LogFileName) then
Append(LogFile)
else
Rewrite(LogFile);
writeln(LogFile, s);
Close(LogFile);
end;
procedure InitStatus;
var
i: integer;
begin
for I := 0 to 447 do
Status.s := 0;
for i := 0 to 7 do
begin
status.sum := 0;
status.delta := 0;
end;
Status.Delta := 1;
Status.SumMax := 0;
Status.DeltaMax := 0;
end;
procedure ReadStatus;
begin
AssignFile(StatusFile, ExeFilePath + StatusFileName);
if FileExists(ExeFilePath + StatusFileName) then
begin
Reset(StatusFile);
Read(StatusFile, Status);
Close(StatusFile);
end
else
InitStatus;
end;
procedure WriteStatus;
begin
AssignFile(StatusFile, ExeFilePath + StatusFileName);
if FileExists(ExeFilePath + StatusFileName) then
Rewrite(StatusFile)
else
Reset(StatusFile);
Write(StatusFile, Status);
Close(StatusFile);
end;
procedure AddDelta;
var
i: integer;
begin
for I := 0 to Status.SumMax do
begin
Status.Sum := Status.Sum + Status.Delta;
end;
for I := 0 to Status.SumMax do
if Status.Sum >= TEN6 then
if i <= 7 then
begin
Status.Sum := Status.Sum - TEN6;
INC(Status.Sum);
end
else
begin
WriteLog(DateTimeToStr(now) + ': SUM is TOO Big!!');
exit;
end;
if Status.Sum > 0 then
INC(Status.SumMax);
end;
procedure IncDelta;
var
i: integer;
begin
Status.Delta := Status.Delta + 2;
for I := 0 to Status.DeltaMax do
if Status.Delta >= TEN6 then
begin
if i < 7 then
begin
Status.Delta := Status.Delta - TEN6;
INC(Status.Delta);
end
else
begin
WriteLog('Delta is TOO Big!');
exit;
end;
end;
end;
procedure InitSumOfDigit6;
var
i5, i4, i3, i2, i1, i0, k: integer;
begin
k := 0;
for I5 := 0 to 9 do
for I4 := 0 to 9 do
for I3 := 0 to 9 do
for I2 := 0 to 9 do
for I1 := 0 to 9 do
for I0 := 0 to 9 do
begin
SumOfDigit6 := i5 + i4 + i3 + i2 + i1 + i0;
INC(k);
end;
end;
procedure ProgressSum;
var
i: integer;
s: integer;
Str: String;
begin
s := 0;
for I := 0 to Status.SumMax do
s := s + SumOfDigit6];
if (Status.S = 0) then
begin
Status.S := 1;
for I := Status.SumMax downto 0 do
Str := str + Format('%06d', ]);
writeln(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
writelog(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
end;
end;
procedure TEST;
begin
AddDelta;
ProgressSum;
IncDelta;
end;
begin
{ TODO -oUser -cConsole Main : Insert code here }
//
WriteLog('程序启动: ' + DateTimeToStr(now));
WriteLn('程序启动: ' + DateTimeToStr(now));
ExeFilePath := ExtractFilePath(ParamStr(0));
Counter := 0;
InitSumOfDigit6;
ReadStatus;
WriteLog('完成初始化: ' + DateTimeToStr(now));
WriteLn('完成初始化: ' + DateTimeToStr(now));
repeat
TEST;
INC(Counter);
if Counter >= 10000000000 then
begin
WriteStatus;
Counter := 0;
end;
until FALSE;
end.
无心人
发表于 2008-7-28 10:05:21
令人郁闷的是,怎么速度比C代码慢很多啊???
gxqcn
发表于 2008-7-28 10:34:55
估计主要原因是你上面用的array太大(1000000个int),
无法一次性装入CPU的cache 所致。
无心人
发表于 2008-7-28 11:04:23
确实是
修改好了
正式挂
呵呵
差点因此失去用Pascal的信心
要知道用C写处理结构存储的
程序就比Pascal麻烦多了
呵呵program square;
{\$APPTYPE CONSOLE}
uses
SysUtils;
const
TenPower = 10000;
StatusFileName = 'Square.Status';
LogFileName = 'Square.Log';
BlockSize = 8;
BoolSize = 320;
type
TStatus = record
S: array of byte; //320 Byte
Sum: array of integer; //32 Byte
SumMax: integer; //4 byte;
Delta: array of integer;//32 Byte
DeltaMax: integer; //4 byte
end;
var
Status: TStatus;
StatusFile: File of TStatus;
LogFile: TextFile;
SumOfDigit4: array of byte;
ExeFilePath: string;
Counter: Integer;
procedure WriteLog(s: string);
begin
AssignFile(LogFile, ExeFilePath + LogFileName);
if FileExists(ExeFilePath + LogFileName) then
Append(LogFile)
else
Rewrite(LogFile);
writeln(LogFile, s);
Close(LogFile);
end;
procedure InitStatus;
var
i: integer;
begin
for I := 0 to BoolSize-1 do
Status.s := 0;
for i := 0 to BlockSize-1 do
begin
status.sum := 0;
status.delta := 0;
end;
Status.Delta := 1;
Status.SumMax := 0;
Status.DeltaMax := 0;
end;
procedure ReadStatus;
begin
AssignFile(StatusFile, ExeFilePath + StatusFileName);
if FileExists(ExeFilePath + StatusFileName) then
begin
Reset(StatusFile);
Read(StatusFile, Status);
Close(StatusFile);
end
else
InitStatus;
end;
procedure WriteStatus;
begin
AssignFile(StatusFile, ExeFilePath + StatusFileName);
Rewrite(StatusFile);
Write(StatusFile, Status);
Close(StatusFile);
end;
procedure InitSumOfDigit4;
var
i3, i2, i1, i0, k: integer;
begin
k := 0;
for I3 := 0 to 9 do
for I2 := 0 to 9 do
for I1 := 0 to 9 do
for I0 := 0 to 9 do
begin
SumOfDigit4 := i3 + i2 + i1 + i0;
INC(k);
end;
end;
var
i, s: integer;
Str: String;
begin
{ TODO -oUser -cConsole Main : Insert code here }
//
WriteLog('程序启动: ' + DateTimeToStr(now));
WriteLn('程序启动: ' + DateTimeToStr(now));
ExeFilePath := ExtractFilePath(ParamStr(0));
Counter := 0;
InitSumOfDigit4;
ReadStatus;
WriteLog('完成初始化: ' + DateTimeToStr(now));
WriteLn('完成初始化: ' + DateTimeToStr(now));
repeat
// TEST;
//ADDDelta
for I := 0 to Status.SumMax do
begin
Status.Sum := Status.Sum + Status.Delta;
end;
for I := 0 to Status.SumMax do
if Status.Sum >= TenPower then
if i <= BlockSize-1 then
begin
Status.Sum := Status.Sum - TenPower;
INC(Status.Sum);
end
else
begin
WriteLog(DateTimeToStr(now) + ': 平方和缓冲溢出!!');
WriteLn(DateTimeToStr(now) + ': 平方和缓冲溢出!!');
exit;
end;
if Status.Sum > 0 then
INC(Status.SumMax);
//ProgressSum;
s := 0;
for I := 0 to Status.SumMax do
s := s + SumOfDigit4];
if (Status.S = 0) then
begin
Status.S := 1;
Str := '';
for i := Status.SumMax downto 0 do
Str := str + Format('%04d', ]);
writeln(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
writelog(DateTimeToStr(now) + ': ' + IntToStr(s) + ' ' + str);
end;
//IncDelta;
Status.Delta := Status.Delta + 2;
for I := 0 to Status.DeltaMax do
if Status.Delta >= TenPower then
begin
Status.Delta := Status.Delta - TenPower;
INC(Status.Delta);
end;
if Status.Delta > 0 then
INC(Status.DeltaMax);
INC(Counter);
if Counter = 0 then
WriteStatus;
until FALSE;
end.
无心人
发表于 2008-7-28 14:56:56
运行到了181时是3小时10分钟左右吧
看来我要在72小时后再去收集结果
否则不可能超越GxQ
在考虑下是否要加点SSE2
不知Delphi10支持SSE2汇编么?
另外C有否比较简单的结构存盘的方法?
还有,把程序放2003的计划任务里了
设定的是启动后执行
也不知道停电后启动时候是否能如愿执行
也没测试状态恢复得了么?
呵呵,祈祷学校7天不停电
或者我程序能成功恢复状态
程序启动: 2008-7-28 11:24:29
完成初始化: 2008-7-28 11:24:29
2008-7-28 11:24:29: 1 1
2008-7-28 11:24:29: 4 4
2008-7-28 11:24:29: 9 9
2008-7-28 11:24:29: 7 16
2008-7-28 11:24:29: 13 49
2008-7-28 11:24:29: 10 64
2008-7-28 11:24:29: 16169
2008-7-28 11:24:29: 19289
2008-7-28 11:24:29: 18576
2008-7-28 11:24:29: 22 1849
2008-7-28 11:24:29: 27 3969
2008-7-28 11:24:29: 25 4489
2008-7-28 11:24:29: 31 6889
2008-7-28 11:24:29: 28 17956
2008-7-28 11:24:29: 34 27889
2008-7-28 11:24:29: 36 69696
2008-7-28 11:24:29: 40 97969
2008-7-28 11:24:29: 37 98596
2008-7-28 11:24:29: 43 499849
2008-7-28 11:24:29: 46 698896
2008-7-28 11:24:29: 451887876
2008-7-28 11:24:29: 492778889
2008-7-28 11:24:29: 524999696
2008-7-28 11:24:29: 549696996
2008-7-28 11:24:29: 55 19998784
2008-7-28 11:24:29: 58 46689889
2008-7-28 11:24:29: 61 66699889
2008-7-28 11:24:29: 63 79869969
2008-7-28 11:24:29: 64 277788889
2008-7-28 11:24:29: 67 478996996
2008-7-28 11:24:29: 70 876988996
2008-7-28 11:24:29: 73 1749999889
2008-7-28 11:24:29: 72 3679999569
2008-7-28 11:24:29: 76 5599977889
2008-7-28 11:24:29: 79 7998976969
2008-7-28 11:24:30: 81 8998988769
2008-7-28 11:24:30: 8217999978896
2008-7-28 11:24:30: 8536799899889
2008-7-28 11:24:30: 8888998998929
2008-7-28 11:24:30: 90 297889998849
2008-7-28 11:24:30: 91 299879997769
2008-7-28 11:24:30: 94 897977978689
2008-7-28 11:24:30: 97 975979998889
2008-7-28 11:24:30: 100 2699997789889
2008-7-28 11:24:30: 99 3957779999889
2008-7-28 11:24:30: 103 9879498789889
2008-7-28 11:24:30: 106 9998768898889
2008-7-28 11:24:30: 108 29998985899689
2008-7-28 11:24:30: 109 85986989688889
2008-7-28 11:24:30: 112 97888999968769
2008-7-28 11:24:31: 115386999898769969
2008-7-28 11:24:31: 117429998989997889
2008-7-28 11:24:31: 118578889999977689
2008-7-28 11:24:32: 121898999897988929
2008-7-28 11:24:32: 124 1959999889996996
2008-7-28 11:24:33: 127 3699998989898689
2008-7-28 11:24:35: 126 6788999798879769
2008-7-28 11:24:36: 130 9895699989899689
2008-7-28 11:24:43: 133 38896878989988889
2008-7-28 11:24:43: 136 38999699989995889
2008-7-28 11:24:47: 135 67699789959899889
2008-7-28 11:25:00: 139 188997899869998769
2008-7-28 11:25:07: 142 279869897899999969
2008-7-28 11:25:19: 144 498999778899898896
2008-7-28 11:25:40: 148 989879999979599689
2008-7-28 11:26:06: 1451877896979979898969
2008-7-28 11:27:27: 1535899989587897999889
2008-7-28 11:27:44: 1516979497898999879969
2008-7-28 11:28:08: 1548899988895999696889
2008-7-28 11:30:56: 157 28979978999958969889
2008-7-28 11:35:38: 160 78897999969769888996
2008-7-28 11:36:25: 162 87989899898866889889
2008-7-28 11:42:54: 163 199989299899788979969
2008-7-28 11:52:44: 166 449998999899988698769
2008-7-28 12:02:57: 171 789899899796987988996
2008-7-28 12:07:14: 169 969988797999759789889
2008-7-28 12:47:35: 172 3599979999987777888889
2008-7-28 13:01:41: 175 4899976999986989889796
2008-7-28 13:36:48: 178 8889998799995887887889
2008-7-28 13:44:25: 180 9899698989999989958489
2008-7-28 14:33:48: 18117989999975899879969889
刚算的,似乎一秒处理是10000000个数字,少的多
需要52小时达到GxQ的最新的结果,呵呵