Jump to content

Pythagorean quadruples: Difference between revisions

m
→‎{{header|Pascal}}: Give i386 a chance und improved runtime for both Cpu64/Cpu32 :-)
m (→‎{{header|Pascal}}: changed link to Ring version ( estimated runtime in pascal 8h10min (run outer loop 1..32 in 427783 ms ( 2 cpu-cycles per Test ) ) did it ever run?)
m (→‎{{header|Pascal}}: Give i386 a chance und improved runtime for both Cpu64/Cpu32 :-))
Line 1,123:
</pre>
=={{header|Pascal}}==
{{works with|freeFree pascalPascal}} Brute froce, but not as brute as [http://rosettacode.org/mw/index.php?title=Pythagorean_quadruples#Ring Ring].Did Stoppingit searchever if limit is reachedrun?<BR>
Stopping search if limit is reached<BR>
Running on Linux64 the CPU32 runs very slow.
<lang pascal>program pythQuad;
//find phythagorean Quadrupel up to a,b,c,d <= 2200
Line 1,131:
//brute force
//split in two procedure to reduce register pressure for CPU32
//23s -> 18,4 s no impact for CPU64
//{$CODEALIGN LOCALMIN=16}{$SAFEFPUEXCEPTIONS OFF/ON} no effect
//compiled with ppcx64 / ppc386 -O4 -Xs
 
const
MaxFactor = 2200;
limit = MaxFactor*MaxFactor;
type
Line 1,146 ⟶ 1,143:
checkCnt : LongWord;
 
procedure Find1Find2(s:tSum;idx:tSum);
//second sum (a*a+b*b) +c*c =?= d*d
var
s1 : tSum;
posSprd : tSum;
begin
d := trunc(sqrt(s+idx*idx));// calculate first sqrt
For idx := idx to MaxFactor do
Begin
Line 1,156 ⟶ 1,155:
If s1 <= limit then
Begin
posSprwhile :=s1 idx;> d*d do //dummy to comment outadjust thesqrt next row
posSpr := roundinc(sqrt(s1)d);
inc(checkCnt); // do something while waiting for posSqr
IF posSpr*posSpr=s1=d*d then
check[posSprd] := true;
end
else
Line 1,167 ⟶ 1,166:
end;
 
procedure Find0Find1;
//first sum a*a+b*b
var
ia,jb : tIdx;
s0,s1s : tSum;
begin
For ia := 1 to MaxFactor do
For jb := ia to MaxFactor do
Begin
s0 := i*i;
For j := i to MaxFactor do
Begin
s1s := ja*ja+s0b*b;
if s1s < limit then
Find1(s1s,jb)
else
break;
end;
end;
end;
 
Line 1,189 ⟶ 1,186:
i : NativeUint;
begin
find0Find1;
 
For i := 1 to MaxFactor do
If Not(Check[i]) then
Line 1,199 ⟶ 1,197:
{{out}}
<pre>
CPU64:
1 2 4 5 8 10 16 20 32 40 64 80 128 160 256 320 512 640 1024 1280 2048
929605937 checks were done
real 0m2.638s -> 10,5 cpucycles per check ( Ryzen 5 1600 3,7 Ghz )
 
CPU32:
1 2 4 5 8 10 16 20 32 40 64 80 128 160 256 320 512 640 1024 1280 2048
929605937 checks were done
real 0m180m2.370s323s -> 73,59 cpucyclescpu-cycles per check on Ryzen 5 1600 3,7 Ghz ( Turbo )
lost in row: posSpr := round(sqrt(s1));
</pre>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.