-
Notifications
You must be signed in to change notification settings - Fork 11
Home
MathCompile is a package that translates Wolfram Language functions into C++ code and generate dynamic libraries that can be called in Wolfram Language.
The primary usage of MathCompile is to speed up the execution of Wolfram Language code, similar to the built-in compiler. Compared to the built-in compiler, MathCompile supports functional programming much better, and it implements all supported functions so that the compiled functions do not depend on the Wolfram run-time library to run.
Here are some scenarios where you should consider using MathCompile:
- This part of the code is a performance bottleneck;
- The code does numerical calculation;
- The code uses loop, such as
Table
,Do
, orNestList
; - The code does numerous operations on small lists.
And here are some scenarios where you cannot/do not need to use MathCompile:
- The code does symbolic computation;
- The code uses functions that are not compilable, e.g.
NIntegrate
; - The performance is limited by the functions highly optimized already, e.g. matrix multiplication;
- Compilation does not provide a speed-up according to tests.
See the Guide.
See Performance Comparison between compiled and not compiled functions on a few interesting problems from Project Euler.
MathCompile is still in a very early stage, where a lot of functionalities are to be implemented. Here is a incomplete list of what will possibly be added.
-
More functions (for completeness)
Partition
,FreeQ
,MemberQ
,Position
,Cases
,Delete
,Insert
,Inner
,Outer
,ReplacePart
, and a few more. -
Helpful compilation error messages
Currently, the error messages directly comes fromCreateLibrary
. Parsing the output from the C++ compilers and locating the error is possible and will be implemented. -
Helpful Run-time error messages
Currently, all run-time errors are caught and returned as library function error. Showing a detail description will be added, but locating an error is hard. -
Inlining arrays
Array constants should be able to pulled into a compiled function. Since compilingList
with numerous arguments is not ideal, special treatments are necessary. -
Import and export functions
Import and export of binary data and tables of numbers can be built into the compiler without too much effort. -
Parallelization
Parallelization can greatly improve the performance of listable functions andDot
, whileParallelTable
andParallelMap
, etc. are harder to implement correctly. -
Interacting with the kernel
The built-in compiler (withCompilationTarget->"C"
) is able to call a not-compilable function, which is useful when a necessary function happens to be missing. In addition, supportingPrint
orEcho
is useful. -
More data structures?
Supporting sparse array might not be worthwhile, butAssociation
(asstd::map
) has the potential of performance improvement.