Questions tagged [compile]

Questions about the generation and use of compiled functions using Compile.

73 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
24
votes
0answers
409 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 12.0. In the following example, inside the minimumX's ...
10
votes
0answers
262 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-...
10
votes
0answers
848 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 ...
9
votes
0answers
108 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 ...
9
votes
0answers
154 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 ...
8
votes
0answers
230 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 ...
7
votes
0answers
74 views

Substitute for Association inside Compile?

Associations are not compilable, so I’m looking for a workaround to this. That is, I need a mutable hashtable-like data structure with fast key value lookups ...
7
votes
0answers
79 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
0answers
72 views
+150

How would you compile a conditional accumulation?

I was reading this question and it wanted to know how to FunctionCompile this: ...
6
votes
0answers
143 views

Possible Compile bug

Bug introduced in 11.3 or earlier The program: ...
6
votes
0answers
494 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 ...
6
votes
0answers
204 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 ...
6
votes
0answers
477 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
0answers
54 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 ...
5
votes
0answers
120 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
0answers
83 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
0answers
612 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
0answers
132 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
0answers
100 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
0answers
84 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
0answers
178 views

Is it possible to prohibit unnecessary CopyTensor in Compile? Just like .noalias() in Eigen library?

Turn on Needs["CompiledFunctionTools`"] First example ...
4
votes
0answers
150 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, ...
4
votes
0answers
241 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
0answers
158 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
0answers
133 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
0answers
97 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::...
3
votes
0answers
502 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
0answers
42 views

Speeding up the process of NDSolve[] when a user-defined function is involved?

I am trying to tackle a (1+4 dimensional PDE) model at which the solution of the first PDE (with some interpolations and changing the domain) would be used in the second PDE. In fact, I must choose ...
2
votes
0answers
92 views

Strategies for using mathematica compiled code on a website?

I have developed a chaos detection algorithm which is already used as a compiled (target C) function within Mathematica. The development has been done under Win 10 64-bit with MMA 11.0.1 and the ...
2
votes
0answers
61 views

Eliminating a call to MainEvaluate from a compiled function

I would like to write a compile function ...
2
votes
0answers
95 views

How to speed up multiple calls of NonlinearModelFit?

I'm trying to do an insane amount of non-linear fits to large amounts of data sets. However, I found that the NonlinearModelFit is horribly slow. Here's the setup: ...
2
votes
0answers
52 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 ...
2
votes
0answers
73 views

Can substitution rules be compiled?

I am thinking of having a custom multiplication operation CenterDot[A,B] for non-commutative operators, and some rules that should commute the operators to a ...
2
votes
0answers
157 views

How to use Compile? Bivariate Gibbs Sampler

I am trying to use compile to speed up my Gibbs sampler. I know I can use Reap and Sow to speed up tremendously. I have a more complicated Bayesian posterior that I want to speed up with compile so I ...
2
votes
0answers
177 views

integration of a list of gaussian type orbitals (GTO)

I am currently trying to integrate various components of a current density (j={jx,jy,jz}) over space. The problem is that the current j is extracted from a quantum chemical computation and is a sum of ...
2
votes
0answers
114 views

Compilation of a function that needs to call Subsets

I'm working on a code that runs many (easy) operations on combinations (subsets) of different size (6, 7, 8, 9) taken from a big set of numbers (normally more that 40). So, this means the code has to ...
2
votes
0answers
136 views

Compile issues, scoping and order of evaluation

I have a few questions about compiling functions, which I think are all related to scoping and order of evaluation. I will illustrate them by a minimal example of the problem I have. I'm sorry for ...
2
votes
0answers
54 views

Compiled DiagonalMatrix

The standard function DiagonalMatrix cannot be compiled, so I tried writing my own: ...
1
vote
0answers
152 views

Can I use the Gwnum library to accelerate the multiplication in Mathematica?

Is it possible to use Gwnum library to accelerate the multiplication in Mathematica?
1
vote
0answers
81 views

Is there a way to reduce size of complex number?

I would like to create huge matrices with hundreds of thousands of elements per side and I would like to use complex numbers in it for further processing by Mathematica functions. When I investigate ...
1
vote
0answers
170 views

CreateExecutable returns $Failed

My platform is win10 64b, Mathematica 11 and Visual Studio 2015. When I apply CreateExecutable, it always returns $Failed. The ...
1
vote
0answers
135 views

How to speedup Plot3D with precompiled argument

I have a huge problem with my code: I estimate it to take hours to run. The scheme of the code is the following (I left the steps the same, but took much simpler functions): ...
1
vote
0answers
278 views

Compiled function and integration

I'm using the recursive functions defined here: MyFnc and myFncC (compiled version). I want to call this functions in the ...
1
vote
0answers
149 views

Compilation error: “Could not complete external evaluation at…”

I'm pretty new to trying to use Compile[], and I just can't see why I'm getting this error. I have two functions to define beforehand; one of them is a bit odd: <...
1
vote
0answers
84 views

Some problems with complied function

...
1
vote
0answers
117 views

Complex input for Compile makes it slow

I asked a question here and then tried to use Compile for the solution to gain even more speed. Inside Compile there is a loop ...
1
vote
0answers
164 views

Evaluation inside Compile

here's a simple question: I have a function: ...
1
vote
0answers
98 views

Regarding CompilationTarget->“C”

Recently I have read some interesting things about CompilationTarget->"C" on SE, e.g. in https://mathematica.stackexchange.com/a/54459/11116 where @MichaelE2 ...
0
votes
0answers
53 views

Compiling a function containing Apply

Well, the following function fun1 will be used thousands times (a single argument among these thousands one is called arg in the following) . Speeding is therefore critical for my code (KenKen ...
0
votes
0answers
47 views

Evaluation control inside Compile

I have the following function ...