simd alternatives and similar packages
Based on the "Math" category.
Alternatively, view simd alternatives based on common mentions on social networks and blogs.

vector
An efficient implementation of Intindexed arrays (both mutable and immutable), with a powerful loop optimisation framework . 
statistics
A fast, high quality library for computing with statistics in Haskell. 
HerbiePlugin
GHC plugin that improves Haskell code's numerical stability 
hgeometry
HGeometry is a library for computing with geometric objects in Haskell. It defines basic geometric types and primitives, and it implements some geometric data structures and algorithms. The main two focusses are: (1) Strong type safety, and (2) implementations of geometric algorithms and data structures that have good asymptotic running time guarantees. 
computationalalgebra
GeneralPurpose Computer Algebra System as an EDSL in Haskell 
dimensional
Dimensional library variant built on Data Kinds, Closed Type Families, TypeNats (GHC 7.8+). 
mwcrandom
A very fast Haskell library for generating high quality pseudorandom numbers. 
numhask
A haskell numeric prelude, providing a clean structure for numbers and operations that combine them. 
cf
"Exact" real arithmetic for Haskell using continued fractions (Not formally proven correct) 
optimization
Some numerical optimization methods implemented in Haskell 
poly
Fast polynomial arithmetic in Haskell (dense and sparse, univariate and multivariate, usual and Laurent) 
equationalreasoning
Agdastyle equational reasoning in Haskell 
safedecimal
Safe and very efficient arithmetic operations on fixed decimal point numbers 
monoidsubclasses
Subclasses of Monoid with a solid theoretical foundation and practical purposes 
eigen
Haskel binding for Eigen library. Eigen is a C++ template library for linear algebra: matrices, vectors, numerical solvers, and related algorithms.
Less time debugging, more time building
* Code Quality Rankings and insights are calculated and provided by Lumnify.
They vary from L1 to L5 with "L5" being the highest.
Do you think we are missing an alternative of simd or a related project?
Popular Comparisons
README
simd
This library provides a simple interface to the SIMD primops provided in GHC 7.8. SIMD (Single Instruction Multiple Data) CPU instructions provide an easy way to parallelize numeric computations. GHC 7.8 provides primops that let us access these CPU instructions. This package wraps thos primops in a more user friendly form. These primops can only be used with the llvm backend, so you must have llvm installed and compile any program using this library with the llvm option.
This library is available on hackage, and so can be installed by:
cabal update
cabal install simd
Example usage
We can write a nonSIMD function to calculate the Euclidean distance as:
distance :: VU.Vector Float > VU.Vector Float > Float
distance !v1 !v2 = sqrt $ go 0 (VG.length v11)
where
go tot (1) = tot
go tot i = go tot' (i1)
where
tot' = tot+diff1*diff1
diff1 = v1 `VG.unsafeIndex` iv2 `VG.unsafeIndex` i
To take advantage of the SIMD operations, we first convert the vector from type VU.Vector Float
into VU.Vector (X4 Float)
using unsafeVectorizeUnboxedX4
.
We then perform our SIMD operations.
X4 Float
is an instance of the Num
type class, so this is straightforward.
Finally, we convert our X4 Float
into a single Float
using the plusHorizontalX4
command.
Horizontal additions are costly and should be avoided except as the final step in a SIMD computation.
distance_simd4 :: VU.Vector Float > VU.Vector Float > Float
distance_simd4 v1 v2 = sqrt $ plusHorizontalX4 $ go 0 (VG.length v1'1)
where
v1' = unsafeVectorizeUnboxedX4 v1
v2' = unsafeVectorizeUnboxedX4 v2
go tot (1) = tot
go tot i = go tot' (i1)
where
tot' = tot+diff*diff
diff = v1' `VG.unsafeIndex` i  v2' `VG.unsafeIndex` i
The X4
above stands for how many operations we want to do in parallel using SIMD.
We could also choose X8
and X16
, but as the performance graphs below demonstrate, these do not provide as much of a speed up as you might hope.
More examples of Euclidean distance functions (some of which perform very bad!) can be found in the criterion benchmark in the examples folder.
Performance graphs
These performance graphs measure how long it takes to calculate the Euclidean distance between two vectors of different lengths. For large vectors, almost all the work can be done in parallel and SIMD instructions work very well. For small vectors, non parallelizable instructions and initialization overhead become more important. For vectors of size 16, we actually run slower using the simd operations. I suspect with some fiddling around, this overhead could be reduced. But I don't ever use vectors that small, so I didn't bother trying.
Performance tests will vary a lot depending on what computer you are using and what instructions it supports well. I ran these tests on my 64 bit Core 2 Duo laptop.
Other
It might be useful to provide some rewrite rules to make vectorization an automatic performance improvement. This is not easy to do with the current Data.Vector API, however, because all the vector operations get inlined before the rules can fire. In any case, people who care enough about performance to want SIMD instructions will probably want to write the SIMD code manually.
Finally, I wasn't part of the work on the GHC side of SIMD operations. They did all the hard work. Thanks!