Questions tagged [compile]

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

114 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
26 votes
0 answers
521 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 <...
  • 6,605
15 votes
0 answers
370 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 ...
  • 30.8k
11 votes
0 answers
218 views

How to use Bags in FunctionCompile?

I was reading this question and it wanted to know how to FunctionCompile this: ...
  • 30.8k
11 votes
0 answers
934 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
225 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 ...
  • 19.3k
10 votes
0 answers
290 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-...
  • 112k
9 votes
0 answers
123 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 ...
  • 2,701
8 votes
0 answers
240 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 ...
  • 19.3k
8 votes
0 answers
531 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 ...
  • 627
7 votes
0 answers
88 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
111 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
167 views

Possible Compile bug

Bug introduced in 11.3 or earlier The program: ...
6 votes
0 answers
213 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 ...
  • 1,347
5 votes
0 answers
85 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: ...
  • 59.5k
5 votes
0 answers
93 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
142 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 ...
  • 2,480
5 votes
0 answers
151 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 "...
  • 103
5 votes
0 answers
131 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 ...
  • 1,191
5 votes
0 answers
176 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, ...
  • 265
5 votes
0 answers
498 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 ...
  • 9,522
5 votes
0 answers
627 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 ...
  • 51
4 votes
0 answers
162 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
86 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 ...
  • 445
4 votes
0 answers
211 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 ...
  • 109
4 votes
0 answers
145 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 ...
  • 2,480
4 votes
0 answers
124 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::...
  • 16.6k
4 votes
0 answers
91 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 ...
  • 16.6k
4 votes
0 answers
198 views

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

Turn on Needs["CompiledFunctionTools`"] First example ...
  • 16.6k
4 votes
0 answers
275 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
72 views

Compiling a function that uses MapThread

I'm looking for tips on quickly applying the following update to $B$ pairs of $(w_i,x_i)$ $$\text{step}(w_i,x_i)=w_i-a x_i \langle w_i, x_i \rangle$$ Below is a readable but very slow version ...
3 votes
0 answers
70 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,140
3 votes
0 answers
78 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 ...
  • 151
3 votes
0 answers
112 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: ...
  • 6,266
3 votes
0 answers
246 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 ...
  • 8,667
3 votes
0 answers
75 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 ...
  • 51
3 votes
0 answers
236 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
534 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 ...
  • 907
2 votes
0 answers
54 views

Argument value loss using Listable C-Compiled Function

In my recent studies, I have come across a very strange anomaly with C compiled functions. When I call a function that has the 'Listable' attribute while global variables are accessed through ...
2 votes
0 answers
46 views

SymbolicGPU documentation

I found an interesting files there $CUDALinkPath -> ../GPUTools here ...
2 votes
0 answers
38 views

Can NumericArray be Compiled?

I've have a big block of code written under Compile. Some other part of the code which receives data from shared Q useing ...
  • 403
2 votes
0 answers
86 views

Fast value extraction for refreshing large data

I am trying to fine tune a procedure to reduce its running time. It involves two large arrays "data" and "positions": ...
  • 153
2 votes
0 answers
53 views

Using FunctionCompile to emulate DistanceMatrix with my own DistanceFunction

I'd like to create a distance matrix with an expensive distance function. To explore how to do this for a simpler case, consider these three ways of creating a Euclidean distance matrix: Using a ...
  • 3,140
2 votes
0 answers
88 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 ...
2 votes
0 answers
116 views

Repeated calling of a ParametricNDSolve result in a faster way?

I recently learned of ParametricNDSolve and found that I need to compute it once and then call its result sol at different ...
  • 4,564
2 votes
0 answers
103 views

LTemplate and external library Armadillo

As a great fan of the simplicity of the LTemplate library for the end user I am now faced with a problem when apparently everything compiles correctly but the functions are not loaded from the library....
  • 832
2 votes
0 answers
122 views

Convert huge (10-100MB of plain text) Mathematica function for external use

I have a huge Mathematica function (plain text ranging 10-100MB) that I am trying to convert to Fortran for external use. I tried using FortranForm, which does most of the work, and cleaned the code ...
  • 21
2 votes
0 answers
121 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 ...
  • 1,795
2 votes
0 answers
179 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,480
2 votes
0 answers
72 views

Eliminating a call to MainEvaluate from a compiled function

I would like to write a compile function ...
  • 155
2 votes
0 answers
151 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: ...
  • 314