source code
/* The Computer Language Benchmarks Game
https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
Naive transliteration from Sebastien Loisel's C program
contributed by Isaac Gouy
*/
class SpectralNorm
{
double eval_A(int i, int j) { return 1.0/((i+j)*(i+j+1)/2+i+1); }
void eval_A_times_u(int N, double[] u, double[] Au)
{
int i,j;
for(i=0;i<N;i++)
{
Au[i]=0;
for(j=0;j<N;j++) Au[i]+=eval_A(i,j)*u[j];
}
}
void eval_At_times_u(int N, double[] u, double[] Au)
{
int i,j;
for(i=0;i<N;i++)
{
Au[i]=0;
for(j=0;j<N;j++) Au[i]+=eval_A(j,i)*u[j];
}
}
void eval_AtA_times_u(int N, double[] u, double[] AtAu)
{ var v = new double[N]; eval_A_times_u(N,u,v); eval_At_times_u(N,v,AtAu); }
public static void Main(String[] args)
{
int i;
int N = args.Length > 0 ? Int32.Parse(args[0]) : 100;
var nonStatic = new SpectralNorm();
var u = new double[N];
var v = new double[N];
double vBv, vv;
for (i=0; i<N; i++) u[i] = 1;
for(i=0; i<10; i++)
{
nonStatic.eval_AtA_times_u(N,u,v);
nonStatic.eval_AtA_times_u(N,v,u);
}
vBv = vv = 0;
for(i=0; i<N; i++) { vBv += u[i]*v[i]; vv += v[i]*v[i]; }
Console.WriteLine("{0:f9}", Math.Sqrt(vBv/vv));
}
}
notes, command-line, and program output
NOTES:
64-bit Ubuntu quad core
.NET SDK 9.0.100
Host Version: 9.0.0
Commit: 9d5a6a9aa4
<OutputType>Exe
<TargetFramework>net9.0
<ImplicitUsings>enable
<Nullable>enable
<AllowUnsafeBlocks>true
<ServerGarbageCollection>true
<ConcurrentGarbageCollection>true
<PublishAot>false
Wed, 13 Nov 2024 23:15:41 GMT
MAKE:
cp spectralnorm.csharpcore-8.csharpcore Program.cs
cp Include/csharpcore/program.csproj .
mkdir obj
cp Include/csharpcore/project.assets.json ./obj
/opt/src/dotnet-sdk-9.0.100/dotnet build -c Release --use-current-runtime
Determining projects to restore...
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
Restored /home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj (in 6.34 sec).
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
program -> /home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/bin/Release/net9.0/linux-x64/program.dll
Build succeeded.
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
/home/dunham/all-benchmarksgame/benchmarksgame_i53330/spectralnorm/tmp/program.csproj : warning NU1900: Error occurred while getting package vulnerability data: Unable to load the service index for source https://api.nuget.org/v3/index.json.
2 Warning(s)
0 Error(s)
Time Elapsed 00:00:11.36
13.38s to complete and log all make actions
COMMAND LINE:
./bin/Release/net9.0/linux-x64/program 5500
PROGRAM OUTPUT:
1.274224153