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.
2,956
questions
1
vote
0
answers
91
views
Speed up the evaluation of two million consecutive eigenvalues using `NDEigenvalues`?
$Version
"13.0.1 for Linux x86 (64-bit) (January 29, 2022)"
I have $28$GB of RAM.
I need to calculate two million consecutive eigenvalues for a given ...
3
votes
2
answers
71
views
Speed up sparse Hermitian matrix-vector product
I am interested in speeding up as much as possible the dot product in the specific case of a multiplication of a $n\times n$ sparse hermitian matrix $H$ (where $n$ is typically large, let's say $\...
4
votes
2
answers
132
views
How to speed up the following algorithm?
I have some random combinations of numbers pairs (where numbers range from 1 to some ntest) ...
3
votes
0
answers
51
views
How to improve Burrows-Wheeler Transform performance?
I have implemented the Burrows-Wheeler Transform as below:
...
0
votes
1
answer
74
views
How to select non-repeating pair of numbers?
Consider the following combinations of integers comb, where the integers range from 1 to n ...
4
votes
1
answer
145
views
Effective use of idle cores when using parallelization
Assume I have 10 cores in a CPU. And I run ParallelMap on them:
LaunchKernels[10];
ParallelMap[F1,L1];
where L1 is a list of ...
3
votes
1
answer
90
views
Efficient way of creating matrices from a very large array while avoiding singular values
I need to create matrix from a large array (>>10000 elements) for further use. I have tried Outer and ParallelTable commands, among which Outer seems to be faster when the array size is not so ...
3
votes
1
answer
90
views
How to improve code speed for the large datasets?
How can I improve the speed of this code? It runs okay but is quite slow for large datasets, for example, 5 million elements.
...
2
votes
2
answers
138
views
Compile does not boost the speed
I have these functions that are used to defineMyFun below
...
4
votes
1
answer
141
views
How can we improve performance when passing data to a function?
I have a defined function $F(x,y,z)$ and data of $(x,y)$ and would like to evaluate the sum of F over data and at different z values. Here is a minimal example:
...
-1
votes
2
answers
142
views
Is it possible to pass by reference at the system level?
I am reformulating the question since it was apparently unclear. One of the comments made me find the correct programming language "syntax" for what I wanted to do(Thanks Nasser).
In this ...
1
vote
1
answer
104
views
Fastest splitter?
Consider some dataset
...
5
votes
1
answer
223
views
List of built-in functions written in Wolfram Language
I was developing a program and noted that Grad[0,{x,y,..}] was taking too much time to return zero vector (I do this many times, so the performance matters to me). ...
0
votes
1
answer
76
views
Solve constraints don't work properly
So in my previous question, I was trying to find two parameters kV and km for an implicit function using FindFit(FF) command and I did it but the problem is that it takes around an hour to do it. ...
4
votes
2
answers
134
views
How to efficiently duplicate and rotate a graphics object?
Consider the following code
...
1
vote
0
answers
83
views
How to efficiently calculate matrix operations when the elements are defined as functions?
I'm trying to calculate the one-body density matrix of a system of particles as described in this article, given in equations 14 and 15.
Here, is my code but it seems very slow. Is there any efficient ...
5
votes
3
answers
335
views
How to speed up Outer[Subtract, vect1,vect2]?
My Nbody code use a lot of Outer[Subtract, vect1,vect2]. A lot means ten thousands to one hundred thousands times !! This is at the heart of my Nbody code, and I need to speed up this instruction. ...
2
votes
2
answers
118
views
How can I enforce the use of Subtract and Divide?
It has been noted before, here and here, that when you enter a/b or a-b, Mathematica does not convert these to ...
1
vote
0
answers
43
views
Why did my animated Graphics3D stop functioning after Nvidia GPU driver update? Now I have to end Mathematica process in the task manager
The following code used to work fine until just after a recent Nvidia driver update. Running the code causes Mathematica to completely hang and I must end the Mathematica process in the task manager.
...
1
vote
1
answer
169
views
How to improve the speed of this numerical integration which includes calculations of large matrix?
The integrand is Re[k^2*Sin[2*theta]*T], where k is constant, theta is a variable (x, y and fi are the other variables), and T includes calculation of large matrix ...
0
votes
0
answers
35
views
Compile constraints for NMinimize
I use complicated constraints for optimisation, something like
Table[
EuclideanDistance[pts[[i]], pts[[j]]] >= 1
, {i, numPts - 1}, {j, i + 1, numPts}]
...
0
votes
0
answers
64
views
How do you rate Mathematica and Python in terms of numerical computation? [duplicate]
I often hear, in the physics community, that python is faster and overall better than mathematica for numeric calculations. But this seems very subjective since code badly written in one language can ...
2
votes
2
answers
95
views
Analog of monitor which does not lead to freezes of the interface
I have some heavy computation wrapped by Monitor and ProgressIndicator. It is the template:
...
4
votes
1
answer
106
views
Why does Mathematica's interface freeze when scrolling to the evaluating cell?
I have some heavy computations in Mathematica that use parallelization. The CPU consumption is ~80-90%. I use ProgressIndicator to trace the progress of the ...
0
votes
0
answers
56
views
Recursion limit for NDSolve
I have a fairly complex equation containing many terms, I can use the NDSolve for solving the differential equation for lesser terms (6400ish). But can't do it for ...
0
votes
1
answer
61
views
How to Speed Up Piecewise Symbolic Integration
In Mathematica, I am attempting to integrate over 2-D $\phi$ "hat functions" for a FEM scheme. I suppose I am only observing "interior points" in the domain $\left( 0 , 2 \right) \...
0
votes
0
answers
125
views
NDSolve gives High Oscillatory Solution [duplicate]
I want to solve a differential equation of second order with complex initial conditions.
...
2
votes
1
answer
149
views
Speeding up minimization problem related to a minimal surface
I am trying to find the minimum of the function $$f(x)=\int_0^1(1+t^x)\sqrt{1+x^2 t^{2(x-1)}}dt$$ which arises from trying to minimize the surface area of a function rotated around the $x$ axis. Here ...
1
vote
0
answers
89
views
The first step to Speed Up using GPU
If we run the following code, mathematica kernel uses only CPU :
LinearOptimization[
x + y, {x + 2 y >= 3, x >= -1, y >= -1}, {x, y}]
I want the ...
0
votes
1
answer
35
views
Map Integrate onto one single term
This is related to the question (Integrate many simple terms fast) I had before, where Nasser gave me an answer which worked 'most of the time' but not always. Context: ...
1
vote
1
answer
67
views
Integrate many simple terms fast
I have the following problem which I do not even know if there is a solution.
Say I have following integral:
...
1
vote
1
answer
86
views
Recursive application of Grad in scalars
I am looking for an efficient way to apply Grad recursively to a scalar function. The code I have so far is in the structure below. I define the scalar function outside the loop, take its derivatives ...
10
votes
5
answers
1k
views
How can I get samples of f(x) that are roughly evenly spaced?
I am looking for an efficient way of getting 60 to 80 samples of an arbitrary f(x) such that the distance between adjacent samples are approximately equal. My first attempt is based on a first order ...
3
votes
1
answer
91
views
Tensor product inside the compiler
The compiler does not have support for tensor product, are there any packages that implements the tensor product in a way that can be compiled? I need to take the tensor product of several numeric ...
3
votes
0
answers
144
views
Why does this small change make execution 30,000x slower? [duplicate]
Recently, when using Mathematica to process some triangle meshes, I noticed an unusual slowdown when processing a large mesh.
...
1
vote
1
answer
108
views
Error while using FullSimplify
I am trying to simplify a particular expression using Collect, Series, and FullSimplify:
<...
3
votes
0
answers
108
views
Optimizing memoization in compiled Mathematica code
Consider the following two codes - compiledcode and compiledcode1:
...
1
vote
0
answers
60
views
Speed limitations when importing files from .zip archive
I have .m files with a total size of ~500 MB. Their import is really fast, within less than 1 second. In contrast, I may pack them into a .zip archive. The importing then is much slower, ~20 s. ...
0
votes
0
answers
83
views
Break symbolic eigenvalue calculation early
I am computing eigenvalues of matrices with single monomial entries (x,y,z, etc.) and for efficiency, need to truncate calculations early if any eigenvalues contain non-linear (x^{2}, \sqrt(x),x*y etc....
2
votes
1
answer
89
views
Efficient overwriting of specific tensor elements
I have a square, $n\times n$ rank 2 tensor x, a length $m$ list p of (distinct) positions in it, and a length $m$ list ...
2
votes
1
answer
78
views
Summing second elements in list of pairs whenever first elements fall in range
Say one has a list of pairs
list = {{0,1},{1,2},{1,4},{5,6},{3,2},{3,5},{0,9}}
and one wants to sum the second element of the pairs for which the first element is ...
3
votes
0
answers
66
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
3
answers
181
views
Evaluating series expansion is very slow
I need in my work to get series expansion of
(2 E^x x HypergeometricPFQ[{1}, {1/2 + E^-x/4, 1 + E^-x/4}, -(x^2/4)])/Gamma[E^-x/2] + x^(1 - E^-x/2) Sin[x]
up to $n=...
2
votes
1
answer
103
views
Efficiently Finding Weighted Integer Partitions
Suppose we have some list of natural numbers $\{ 1, 2, \dots, N \}$ and each natural number $i$ has a 'weight' $w_i$. I would like to generate the all the integer partitions which satisfy the ...
0
votes
0
answers
129
views
How to quickly generate the values satisfying the given condition?
Consider some domains in variables th, z and some condition cond defining the domain of a ...
1
vote
1
answer
140
views
Parallelized Monte-Carlo
I'm trying to do a little Monte-Carlo, and the code is working great, but slows down when I try to increase the number of iterations, any suggestions on how I can parallelize this? Every way I've ...
1
vote
0
answers
67
views
What can be improved in the following custom interpolation?
Consider some test data: a grid of x, y, and values of some function on this grid:
...
2
votes
1
answer
129
views
Speeding a Manipulate illustrating convolution
I'd like to illustrate the mathematical process of convolution ($f(x) \star g(x)$) with an interactive Manipulate, but the evaluation is far too slow for a class ...
1
vote
0
answers
63
views
why N is slower when setting precision [closed]
Column[{
N[Sin[1] + Cos[1], 5] // AbsoluteTiming,
N[Sin[1] + Cos[1]] // AbsoluteTiming
}]
{0.000073,1.3818}
{0.000015,1.38177}
...
4
votes
1
answer
218
views
How to quickly sample points from the given PDF data?
Consider some data (distr.dat). It is a tabulated PDF: x, y, z, PDF[x,y,z], where x is some parameter (and the integral of ...