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

learn more… | top users | synonyms

3
votes
1answer
306 views

Errors in Compile

I defined a function ...
2
votes
0answers
149 views
5
votes
1answer
564 views

Catching and debugging numerical errors in compiled functions

I have a compiled function (that was created using the second method of this question). Basically it's using a compiled closure. The problem is that for some parameter values it does not evaluate. ...
9
votes
1answer
646 views

Compiling a recursive formula

My question is related to computing what is called "invariant measure" for a particular well known fractal - the Sierpinski triangle. We have an array m of four two by two matrices, say ...
4
votes
1answer
760 views

Mathematica NDSolve and 'Compile'?

Since the consensus is usually that NDSolve speeds fares badly against compiled code such as c++ ODE solvers using GSL say, is it possible to make up for this lag ...
13
votes
1answer
318 views

Removing calls to MainEvalute when using inlined compiled closures

This question is tightly related to the answer Shaving the last 50 ms off NMinimize. There @OleksandR shows how inlined closures can be used to eliminate calls to ...
2
votes
1answer
143 views

compile function and floating points

The compile function I have written computes a table of relative frequencies of some data. Thus, the output is a list of increase elements, p, in [0,1]. Since I have say 1000 data points the elements ...
6
votes
1answer
261 views

How to compile Map and MapAt

I have a long list (say, million of elements, like this one: {{{1.0, 2.0}, 3}, {{4.0, 5.0}, 6},...} I would like to compile a function ...
8
votes
1answer
280 views

Elementwise, compilable min function

I am trying to implement efficiently a transfer-matrix like algorithm. On each iteration, I have two vectors $x=\{x_1,\dots,x_n\}$, $y=\{y_1,\dots,y_n\}$ with real numbers and I need to compute the ...
7
votes
0answers
243 views

Using Compile to speed up Function with PermutationProduct

I have the following fairly simple routine dot involving PermutationProduct that I wish to speed up using ...
12
votes
2answers
504 views

Using Goto and Label in compiled function?

Below I post some rudimentary code to show that there is something wrong using Goto and Label commands in compiled functions (or I believe there is something wrong). It seems that the command Label is ...
8
votes
1answer
330 views

Compiled version of (Norm/@coordinates)

Here I define (NormCoordinates). ...
9
votes
3answers
430 views

Compiled function error - nontensor object created

I'm trying to optimize code that uses Position MANY times. The following toy code works: ...
5
votes
0answers
391 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 ...
9
votes
2answers
219 views

Can RecurrenceTable make use of CompiledFunction?

I'm trying to implement a discrete-time 2D Verlet algorithm for a point-mass subject to a softened gravitational interaction as a test for a more computationally intensive simulation using ...
10
votes
2answers
246 views

Avoiding MainEvaluate in a CompiledFunction to fetch global variables

I'm trying to write a simulation using Mathematica 8.0. Since I will most likely be doing the same operation over and over again, I'm trying to Compile whatever I ...
10
votes
1answer
201 views

Unexpected behavior of Compile, Return and ;

Could somebody explain why test = Compile[{{x}}, Return[x]; ]; test[0.] returns ...
13
votes
1answer
289 views

Using Boost with CreateLibrary

I was looking at the answer of Leonid of Faster alternatives for DayOfWeek and wanted to see how hard it would be to do something similar in C++ using an external library like Boost. I tried to ...
14
votes
1answer
524 views

Parallel compiled functions running on parallel sub-kernels

Question Why is it, that compiled, Listable, parallel functions which work perfectly fine on the main kernel, do not run in parallel on sub-kernels? Details ...
12
votes
3answers
707 views

What compilers are “suitable” for CompilationTarget->“C”?

The documentation for CompilationTarget says, "if you do not have a suitable C compiler then you will not be able to set CompilationTarget to C". Well at this time, I don't have a compiler installed ...
6
votes
1answer
187 views

DistributeDefinitions not working for compiled functions

This is fixed in Mathematica 9.0.0. I'm having trouble with parallel evaluation of compiled functions. Here is a simple example illustrating the problem: ...
12
votes
1answer
953 views

How to install and configure Intel C++ Compiler for Mathematica correctly?

I wish to try the trial version of the latest Intel C++ Compiler for Windows with Mathematica. I have downloaded the current version of Intel® C++ Composer XE 2011 for Windows and installed only the ...
5
votes
2answers
154 views

MemberQ weird inside Compile

Compile[{{x, _Real, 1}}, MemberQ[x, 2]][{2}] outputs False. In fact, it seems to get compiled as ...
2
votes
1answer
214 views

how to nest parallelized computations on a cluster?

I am lucky to have access to a computational cluster and I could submit my job to many-many cores. As I need to evaluate a numerical integral within a numerical integral, I would like to know if I can ...
0
votes
2answers
782 views

nested numerical integration: not valid limits?

I encountered an error when I was hoping for some Mathematica (8.0.4) magic sparing me to code up numerical integration, function approximation and root-finding myself. The broader context and the ...
15
votes
1answer
2k views

How do I get Mathematica to recognize a C compiler on a 64-bit Windows machine?

Mathematica does not recognize any C compiler on my computer. I run Mathematica 8.0.4.0 on Windows 7. I've tried to make sure various C compilers are installed on my computer, but I'm not sure how to ...
13
votes
2answers
802 views

Speeding up random walk for many particles

I am trying to speed up this code for many particles to take a random walk. I'm not sure why it is so slow for such a simple task. I got a few hints from colleagues to reduce the precision of the ...
10
votes
1answer
306 views

Using Apply inside Compile

In this great answer a compiled version of the Nelder-Mead algorithm is presented. Since it works on arbitrary dimensions (i.e. arbitrary number of arguments), it has to use apply on the objective ...
9
votes
2answers
129 views

tol and None in output of CompilePrint

A bit of background: I'm trying to fit a very complicated symbolic function. By compiling the function I got about 100x speedup, but I would need another 10. Therefore I'm trying to understand if the ...
5
votes
4answers
676 views

Compile and “True should be a machine-size real number…” Error

I am trying to compile a little summation function. As far as I understand, because the built-in Sum function can also return ...
5
votes
2answers
670 views

Expression evaluation inside of FindRoot inside a Compiled Function

I'm trying to get some performance increase out of my own implicit differential equation solver using Compile[]. The uncompiled function is of the following form: ...
5
votes
2answers
349 views

How to set the return type of a compiled function? (Compile::noinfo warning)

I have simple function I would like to compile, but I get a warning and a call to MainEvaluate. I would like to avoid both. ...
-4
votes
3answers
1k views

Problem with Compile Function

I am attempting to Compile this function which is used to calculate a elastic collision in two dimensions. The two first coordinates of each list are the position ...
3
votes
2answers
346 views

Can SetDelayed (:=) be compiled?

Is it possible to put an If statement as below within a compile (see below)? I received a warning about SetDelayed. ...
3
votes
1answer
330 views

Explanation on why Compile statement works only if input and output sizes work

I found the following code: Compile[{{m, _Real, 2}}, Fourier[m]][Table[N[i - j], {i, 4}, {j, 4}]] which doesn't work correctly. But the following was posted as a ...
7
votes
2answers
654 views

Working with large data, pass-by-reference, compiled functions

I think I know the answer to this, but after two days of Googling, this is my last effort before going down an unwanted path... I have a function that takes lots of large data as arguments as well as ...
2
votes
1answer
3k views

Visual Studio Express 2010 on x86-64: libcmt.lib missing

The CCompilerDriver documentation explains that to use visual studio express on 64-bit targets, it's necessary to install the windows SDK after installing visual studio. I have done this, first ...
14
votes
2answers
667 views

Efficiently collecting results inside a compiled function

When we don't know the number of results that will be generated, the usual way to collect results is Reap/Sow. Another ...
86
votes
5answers
7k views

How to compile effectively?

What are the best practices of compiling functions? I understand that this is a vague question, but let me list some aspects that might trigger useful answers. Some of these have already been answered ...
17
votes
3answers
734 views

How to force Compile to return multiple results?

I would like to return two separate values from a compiled function, but Mathematica refuses to use the compiled version. Here is a narrowed-down example: ...
11
votes
3answers
761 views

Function does not compile with Greater in it

I have to speed up a matrix-calculation and would like to use Compile for it, though it fails and produces an unknown error message: ...
7
votes
3answers
481 views

Threading a compiled function over multiple arguments of different lengths

I am interested in threading a compiled function over multiple argument lists of different lengths. I will explain this in two steps: Suppose f is some function. Then one can define another ...
11
votes
1answer
339 views

Why is MainEvaluate being used when LinearSolve can be compiled?

According to this question LinearSolve can be Compiled. However, CompilePrint shows a MainEvaluate but no-warning is generated. It appears that LinearSolve is not ...
5
votes
2answers
2k views

How to use a matrix variable for a compiled function

I want to compile the following function which takes a matrix variable. ...
22
votes
3answers
613 views

Which Distributions can be Compiled using RandomVariate

Recently, Oleksandr kindly showed a list of Mathematica commands that can be compiled. RandomVariate was part of that list. However, whether this can be compiled depends upon the distribution that is ...
73
votes
8answers
6k views

List of compilable functions

Is there somewhere a list on the functions that Compile can compile, or the cases in which a particular function can be compiled that I haven't found? I'd be glad ...
41
votes
2answers
2k views

Internal`Bag inside Compile

Since Internal`Bag, Internal`StuffBag and Internal`BagPart can be compiled down, it is a ...
34
votes
4answers
3k views

How well does Mathematica code exported to C compare to code directly written for C?

Essentially what it says in the title. Mathematica can, IIRC, export it's code to C. How much overhead does that inflict on the code, as compared to writing it from scratch in C?
12
votes
2answers
185 views

How do you determine the optimal autocompilation length on your system

When you pack lists there is an overhead therefore packing a list with, say, 2 elements is likely to cost more than you get back in efficiency. Mathematica has default list lengths for which functions ...
43
votes
4answers
2k views

Speeding up this fractal-generating code

I used the code below (which is a sample from this gist containing more similar code) in my answer to my own question about Mandelbrot-like sets for functions other than the simple quadratic on ...