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
1 answer
12 views

Optimization for NSolve

I am trying to solve the system of n equations numerically. Basically, I am solving saddle point equations for eigenvalues of hermitean matrices and trying to reproduce Wigner's semicircle law: ...
Prokopii Anempodistov's user avatar
2 votes
1 answer
65 views

Fast sampling from Fermi-Dirac distribution under specific conditions

This question is a continuation of the following one. Let us assume a Fermi-Dirac (FD) distribution (times $p^{2}$): ...
John Taylor's user avatar
  • 5,733
2 votes
0 answers
55 views

Speeding up the nested NIntegration consisted of `Exp' and `Bessel' functions

I got stuck with optimizing the nested numerical integration of function with a high number of Bessel functions (first and second kinds) summed and several exponents. I will appreciate any suggestions ...
seva011's user avatar
  • 89
1 vote
1 answer
81 views

Most efficient way of defining the following sets for every step $n$

For each $n\in\mathbb{N}$, how do we compute sets $A_n$ and $B_n$ below: Let $A_1=[0,2/3)$. Let $B_1=(2/3,1]$. If $A_n$ is a union of intervals, then for each interval cut out the middle $1/2^{n+1}$ ...
Arbuja's user avatar
  • 71
2 votes
1 answer
69 views

Find disjoint subsets and their union is {1...9}

I have such a list sets = Select[IntegerDigits /@ (Range[Floor@Sqrt@987654321]^2), DuplicateFreeQ@# && FreeQ[#, 0] &] I want to pick all subsets of ...
vector's user avatar
  • 201
1 vote
0 answers
30 views

Efficient chain rule implementation

(there is a fair amount of context here) I am implementing a generalized chain rule to do some work, say for order 3 in derivatives ($\partial_i = \partial/\partial x_i$): \begin{align} \partial_i \...
Felipe's user avatar
  • 489
0 votes
0 answers
43 views

Memory-Efficient FFT of Sparse Array

I have to take the Fourier transform of quite a large 2D array (2^15 by 2^15, but I'll use 2^10 as an example here). My array is mostly zeros, and since Fourier can ...
az123p's user avatar
  • 239
5 votes
1 answer
141 views

How could I speed up this tensor product?

I have to take tensor products of lists of tensors and I want to include the possibility of tensors whose components have high working precision. The tensors are all totally symmetric, so the first ...
Felipe's user avatar
  • 489
0 votes
2 answers
106 views

NonlinearModelFit extremely slow performance with a single iteration

I have been experiencing very slow performance of NonlinearModelFit. The code that in my case causes that is below. The first part gets the data, the model and ...
atapaka's user avatar
  • 3,954
1 vote
0 answers
36 views

Performing difference in extracting coefficients from a sum

I have an expression ...
Lelouch's user avatar
  • 533
1 vote
0 answers
95 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 ...
user444's user avatar
  • 2,414
4 votes
2 answers
78 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 $\...
Matteo's user avatar
  • 283
4 votes
2 answers
134 views

How to speed up the following algorithm?

I have some random combinations of numbers pairs (where numbers range from 1 to some ntest) ...
John Taylor's user avatar
  • 5,733
3 votes
0 answers
55 views

How to improve Burrows-Wheeler Transform performance?

I have implemented the Burrows-Wheeler Transform as below: ...
flinty's user avatar
  • 25.3k
0 votes
1 answer
75 views

How to select non-repeating pair of numbers?

Consider the following combinations of integers comb, where the integers range from 1 to n ...
John Taylor's user avatar
  • 5,733
4 votes
1 answer
157 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 ...
seva011's user avatar
  • 89
4 votes
1 answer
96 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 ...
user91411's user avatar
  • 400
3 votes
1 answer
92 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. ...
hana's user avatar
  • 2,390
2 votes
2 answers
143 views

Compile does not boost the speed

I have these functions that are used to defineMyFun below ...
MMA13's user avatar
  • 4,674
4 votes
1 answer
144 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: ...
MMA13's user avatar
  • 4,674
-1 votes
2 answers
149 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 ...
Felipe's user avatar
  • 489
2 votes
1 answer
107 views

Fastest splitter?

Consider some dataset ...
John Taylor's user avatar
  • 5,733
5 votes
1 answer
228 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). ...
Felipe's user avatar
  • 489
0 votes
1 answer
85 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. ...
Karen Simonyan's user avatar
4 votes
2 answers
138 views

How to efficiently duplicate and rotate a graphics object?

Consider the following code ...
sam wolfe's user avatar
  • 4,693
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 ...
sudipta's user avatar
  • 63
5 votes
3 answers
338 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. ...
Rémy Galli's user avatar
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 ...
Felipe's user avatar
  • 489
1 vote
0 answers
44 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. ...
Jeff Hunsaker's user avatar
1 vote
1 answer
170 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 ...
user59546's user avatar
  • 115
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}] ...
lesobrod's user avatar
  • 1,667
0 votes
0 answers
65 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 ...
Felipe's user avatar
  • 489
2 votes
2 answers
100 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: ...
John Taylor's user avatar
  • 5,733
4 votes
1 answer
121 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 ...
John Taylor's user avatar
  • 5,733
0 votes
0 answers
58 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 ...
Bravyi's user avatar
  • 21
0 votes
1 answer
62 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) \...
Chloe's user avatar
  • 165
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. ...
Jules Alvarez's user avatar
2 votes
1 answer
153 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 ...
Kamal Saleh's user avatar
1 vote
0 answers
93 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 ...
imida k's user avatar
  • 4,285
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: ...
Confuse-ray30's user avatar
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: ...
Confuse-ray30's user avatar
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 ...
Felipe's user avatar
  • 489
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 ...
Ted Ersek's user avatar
  • 7,124
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 ...
Felipe's user avatar
  • 489
3 votes
0 answers
147 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. ...
smish's user avatar
  • 51
1 vote
1 answer
111 views

Error while using FullSimplify

I am trying to simplify a particular expression using Collect, Series, and FullSimplify: <...
BabaYaga's user avatar
  • 1,836
3 votes
0 answers
110 views

Optimizing memoization in compiled Mathematica code

Consider the following two codes - compiledcode and compiledcode1: ...
John Taylor's user avatar
  • 5,733
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. ...
John Taylor's user avatar
  • 5,733
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....
JJJJJJJJJJJJJJJJ's user avatar
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 ...
anonymous's user avatar
  • 421

1
2 3 4 5
60