Commit f4f685f2 authored by igouy-guest's avatar igouy-guest

*** empty log message ***


SKIPPED:
	website/websites/u64q/code/mandelbrot.7.ifc.code
	website/websites/u64q/code/mandelbrot.7.ifc.log
	website/websites/u64q/code/nbody.4.swift.code
	website/websites/u64q/code/nbody.4.swift.log
	website/websites/u64q/code/nbody.9.csharpcore.code
	website/websites/u64q/code/nbody.9.csharpcore.log
	website/websites/u64q/data/data.csv
	website/websites/u64q/data/ndata.csv
	website/websites/u64q/data/u64q_bulkdata.csv.bz2
parent 4d425327
! The Computer Language Benchmarks Game
! http://benchmarksgame.alioth.debian.org/
!
! contributed by Pascal Parois
program mandelbrot
implicit none
integer, parameter :: iter = 50, vsize=48
integer, parameter :: int8 = selected_int_kind(2)
integer, parameter :: dp = selected_real_kind(15, 307)
integer :: i, j,k,l, pos
real(dp),dimension(vsize) :: cr,ci,zr,zi,tr,ti
real(dp) cte
integer :: bytepos, grid
integer(int8) :: byte
character(len=:), dimension(:),allocatable :: buf ! character buffer to avoid integer formatting on output
integer w
character(len=8) :: argv
character(len=100) :: sbuffer, formatstr
real(dp), parameter :: threshold = 4.0_dp
call get_command_argument(1, argv)
read(argv, *) w
grid=ceiling(w/real(vsize))*vsize
allocate(character(len=grid/8) :: buf(w))
buf=''
cte=2.0_dp/real(w,dp)
!$omp parallel do default(none) shared(grid, buf, cte, w)&
!$omp& private(i, j, k, bytepos, pos, byte)&
!$omp& private(zr, zi, cr, ci, tr, ti)&
!$omp& schedule(guided)
do i=0, w-1
pos=0
byte=0_int8
bytepos=8
do j = 0, grid-1,vsize
ci = cte*real(i,dp)-1.0_dp
do k=0, vsize-1
cr(k+1) = cte*real(j+k,dp)-1.5_dp
end do
zr=0.0_dp
zi=0.0_dp
tr=0.0_dp
ti=0.0_dp
do k=1, iter
zi=2.0_dp*zr*zi+ci
zr=tr-ti+cr
ti=zi*zi
tr=zr*zr
if (all(tr+ti>threshold)) then
exit
end if
end do
do k=1, vsize
bytepos=bytepos-1
if (.not. isnan(tr(k)+ti(k)) .and. tr(k)+ti(k)<threshold .and. j<=w) then
byte = ibset(byte, bytepos)
end if
if(bytepos==0) then
bytepos=8
pos = pos + 1
buf(i+1)(pos:pos) = transfer(byte, 'a')
byte=0_int8
end if
end do
end do
end do
!$omp end parallel do
! pbm header
write(*,'("P4",/,i0," ",i0)') w, w
! print output
write(formatstr, '(A,I0,A)') '(A',ceiling(w/8.0),')'
do i = 1, w
write(*, formatstr, advance='no') buf(i)(1:ceiling(w/8.0))
end do
end program mandelbrot
/* The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
Contributed by Robert F. Tobler
Modified to use SIMD vectors by Anthony Lloyd and Paul Westcott
*/
using System;
using System.Numerics;
using System.Runtime.CompilerServices;
public static class NBody
{
const double dt = 0.01;
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static double[] createBodies()
{
const double Pi = 3.141592653589793;
const double Solarmass = 4 * Pi * Pi;
const double DaysPeryear = 365.24;
const double jmass = 9.54791938424326609e-04 * Solarmass;
const double jvx = 1.66007664274403694e-03 * DaysPeryear;
const double jvy = 7.69901118419740425e-03 * DaysPeryear;
const double jvz = -6.90460016972063023e-05 * DaysPeryear;
const double smass = 2.85885980666130812e-04 * Solarmass;
const double svx = -2.76742510726862411e-03 * DaysPeryear;
const double svy = 4.99852801234917238e-03 * DaysPeryear;
const double svz = 2.30417297573763929e-05 * DaysPeryear;
const double umass = 4.36624404335156298e-05 * Solarmass;
const double uvx = 2.96460137564761618e-03 * DaysPeryear;
const double uvy = 2.37847173959480950e-03 * DaysPeryear;
const double uvz = -2.96589568540237556e-05 * DaysPeryear;
const double nmass = 5.15138902046611451e-05 * Solarmass;
const double nvx = 2.68067772490389322e-03 * DaysPeryear;
const double nvy = 1.62824170038242295e-03 * DaysPeryear;
const double nvz = -9.51592254519715870e-05 * DaysPeryear;
return new double[] {
// sun
(jvx * jmass + svx * smass + uvx * umass + nvx * nmass)/-Solarmass,
(jvy * jmass + svy * smass + uvy * umass + nvy * nmass)/-Solarmass,
(jvz * jmass + svz * smass + uvz * umass + nvz * nmass)/-Solarmass,
0.0,
0.0, 0.0, 0.0, 0.0,
Solarmass,
// jupiter
jvx, jvy, jvz, 0.0,
4.84143144246472090e+00, -1.16032004402742839e+00, -1.03622044471123109e-01, 0.0,
jmass,
// saturn
svx, svy, svz, 0.0,
8.34336671824457987e+00, 4.12479856412430479e+00, -4.03523417114321381e-01, 0.0,
smass,
// uranus
uvx, uvy, uvz, 0.0,
1.28943695621391310e+01, -1.51111514016986312e+01, -2.23307578892655734e-01, 0.0,
umass,
// neptune
nvx, nvy, nvz, 0.0,
1.53796971148509165e+01, -2.59193146099879641e+01, 1.79258772950371181e-01, 0.0,
nmass,
};
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static double energy(double[] bodies)
{
double e = 0.0;
for(int i=0; i<bodies.Length; i+=9)
{
var Vi = new Vector<double>(bodies,i);
var Xi = new Vector<double>(bodies,i+4);
var imass = bodies[i+8];
e += 0.5 * imass * Vector.Dot(Vi,Vi);
for(int j=i+9; j<bodies.Length; j+=9)
{
var DX = Xi - new Vector<double>(bodies,j+4);
e -= imass * bodies[j+8] / Math.Sqrt(Vector.Dot(DX,DX));
}
}
return e;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
static void advance(double[] bodies)
{
for(int i=0; i<bodies.Length; i+=9)
{
var Vi = new Vector<double>(bodies,i);
var Xi = new Vector<double>(bodies,i+4);
var MASSi = new Vector<double>(bodies[i+8]);
for(int j=i+9; j<bodies.Length; j+=9)
{
var DX = new Vector<double>(bodies,j+4) - Xi;
var d2 = Vector.Dot(DX, DX);
var MAG = new Vector<double>(dt / (d2 * Math.Sqrt(d2)));
var MASSj = new Vector<double>(bodies[j+8]);
Vi += DX * MASSj * MAG;
(new Vector<double>(bodies,j) - DX * MASSi * MAG).CopyTo(bodies,j);
}
(Vi * dt + Xi).CopyTo(bodies,i+4);
Vi.CopyTo(bodies,i);
}
}
public static void Main(String[] args)
{
var bodies = createBodies();
Console.Out.WriteLineAsync(energy(bodies).ToString("F9"));
int n = args.Length > 0 ? Int32.Parse(args[0]) : 10000;
while(n-->0) advance(bodies);
Console.Out.WriteLineAsync(energy(bodies).ToString("F9"));
}
}
/* The Computer Language Benchmarks Game
http://benchmarksgame.alioth.debian.org/
contributed by Ralph Ganszky
Added dummy element to tuple (because I read an article that this helps
to block less writing back to memory) and store data in
UnsafedMutablePointer to reduce overhead of array access.
*/
import Foundation
typealias Body = (r: (x: Double, y: Double, z: Double),
v: (x: Double, y: Double, z: Double),
m: Double, d: Double)
let nPlanets = 5
let SOLAR_MASS = 4 * Double.pi * Double.pi
let DAYS_PER_YEAR = 365.24
var sun = Body( r: (x: 0.0, y: 0.0, z: 0.0),
v: (x: 0.0, y: 0.0, z: 0.0),
m: SOLAR_MASS, d: 0.0 )
var jupiter = ( r: (x: 4.8414314424647209,
y: -1.16032004402742839,
z: -0.103622044471123109),
v: (x: 1.66007664274403694e-03 * DAYS_PER_YEAR,
y: 7.69901118419740425e-03 * DAYS_PER_YEAR,
z: -6.90460016972063023e-05 * DAYS_PER_YEAR),
m: 9.54791938424326609e-04 * SOLAR_MASS, d: 0.0 )
var saturn = ( r: (x: 8.34336671824457987,
y: 4.12479856412430479,
z: -4.03523417114321381e-01),
v: (x: -2.76742510726862411e-03 * DAYS_PER_YEAR,
y: 4.99852801234917238e-03 * DAYS_PER_YEAR,
z: 2.30417297573763929e-05 * DAYS_PER_YEAR),
m: 2.85885980666130812e-04 * SOLAR_MASS, d: 0.0 )
var uranus = ( r: (x: 1.28943695621391310e+01,
y: -1.51111514016986312e+01,
z: -2.23307578892655734e-01),
v: (x: 2.96460137564761618e-03 * DAYS_PER_YEAR,
y: 2.37847173959480950e-03 * DAYS_PER_YEAR,
z: -2.96589568540237556e-05 * DAYS_PER_YEAR),
m: 4.36624404335156298e-05 * SOLAR_MASS, d: 0.0 )
var neptune = ( r: (x: 1.53796971148509165e+01,
y: -2.59193146099879641e+01,
z: 1.79258772950371181e-01),
v: (x: 2.68067772490389322e-03 * DAYS_PER_YEAR,
y: 1.62824170038242295e-03 * DAYS_PER_YEAR,
z: -9.51592254519715870e-05 * DAYS_PER_YEAR),
m: 5.15138902046611451e-05 * SOLAR_MASS, d: 0.0 )
var bodies = UnsafeMutablePointer<Body>.allocate(capacity: nPlanets)
defer {
bodies.deallocate(capacity: nPlanets)
}
bodies[0] = sun
bodies[1] = jupiter
bodies[2] = saturn
bodies[3] = uranus
bodies[4] = neptune
func advance(_ bodies: UnsafeMutablePointer<Body>, n: Int, dt: Double) {
for i in 0..<n {
let iBody = bodies[i]
for j in i+1..<n {
let jBody = bodies[j]
let (dx, dy, dz) = (iBody.r.x - jBody.r.x,
iBody.r.y - jBody.r.y,
iBody.r.z - jBody.r.z)
let dSquared = dx*dx + dy*dy + dz*dz
let distance = sqrt(dSquared)
let mag = dt / (dSquared * distance)
bodies[i].v = (bodies[i].v.x - dx * jBody.m * mag,
bodies[i].v.y - dy * jBody.m * mag,
bodies[i].v.z - dz * jBody.m * mag)
bodies[j].v = (bodies[j].v.x + dx * iBody.m * mag,
bodies[j].v.y + dy * iBody.m * mag,
bodies[j].v.z + dz * iBody.m * mag)
}
}
for i in 0..<n {
bodies[i].r = (bodies[i].r.x + dt * bodies[i].v.x,
bodies[i].r.y + dt * bodies[i].v.y,
bodies[i].r.z + dt * bodies[i].v.z)
}
}
func energy(_ bodies: UnsafeMutablePointer<Body>, n: Int) -> Double {
var energy = 0.0
for i in 0..<n {
let ibody = bodies[i]
energy += 0.5 * ibody.m * ( ibody.v.x * ibody.v.x +
ibody.v.y * ibody.v.y +
ibody.v.z * ibody.v.z)
for j in i+1..<n {
let jbody = bodies[j]
let dx = ibody.r.x - jbody.r.x
let dy = ibody.r.y - jbody.r.y
let dz = ibody.r.z - jbody.r.z
let distance = sqrt(dx*dx + dy*dy + dz*dz)
energy -= (ibody.m * jbody.m) / distance
}
}
return energy
}
let n: Int
if CommandLine.argc > 1 {
n = Int(CommandLine.arguments[1]) ?? 1000
} else {
n = 1000
}
// Adjust momentum of the sun
var p = (0.0, 0.0, 0.0)
for i in 0..<nPlanets {
p.0 += bodies[i].v.x * bodies[i].m
p.1 += bodies[i].v.y * bodies[i].m
p.2 += bodies[i].v.z * bodies[i].m
}
bodies[0].1 = (-p.0 / SOLAR_MASS, -p.1 / SOLAR_MASS, -p.2 / SOLAR_MASS)
print(String(format: "%.9f", energy(bodies, n: nPlanets)))
for _ in 0..<n {
advance(bodies, n: nPlanets, dt: 0.01)
}
print(String(format: "%.9f", energy(bodies, n: nPlanets)))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment