Questions tagged [performance-tuning]

Questions on optimizing Mathematica code for higher performance. This may mean faster execution, lower memory usage or both. Not to be confused with mathematical optimization.

Filter by
Sorted by
Tagged with
0
votes
0answers
39 views

Memory stored with `Trace`

When I inspect the details of a long computation using Trace, is there a way to know when a certain intermediate result is stored in the memory and, more ...
5
votes
2answers
393 views

huge difference in memory usage

I have two pieces of code that do exactly the same thing. However, the memory consumption is very different in the two approaches, and I cannot figure out the reason. Here is the code: ...
3
votes
1answer
96 views

Help coding an Abelian Sandpile

I'm attempting to code an abelian sandpile. I thought a good way to go about it would be utilizing recursion, which I've never tried in MMA before. The code currently runs but doesn't seem to work (it ...
0
votes
1answer
76 views

Is there a way for Mathematica to store values obtained in a previous computation?

This question may be badly worded but I have some commands which are defined recursively, call these $x[n]$, which give a list as a solution. I then have a function, say $f$, which is applied to these ...
6
votes
1answer
102 views

SparseArray to list of lists (column entries) efficiently?

Suppose we have a very big very sparse matrix, e.g.: ...
12
votes
2answers
2k views

Can someone boost even more my code?

UPDATE As suggested by @Roman, I've included here all my code. I'm using just bult-in function and compile to boost my code, but I think that it can be better. My code looks like ...
0
votes
0answers
55 views

Improving speed of ParametricNDSolve for three-dimensional integration

I'm trying to calculate a three-dimensional integral of a function depending on four parameters a, b, c, d via ParametricNDSolve ...
2
votes
0answers
53 views

Best resources for HPC with mathematica

I am quite good with Mathematica and functional programming in general. My main source of information, to learn how to program with Mathematica, has been the fantastic book Power Programming with ...
4
votes
1answer
139 views
2
votes
0answers
26 views

Optimising tensor operations under memory constraints

Let riem is a free variable with riem ∈ Arrays[{4, 4, 4, 4} as assumption. Let: ...
8
votes
1answer
184 views

Better performance for shortest path in an Image

I would like to find the shortest path in an image from one pixel to another. If the image is grayscale, the distance between two pixels could be Abs[p1 - p2], ...
7
votes
1answer
173 views

Does the following change to MKL environment variable boost Mathematica speed on AMD CPUs

I personally do not have an AMD CPU but since they are literally becoming quite hot these days, I thought whether the following fix (as proposed here: https://www.reddit.com/r/matlab/comments/dxn38s/...
0
votes
1answer
60 views

Why does this Code take a very very long time to run

I have the following code, which runs with no trouble using randomly generated symmetric matrices (either RandomReal[] or ...
3
votes
2answers
44 views

Find position of sublists containing a given element at nth position

I have a list of lists similar to this: L = {{"a", "b", "c"}, {"x", "c", "y"}, {"i", "j", "h"}, {"x", "b", "z"}} Each list within ...
2
votes
1answer
43 views

How can I find whether a given algebraic expresion T can be obtained as linear combination from a set S (with number coeficients)

We might take: s = {(x-y)^2, x*y+z}; e = (x+y)^2 + 4*z; and linearDecompose[e,s] could give ...
1
vote
1answer
57 views

How to use Sow and Reap instead of AppendTo for faster computations? [duplicate]

In this example I used appendTo. f[x_] := x + 1; data = {}; For[x = 1, x <= 10, x++, <...
0
votes
1answer
38 views

FindInstance runtime is too long

...
5
votes
2answers
137 views

How to efficiently populate a symmetric matrix?

I need to populate a matrix $A_{kl}$, where $$ k = (m-1)J+n$$ $$ l = (p-1)J+q$$ And $$m,p = 1, 2, ..., I$$ $$n,q = 1, 2, ..., J$$ Its components are (mnpq). For ...
7
votes
3answers
197 views

Fold a list but alternate used functions

Is there a clean way to fold a list but alternate functions used? Say we call such function FoldAlternating. Then for example, The ...
2
votes
2answers
38 views

How can I optimize the Manipulate function in plotting?

Ahoy! I'm trying to create a Fourier series visualization tool that allows me to interactively view a Fourier series as a function of the number of terms using ...
9
votes
0answers
163 views

What is the best and most efficient way to curry?

Suppose I have a function with a signature like g[expr, _?(f), {1}, Heads -> False] and I want to access it as an operator by giving the first argument last. I ...
2
votes
0answers
34 views

A maximal clique containing exactly n vertices and have a maximum total edge weight

In the weighted graph (edge-weighted), I look for possibilities for finding a maximal clique containing exactly n vertices and have a maximum weight. From the ...
3
votes
0answers
27 views

Fastest way to change the values of an association

I have an association of the following form : assoc = Association[a -> {1, 2, 3}, b -> {5, 6, 7}] <|a -> {1, 2, 3}, b -> {5, 6, 7}|> (the size ...
2
votes
0answers
83 views

How can I improve the speed of computing of numerical integration and eigenvalue?

First, let me explain what I am calculating. I have the following 2D-equation: $$ w(x,y) = \sum_{m}^{M}\sum_{n}^{N}A_{mn}\sin\left(\frac{2m\pi x}{a}\right)\sin\left(\frac{2n\pi y}{b}\right) $$ ...
6
votes
0answers
76 views

Memory usage for smallest eigenvalues

I have a bunch of hermitian matrices which are huge (of order 2^17 x 2^17) but extremely sparse so that, when I build the matrices, the usage of RAM is low (say of order 1 GB or similar). The ...
1
vote
2answers
97 views

Efficient computation of list mapping

I'm wondering about possible techniques to solve the following problem efficiently in Mathematica. Suppose you are given a list of integers that represent digits of a number with base 40. This list ...
4
votes
1answer
145 views

Find a continuous map between two sets of 2D points

Given two sets of points in 2D points1 and points2 inside a rectangle, I would like to find a continuous map ...
0
votes
1answer
79 views

Best laptop specs for a better and faster numerical simulations [closed]

Hope all is well! I am planning to buy a laptop (Windows) and looking for your help to decide the specs that we need to speed up the numerical simulations using Mathematica. The Mathemtica code I used ...
1
vote
0answers
18 views

Why does NonlinearModelFit keep repeating identical function evaluations?

If you examine the operation of NonlinearModelFit you find that the model is evaluated with the same parameters again and again. I have a very expensive model so ...
3
votes
1answer
42 views

Poor speed of ConnectSystemModelComponents and CreateSystemModel

I'm trying to use SystemModel to simulate a large air conditioning system, but my kernel crashes from time to time when I try to connect my custom models with each ...
1
vote
1answer
37 views

How to store a table after evaluation and immediately use the stored table for another calculation, automatically

Here is a simple example of what I want to achieve. Consider the two tables table T1:=Table[I,{I,1,5}] and T2:=Table[5n,{n,1,5}] ...
0
votes
0answers
26 views

How to create an alias for a local variable?

I have this charting function which changes how it is drawn depending on the user's choice. The key parts of the code (simplified) are; ...
0
votes
0answers
23 views

Improving performance of LibraryLink evaluation

I have a large function that I want to integrate with an integration routine. The function is supposed to be built out of LibraryLink functions, but I find evaluating the function to be very slow, and ...
28
votes
4answers
6k views

Why is raytracing so slow?

I'm trying to get some rays to bounce in a circle. But I want to be able to control the reflections, i.e. the direction the rays bounce in the circle. I have a MWE below, and it is severely limited by ...
-1
votes
1answer
77 views

How to improve `FindDistribution`? [closed]

Table[{n, FindDistribution[RandomSample[ Join @@ Table[ConstantArray[k, Binomial[n, k]], {k, 0, n}] ], TargetFunctions -> "Discrete"]}, {n, 15}] // TableForm ...
6
votes
4answers
213 views

Faster way to find longest chain of inequalities

I have a list of algebraic expression, all variables are positive, some of them have a specific size relationship. Such as: $\frac{(a b+a c+b c)^2}{a+b+c}\leq \frac{1}{3} (a+b+c) (a b+a c+b c)\leq \...
9
votes
2answers
236 views

Generating long binary lists fast?

Given list $L$ consisting only of $0$'s and $1$'s, we read $L$ backwards and construct a new list $O$ such that: (we start with $O=\{1\}$ and then apply the two rules:) if we encounter $n$ ...
5
votes
0answers
67 views

Improving speed performance of 'Fit' with BSplines?

Context In the context of this (vaguely controversial) question, I am stumbling into a performance issue with Fit. Let me illustrate on fitting a set of ...
0
votes
0answers
51 views

How can I modify the code to speed up the `Do`?

I need to use the following code to do some calculations. But the running speed of this code is too slow. How can I modify this code to improve the running speed? ...
17
votes
1answer
284 views

Adding Regularisation to Built-in Interpolation function

tl;tr; How to improve performance of regularised Interpolation? Context Since Version 12, Mathematica now incorporates a range of (underrated IMHO) ...
4
votes
1answer
145 views

Reduce the time of computation for $5$-dimensional numerical integration

I need to perform (numerically) the $5$-dimensional integral given in the code below for a large number of values of $\epsilon$. The code I have at the moment takes $\sim 11$ minutes and returns an ...
3
votes
0answers
52 views

DateInterval Min/Max performance issue

Update WRI has confirmed that this is a bug. CASE:4521676 The performance of Min and Max on a list of ...
1
vote
0answers
64 views

Faster methods for performing repeated list manipulations?

I've done my best to pore over the other posts on this site, and to the best of my ability I can't seem to find a good solution to my problem, so I apologize in advance if elements of my question are ...
0
votes
1answer
28 views

Map of an expression in a 3D grid is very slow

I have a quite large expression as function of $R$, $\phi$ and $Z$ as you can see: ...
5
votes
1answer
101 views

Table vs. ConstantArray efficiency with compilation

I've been trying to optimize a bit of code the past couple of days, but think I might be misunderstanding how compilation on certain target functions works. As a most barebones example, I've attached ...
5
votes
1answer
108 views

Determine if the edges of a graph are distinguishable

Mathematica 12.1 introduces edge tagged graph (EdgeTaggedGraph), which is supposed to solve the problem of distinguishability of parallel edges. Unfortunately, the ...
10
votes
2answers
339 views

Testing Turbulence Models

In the 90s, several turbulence models were proposed. Using Mathematica vv 10-12.1 we tested two models: 1) Spalart-Allmaras turbulence model (SA) for aerodynamic applications, published in AIAA ...
5
votes
0answers
45 views

speed up tensor expand

I am using the following code ...
14
votes
0answers
275 views

Why is MemoryInUse[] Very Different from the Actual Amount of Memory Being Used?

I call the MemoryInUse[] function, and it outputs about 256 Megabytes. MemoryInUse[] (*255979528*) However, my activity ...
1
vote
1answer
142 views

Help with solving an equation [closed]

Could anyone please help me find the real solution(s) to a system of equations, or could anyone please help me find an effective solver to solve it? The function ...

1
2 3 4 5
44