Commit eb9f4a3f authored by tibbe's avatar tibbe

Removed some shootout benchmarks from under fibon

Newer versions (corresponding to what's currently on the shootout page)
have been added under nofib/shootout in an attempt to make these easier
to run.
parent c82455fe
stretch tree of depth 20 check: -1
1048576 trees of depth 4 check: -1048576
262144 trees of depth 6 check: -262144
65536 trees of depth 8 check: -65536
16384 trees of depth 10 check: -16384
4096 trees of depth 12 check: -4096
1024 trees of depth 14 check: -1024
256 trees of depth 16 check: -256
64 trees of depth 18 check: -64
long lived tree of depth 19 check: -1
Copyright Don Stewart 2010
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Don Stewart nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TOP = ../../..
include $(TOP)/mk/boilerplate.mk
SRCS = binarytrees.hs
PROG_ARGS += 19 +RTS -K32M -RTS
HC_OPTS += -i. -package base
include $(TOP)/mk/target.mk
--
-- The Great Computer Language Shootout
-- http://shootout.alioth.debian.org/
--
-- Contributed by Don Stewart
--
import System.Environment
data Tree = Nil | Node !Int Tree Tree
minN :: Int
minN = 4
io s n t = putStrLn $ s ++ " of depth "++show n++ "\t check: " ++ show t
main = do
n <- fmap (read . head) getArgs
let maxN = max (minN + 2) n
stretchN = maxN + 1
-- stretch memory tree
let c = check (make 0 stretchN)
io "stretch tree" stretchN c
-- allocate a long lived tree
let long = make 0 maxN
-- allocate, walk, and deallocate many bottom-up binary trees
let vs = depth minN maxN
mapM_ (\((m,d,i)) -> io (show m ++ "\t trees") d i) vs
-- confirm the the long-lived binary tree still exists
io "long lived tree" maxN (check long)
return ()
-- generate many trees
depth :: Int -> Int -> [(Int,Int,Int)]
depth d m
| d <= m = (2*n,d,sumT d n 0) : depth (d+2) m
| otherwise = []
where n = 2 ^ (m - d + minN) :: Int
-- allocate and check lots of trees
sumT :: Int -> Int -> Int -> Int
sumT d i t | d `seq` False = undefined -- strictness hint
sumT d 0 t = t
sumT d i t = sumT d (i-1) (t + a + b)
where a = check (make i d)
b = check (make (-i) d)
-- traverse the tree, counting up the nodes
check :: Tree -> Int
check Nil = 0
check (Node i l r) = i + check l - check r
-- build a tree
make :: Int -> Int -> Tree
make i 0 = Node i Nil Nil
make i d = Node i (make (i2-1) d2) (make i2 d2)
where i2 = 2*i; d2 = d-1
......@@ -2,8 +2,7 @@ TOP = ../..
include $(TOP)/mk/boilerplate.mk
SSUBDIRS = \
BinaryTrees ChameneosRedux Fannkuch Mandelbrot \
Nbody Pidigits SpectralNorm
ChameneosRedux Fannkuch Mandelbrot \
SUBDIRS = $(filter-out $(NOT_THESE), $(SSUBDIRS))
......
Copyright Olof Kraigher, Don Stewart 2010
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Olof Kraigher, Don Stewart nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TOP = ../../..
include $(TOP)/mk/boilerplate.mk
SRCS = nbody.hs
PROG_ARGS += 10000000
HC_OPTS += -i. -package base
include $(TOP)/mk/target.mk
{-# OPTIONS_GHC -fexcess-precision #-}
--
-- The Computer Language Shootout
-- http://shootout.alioth.debian.org/
--
-- Contributed by Olof Kraigher, with help from Don Stewart.
--
-- Compile with:
--
-- -funbox-strict-fields -fglasgow-exts -fbang-patterns -O3
-- -optc-O3 -optc-mfpmath=sse -optc-msse2 -optc-march=pentium4
--
import Foreign
import Foreign.Storable
import Foreign.Marshal.Alloc
import Data.IORef
import Control.Monad
import System.Environment
import Text.Printf
main = do
n <- getArgs >>= readIO.head
initialize
offset_momentum
energy 0 planets >>= printf "%.2f\n"
replicateM_ n (advance planets)
energy 0 planets >>= printf "%.2f\n"
return ()
offset_momentum = do
m <- foldr (.+.) (Vec 0 0 0)
`fmap` (mapM momentum
. take (nbodies - 1)
. iterate next $ next planets)
setVec (vel planets) $ (-1/solar_mass) *. m
where
momentum p = p `seq` liftM2 (*.) (mass p) (getVec (vel p))
energy :: Double -> Ptr Double -> IO Double
energy e p
| e `seq` p `seq` False = undefined
| p == end = return e
| otherwise = do
p1 <- getVec (pos p)
v1 <- getVec (vel p)
m1 <- mass p
e <- energy2 p1 m1 e p2
energy (e + 0.5 * m1 * magnitude2 v1) p2
where p2 = next p
energy2 p1 m1 e p
| p1 `seq` m1 `seq` e `seq` p `seq` False = undefined
| p == end = return e
| otherwise = do
p2 <- getVec (pos p)
v2 <- getVec (vel p)
m2 <- mass p
let distance = sqrt . magnitude2 $ p1 .-. p2
energy2 p1 m1 (e - m1 * m2 / distance) (next p)
advance :: Ptr Double -> IO ()
advance p1 | p1 `seq` False = undefined
advance p1 = when (p1 /= end) $ do
pos1 <- getVec $ pos p1
m1 <- mass p1
let go p2
| p2 `seq` False = undefined
| p2 /= end = do
pos2 <- getVec (pos p2)
m2 <- mass p2
let vel2 = vel p2
difference = pos1 .-. pos2
distance2 = magnitude2 difference
distance = sqrt distance2
magnitude = delta_t / (distance2 * distance)
mass_magn = magnitude *. difference
vel1 -= m2 *. mass_magn
vel2 += m1 *. mass_magn
go (next p2)
| otherwise = do
v1 <- getVec vel1
p1 += delta_t *. v1
go p2
advance p2
where
vel1 = vel p1
p2 = next p1
------------------------------------------------------------------------
planets :: Ptr Double
planets = unsafePerformIO $ mallocBytes (7 * nbodies * 8) -- sizeOf double = 8
nbodies :: Int
nbodies = 5
solar_mass, delta_t, days_per_year :: Double
days_per_year = 365.24
solar_mass = 4 * pi ** 2;
delta_t = 0.01
initialize = mapM_ newPlanet planets
where
dp = days_per_year
planets =
[0, 0, 0,
0, 0, 0,
1 * solar_mass,
4.84143144246472090e+00, (-1.16032004402742839e+00), (-1.03622044471123109e-01),
1.66007664274403694e-03*dp, 7.69901118419740425e-03*dp, (-6.90460016972063023e-05)*dp,
9.54791938424326609e-04 * solar_mass,
8.34336671824457987e+00, 4.12479856412430479e+00, (-4.03523417114321381e-01),
(-2.76742510726862411e-03)*dp, 4.99852801234917238e-03*dp, 2.30417297573763929e-05*dp,
2.85885980666130812e-04 * solar_mass,
1.28943695621391310e+01, (-1.51111514016986312e+01), (-2.23307578892655734e-01),
2.96460137564761618e-03*dp, 2.37847173959480950e-03*dp, (-2.96589568540237556e-05)*dp,
4.36624404335156298e-05 * solar_mass,
1.53796971148509165e+01, (-2.59193146099879641e+01), 1.79258772950371181e-01,
2.68067772490389322e-03*dp, 1.62824170038242295e-03*dp, (-9.51592254519715870e-05)*dp,
5.15138902046611451e-05 * solar_mass
]
------------------------------------------------------------------------
-- Support for 3 dimensional mutable vectors
data Vector3 = Vec !Double !Double !Double
cursor :: IORef (Ptr Double)
cursor = unsafePerformIO $ newIORef planets
end :: Ptr Double
end = inc planets (nbodies * 7)
next :: Ptr Double -> Ptr Double
next = flip inc 7
inc :: Ptr Double -> Int -> Ptr Double
inc ptr n = ptr `seq` n `seq` plusPtr ptr (n * 8)
newPlanet :: Double -> IO ()
newPlanet d = d `seq` do
ptr <- readIORef cursor
pokeElemOff ptr 0 d
writeIORef cursor (inc ptr 1)
pos :: Ptr Double -> Ptr Double
pos ptr = ptr
vel :: Ptr Double -> Ptr Double
vel ptr = inc ptr 3
mass :: Ptr Double -> IO Double
mass = flip peekElemOff 6
------------------------------------------------------------------------
(Vec x y z) .+. (Vec u v w) = Vec (x+u) (y+v) (z+w)
(Vec x y z) .-. (Vec u v w) = Vec (x-u) (y-v) (z-w)
k *. (Vec x y z) = Vec (k*x) (k*y) (k*z) -- allocates
magnitude2 (Vec x y z) = x*x + y*y + z*z
------------------------------------------------------------------------
getVec p = p `seq` liftM3 Vec (peek p) (f 1) (f 2)
where f = peekElemOff p
setVec p (Vec x y z)= do
poke p x
pokeElemOff p 1 y
pokeElemOff p 2 z
infix 4 +=
infix 4 -=
v1 += (Vec u v w) = do
x <- peek v1; poke v1 (x+u)
y <- peekElemOff v1 1; pokeElemOff v1 1 (y+v)
z <- peekElemOff v1 2; pokeElemOff v1 2 (z+w)
v1 -= (Vec u v w) = do
x <- peek v1; poke v1 (x-u)
y <- peekElemOff v1 1; pokeElemOff v1 1 (y-v)
z <- peekElemOff v1 2; pokeElemOff v1 2 (z-w)
Copyright Don Stewart, Einar Karttunen, Branimir Maksimovic and Bertram Felgenhauer 2010
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of Don Stewart, Einar Karttunen, Branimir Maksimovic and Bertram Felgenhauer nor the names of other
contributors may be used to endorse or promote products derived
from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TOP = ../../..
include $(TOP)/mk/boilerplate.mk
SRCS = pidigits.hs
PROG_ARGS += 10000
HC_OPTS += -i. -package base
include $(TOP)/mk/target.mk
3141592653 :10
5897932384 :20
6264338327 :30
9502884197 :40
1693993751 :50
0582097494 :60
4592307816 :70
4062862089 :80
9862803482 :90
5342117067 :100
9821480865 :110
1328230664 :120
7093844609 :130
5505822317 :140
2535940812 :150
8481117450 :160
2841027019 :170
3852110555 :180
9644622948 :190
9549303819 :200
6442881097 :210
5665933446 :220
1284756482 :230
3378678316 :240
5271201909 :250
1456485669 :260
2346034861 :270
0454326648 :280
2133936072 :290
6024914127 :300
3724587006 :310
6063155881 :320
7488152092 :330
0962829254 :340
0917153643 :350
6789259036 :360
0011330530 :370
5488204665 :380
2138414695 :390
1941511609 :400
4330572703 :410
6575959195 :420
3092186117 :430
3819326117 :440
9310511854 :450
8074462379 :460
9627495673 :470
5188575272 :480
4891227938 :490
1830119491 :500
2983367336 :510
2440656643 :520
0860213949 :530
4639522473 :540
7190702179 :550
8609437027 :560
7053921717 :570
6293176752 :580
3846748184 :590
6766940513 :600
2000568127 :610
1452635608 :620
2778577134 :630
2757789609 :640
1736371787 :650
2146844090 :660
1224953430 :670
1465495853 :680
7105079227 :690
9689258923 :700
5420199561 :710
1212902196 :720
0864034418 :730
1598136297 :740
7477130996 :750
0518707211 :760
3499999983 :770
7297804995 :780
1059731732 :790
8160963185 :800
9502445945 :810
5346908302 :820
6425223082 :830
5334468503 :840
5261931188 :850
1710100031 :860
3783875288 :870
6587533208 :880
3814206171 :890
7766914730 :900
3598253490 :910
4287554687 :920
3115956286 :930
3882353787 :940
5937519577 :950
8185778053 :960
2171226806 :970
6130019278 :980
7661119590 :990
9216420198 :1000
9380952572 :1010
0106548586 :1020
3278865936 :1030
1533818279 :1040
6823030195 :1050
2035301852 :1060
9689957736 :1070
2259941389 :1080
1249721775 :1090
2834791315 :1100
1557485724 :1110
2454150695 :1120
9508295331 :1130
1686172785 :1140
5889075098 :1150
3817546374 :1160
6493931925 :1170
5060400927 :1180
7016711390 :1190
0984882401 :1200
2858361603 :1210
5637076601 :1220
0471018194 :1230
2955596198 :1240
9467678374 :1250
4944825537 :1260
9774726847 :1270
1040475346 :1280
4620804668 :1290
4259069491 :1300
2933136770 :1310
2898915210 :1320
4752162056 :1330
9660240580 :1340
3815019351 :1350
1253382430 :1360
0355876402 :1370
4749647326 :1380
3914199272 :1390
6042699227 :1400
9678235478 :1410
1636009341 :1420
7216412199 :1430
2458631503 :1440
0286182974 :1450
5557067498 :1460
3850549458 :1470
8586926995 :1480
6909272107 :1490
9750930295 :1500
5321165344 :1510
9872027559 :1520
6023648066 :1530
5499119881 :1540
8347977535 :1550
6636980742 :1560
6542527862 :1570
5518184175 :1580
7467289097 :1590
7772793800 :1600
0816470600 :1610
1614524919 :1620
2173217214 :1630
7723501414 :1640
4197356854 :1650
8161361157 :1660
3525521334 :1670
7574184946 :1680
8438523323 :1690
9073941433 :1700
3454776241 :1710
6862518983 :1720
5694855620 :1730
9921922218 :1740
4272550254 :1750
2568876717 :1760
9049460165 :1770
3466804988 :1780
6272327917 :1790
8608578438 :1800
3827967976 :1810
6814541009 :1820
5388378636 :1830
0950680064 :1840
2251252051 :1850
1739298489 :1860
6084128488 :1870
6269456042 :1880
4196528502 :1890
2210661186 :1900
3067442786 :1910
2203919494 :1920
5047123713 :1930
7869609563 :1940
6437191728 :1950
7467764657 :1960
5739624138 :1970
9086583264 :1980
5995813390 :1990
4780275900 :2000
9946576407 :2010
8951269468 :2020
3983525957 :2030
0982582262 :2040
0522489407 :2050
7267194782 :2060
6848260147 :2070
6990902640 :2080
1363944374 :2090
5530506820 :2100
3496252451 :2110
7493996514 :2120
3142980919 :2130
0659250937 :2140
2216964615 :2150
1570985838 :2160
7410597885 :2170
9597729754 :2180
9893016175 :2190
3928468138 :2200
2686838689 :2210
4277415599 :2220
1855925245 :2230
9539594310 :2240
4997252468 :2250
0845987273 :2260
6446958486 :2270
5383673622 :2280
2626099124 :2290
6080512438 :2300
8439045124 :2310
4136549762 :2320
7807977156 :2330
9143599770 :2340
0129616089 :2350
4416948685 :2360
5584840635 :2370
3422072225 :2380
8284886481 :2390
5845602850 :2400
6016842739 :2410
4522674676 :2420
7889525213 :2430
8522549954 :2440
6667278239 :2450
8645659611 :2460
6354886230 :2470
5774564980 :2480
3559363456 :2490
8174324112 :2