Questions tagged [compile]
Questions about the generation and use of compiled functions using Compile.
145 questions with no upvoted or accepted answers
26
votes
0
answers
537
views
Compile not correctly initializing a variable defined inside Module
Bug introduced in 8.0, fixed in 10.4, intentionally reintroduced in 11.0 and persisting through 13.0.0 or later
In the following example, inside the minimumX's <...
16
votes
0
answers
406
views
FunctionCompile examples for Computer Vision
I'm looking for some good examples of FunctionCompile applied to image processing code since there doesn't seem to be anything on this in the documentation. So here's a first attempt at a hello world ...
11
votes
0
answers
221
views
How to use Bags in FunctionCompile?
I was reading this question and it wanted to know how to FunctionCompile this:
...
11
votes
0
answers
250
views
Does Compilation option "InlineExternalDefinitions"/"InlineCompiledFunctions" lead to unnecessarily complicated nesting?
Question: When an external (possibly complicated) definition f is used inside a compiled function with ...
11
votes
0
answers
946
views
Compile recursive function modifying global variables
How to compile recursive formula when it relies on more than a few global variables (global to the topmost compiled function)? It is unreasonable to pass on all such variables to each recursive ...
10
votes
0
answers
295
views
Check whether a working CCompiler is installed
Let me give a bit background: As many of my answers imply, I often use the auto-parallelization (meaning, that Mathematica distributes the calculation automatically over several cores when list-...
9
votes
0
answers
128
views
Fast Destructuring
This might be a XY problem. I first post my immediate question and some background below.
Question: What's the fastest way to pass arguments matching ...
8
votes
0
answers
244
views
What is a good way to code long, complex, compilable algorithms?
The functional paradigm of the Wolfram Language used in Mathematica is all around wonderful.
For intense numerics, Mathematica comes with the ability to Compile ...
8
votes
0
answers
548
views
How to force the compilation language to be C++ (not C) in CreateExecutable or CreateLibrary
I'm trying to speed up a section of a Mathematica 9.0.1 notebook by performing some calculations in C++ with the Cilk Plus and Threading Building Blocks tools available for the Intel C++ 14.0 compiler ...
7
votes
0
answers
167
views
Compiler with CompilationTarget -> C appears broken in 14.1
On the same Windows 11 machine with the same C compiler (Visual Studio 2022):
...
7
votes
0
answers
89
views
Mathematica 9 can't compile Increment Part with C
Why can't Mathematica 9 compile this code?
x = {1};
Compile[{}, x[[1]]++;,
{{x[[1]]++, _Integer}, {x[[1]], _Integer}}, CompilationTarget :> "C"][]
After ...
6
votes
0
answers
136
views
How to Compile an Open-Source Java Project which depends on the Wolfram Engine for Developers?
Background:
I have a license-related compile-cycle question. I developed a rather large Java project that partially uses the Wolfram Engine (for Developers) to perform certain computations. The ...
6
votes
0
answers
162
views
MWE for compiling functions into standalone DLL and calling them in Python?
I have read calling-a-compiledfunction-dll-from-outside-mathematica and the CodeGeneration tutorial and scanned other related questions too numerous to mention, but I am still unclear about how to ...
6
votes
0
answers
173
views
Possible Compile bug
Bug introduced in 11.3 or earlier
The program:
...
6
votes
0
answers
227
views
Compiling/calling Mathematica-generated .so from C
I'm trying to call a compiled function from a C program.
I am generating the static object
...
5
votes
0
answers
64
views
Listable attribute for functions compiled with FunctionCompile
Is it possible to create Listable compiled code with FunctionCompile in the same way one may do with ...
5
votes
0
answers
92
views
Warning from CompiledFunction is permanently off silently after generating for 3 times, bug or feature?
I've been vaguely aware of this behavior for a long time but never looked into it. Consider this sample:
...
5
votes
0
answers
112
views
Effectivelly using Compile for calculate a Unitary transformation
I am new to Mathematica, and this is my first post, so if my question is not clear enough, I would be glad to read the comments and edit my question to add more information.
The problem
I need to ...
5
votes
0
answers
162
views
Optimize Use of PeakDetect in Mathematica
I am quite new to Mathematica and I am looking for some advice in order to improve and optimize my code.
Here is what I am trying to do:
Open a stream
Read the stream line by line and store it in "...
5
votes
0
answers
191
views
Random number generation within Compile and Parallelization->True
According to this thread RandomChoice is a compilable function.
I use it to generate random numbers in a compiled function with parallelization enabled.
I wrote ...
5
votes
0
answers
178
views
Improving the speed of an optimization algorithm via compilation and parallellization
I have written an implementation of eight variants of the PSO-algorithm and I want to test them over a set of test functions. I am using parallelization as it improves the speed a lot and I have also, ...
5
votes
0
answers
500
views
Listing over multiple inputs (tensor rank > 1) in a compiled function
I'm trying to optimize the solution given by Michael E2 to my previous problem (Efficiently determining if 3D points are within a surface composed of polygons) which I figured would be relatively ...
5
votes
0
answers
630
views
Having problems compiling Mathematica Cuda code
Ok I am trying to follow the examples of Cuda Code in the docummentation
Run the CUDAQ[] and get back a True
and run some of ...
4
votes
0
answers
129
views
Can't compile a standalone app in 14.1
I read the article reviewing the innovations in version 14.1 and am absolutely thrilled to be able to build a standalone app. I tried to replicate the example from the article in an even shorter form, ...
4
votes
0
answers
166
views
Inconsistent Output Bug and Code-Quits-Kernel Bug with Compile
This is the strangest bug I've encountered. In my experience, variations in the code will unexpectedly crash the kernel, give inconsistent output, or produce expected results with no problems.
1) Code-...
4
votes
0
answers
114
views
How to efficiently build a large sparse matrix and overloading a compiled function?
I would like to construct a large sparse matrix folding from rank-4 tensor given by the following:
$\mathcal{L}_{1L}^{00}(i,j)=\mathcal{L}_{1L}^{00}(m_1,m_2;M_1,M_2)$
The indices of matrix $(i,j)$ are ...
4
votes
0
answers
249
views
Speed improvements and confusion for MapThread and Dot
I have a question / confusion over improving the speed of MapThread[Dot,...] for lists of tensors. My problem involves taking two lists of tensors and then ...
4
votes
0
answers
151
views
How to compile effectively with recent MMA? Global variables in C code, compilation of C code
I have read the generously comprehensive answers by @leonidshifrin and @xzczd to the question How to compile effectively but more than seven years have now passed, and whilst I am sure much remains ...
4
votes
0
answers
136
views
How to deal with "Compile::cset" in Compile
When compiling below code
Compile[{{data, _Integer, 2}}, Fold[Flatten /@ Flatten[Outer[List, ##, 1], 1] &, data]]
I encountered error messages
Compile::...
4
votes
0
answers
96
views
weird behaviour of Listable fortran Librarylink function: different result each evaluation
I am working with fotran librarylink function currently. In this post, I will show some weird result of Listable fortran librarylink generated by intel compiler under windows (I tried gcc on linux the ...
4
votes
0
answers
204
views
Is it possible to prohibit unnecessary CopyTensor in Compile? Just like .noalias() in Eigen library?
Turn on
Needs["CompiledFunctionTools`"]
First example
...
4
votes
0
answers
295
views
CompilationTarget to C takes long compilation time
Consider I have a function, with one version that compiled to the virtual machine and one that compiled to C:
...
3
votes
0
answers
37
views
Mathematica call CompiledFunction from Python with Listable and Parrallelization attributes
I have a CompiledFunction e.g. this:
...
3
votes
0
answers
75
views
GSL multiroot finding mode Hybrid function load with Mathematica : Crash
Hi everyone
I work on a Mac M1 Sonoma 14.3 with Mathematica 12.3.1 and 14.0
I have an issue when using a C++ multiroot finding from GSL library.
I used this example : https://www.gnu.org/software/gsl/...
3
votes
0
answers
116
views
Optimizing memoization in compiled Mathematica code
Consider the following two codes - compiledcode and compiledcode1:
...
3
votes
0
answers
67
views
Making speed of MemberQ comparable with explicit If?
Consider the following two lists:
listtest = {11, 13, 22, 221, 1, 3} // Sort // N;
pdglisttest = RandomInteger[{-222, 222}, 10^6] // N;
For the given element of <...
3
votes
0
answers
47
views
How can I know what prevents efficient lower level code when using FunctionCompile?
When using the old Compile, I can use CompilePrint and ensure the resulting CompiledFunction doesn't use MainEvaluate. If MainEvaluate isn't used, the CompiledFunction is efficient. How do we know if ...
3
votes
0
answers
84
views
Using a compiled function in NMinimize
I can get NMinimize to work with compiled functions in simple cases.
This works with a constraint:
...
3
votes
0
answers
113
views
Free up used Memory
When using FunctionCompile[] to generate a large matrix of ranges there seems to be no way of recovering memory even though the variables are either out of scope or overwritten. I am aware that there ...
3
votes
0
answers
113
views
Why does changing this code in a Compile make it work?
This is a follow up question to this one. In that question I asked why the following code didn't work:
...
3
votes
0
answers
140
views
Lanczos method to tridagonalize a matrix
I want to tridagonalize a sparse matrix using the Lanczos algorithm.
I am working with a very large sparse matrix and I need some speed. In the following for example ...
3
votes
0
answers
263
views
How to get the executable out of a compiled function and run it in cmd
Can someone please guide how to run the function compiled by Wolfram Language in cmd independent of the kernel. It seems to export it into ...
3
votes
0
answers
89
views
Compile with "Listable" only on one argument
I would like to write a Compiled function which is listable only in the first argument, because this allow fast and easy parallelization. How is it possible to do it?
In the following way it does not ...
3
votes
0
answers
272
views
How to overload and compile pure functions operating on associations
I am writing a small package for myself for operating on zonotopes.
I am storing the generator matrix and the center of the zonotope in
an association. I decided to write a small constructor:
...
3
votes
0
answers
541
views
Speeding Up Image Processing Functions
I am working with stacks of 1024x1024 timelapse microscopy images that I am performing a series of image processing functions on to help segment each image. These functions include ...
2
votes
0
answers
42
views
Call Compiled Function in Python
How can I call a function made with Compile in Python, Is it possible to just save it using LibraryGenerateand call the ...
2
votes
0
answers
94
views
How to push the performance of this compiled function
I have the function optvals solving for two variables. For the given example of variables, I need the program to run atmost in a millisecond.
The main part of the ...
2
votes
0
answers
103
views
2
votes
0
answers
89
views
Large Structured Programming with Compile
Is it possible or wise to build a large program structure with only Compile?
With FunctionCompile it is possible to create ...
2
votes
0
answers
80
views
Memory leak with pure function and in the listable option of compiled function?
I'm using
13.0.0 for Microsoft Windows (64-bit) (December 3, 2021)
When I repeatedly run the command
...