2
$\begingroup$

I am having a Hermitian Matrix(HCF[k]) depending on a parameter $k$.

My job is to plot the Eigenvalues of the matrix as the parameter $k$ is changed.

But I am facing some problems.
(i) My Mathematica file size, which is of around whopping 90Mb, when HCF[k] is around $284\times284$.
(ii) This part of code is very slow as the size of HCF[k] is increasing.

kdel = 0.00001; (* offset *)
kIn = -π - kdel;  (*Initial value of k *)
kFin = π + kdel;  (*Final value of k *)
kInc = 0.001; (*Increment of k*)

eigeng = 
 ParallelTable[Eigenvalues[HCF[k]], {k, kIn, kFin, kInc}];


kList = ParallelTable[k, {k, kIn, kFin, kInc}];


kFList = ParallelTable[kList, {i, Transpose@eigeng}];

dataToPlot = Flatten[{kFList\[Transpose], eigeng}\[Transpose], {{1, 3}, {2}}];

Graphics[{Point[{#1, #2}]} & @@@ dataToPlot, Frame -> True,
...(* for the aesthetic of plot, i.e. axis title, range and bla bla*)]
  • Is there a way the size issue can be overcome?
  • Is there a way the code can be sped up a little bit?(I checked my rest of the code, it is very fast, which I did by breaking and evaluating it into small cells).

Addendum

  • Form of HCF[k], as it is huge I will try to show you how it looks for small size say
    \left( \begin{array}{cccccc} -20 \pi & -\frac{e^{i k}}{2} & 0 & -\frac{1}{2} & 0 & 0 \\ -\frac{1}{2} e^{-i k} & -20 \pi & -\frac{1}{2} & 0 & 0 & 0 \\ 0 & -\frac{1}{2} & 0 & -\frac{e^{i k}}{2} & 0 & -\frac{1}{2} \\ -\frac{1}{2} & 0 & -\frac{1}{2} e^{-i k} & 0 & -\frac{1}{2} & 0 \\ 0 & 0 & 0 & -\frac{1}{2} & 20 \pi & -\frac{e^{i k}}{2} \\ 0 & 0 & -\frac{1}{2} & 0 & -\frac{1}{2} e^{-i k} & 20 \pi \\ \end{array} \right)
$\endgroup$
5
  • $\begingroup$ What does HCF look like? $\endgroup$
    – MarcoB
    Commented Feb 13, 2017 at 20:55
  • $\begingroup$ @MarcoB Please see the edit, similar form may look like for 284X284. $\endgroup$
    – L.K.
    Commented Feb 14, 2017 at 9:28
  • $\begingroup$ Please post code, not LaTeX, so one can copy/paste it. It would be best if you could either propose a smaller version of your matrix, or simply post the whole matrix somewhere (e.g. pastebin. Also, your kList and kFList do not need to be defined using ParallelTable; a simple Range would work, and probably be faster too. In general, have you tried without parallelization? Are you sure that parallel execution leads to a speedup? $\endgroup$
    – MarcoB
    Commented Feb 14, 2017 at 23:45
  • $\begingroup$ @MarcoB Here you will find the Matrix(paste bin, thanks for this). I always thought Parallel does work fast(may be I was in some illusion). So, never thought of out of parallelization. I am sorry I can't give the code that generated the matrix as there is some work going on(some restrictions on me), I really hope you will understand it(take it good). I gave you the matrix and your help will definitely show some light on the problem. $\endgroup$
    – L.K.
    Commented Feb 15, 2017 at 10:00
  • $\begingroup$ @MarcoB How kFList using Range, I failed in doing that. But able to do the kList $\endgroup$
    – L.K.
    Commented Feb 15, 2017 at 16:14

1 Answer 1

3
$\begingroup$

The following uses your definitions of the matrix from pastebin, and of starting points and increments.

Parallelization does help to speed up the calculation of the eigenvalues, but you have to distribute the definitions of your helper variables to the parallel kernels using DistributeDefinitions first:

AbsoluteTiming[Table[Eigenvalues[mat], {k, kIn, kFin, kInc}];]
(* Out: {142.851, Null} *)

DistributeDefinitions[kdel, kIn, kFin, kInc]
AbsoluteTiming[ParallelTable[Eigenvalues[mat], {k, kIn, kFin, kInc}];]
(* Out: {90.5666, Null} *)

This is on a two-core machine, so the benefits from parallelization may be even better on higher core-count machines.


Having said that, the definitions of kList and kFList can be simplified:

kList = Range[kIn, kFin, kInc];
kFList = ConstantArray[kList, Length@Transpose@eigeng];
$\endgroup$
4
  • $\begingroup$ Better additions, like kList and kFList and DistributeDefinitions[kdel, kIn, kFin, kInc]. I think further simplifications are not possible. For Graphics also. As from my side, speed I got from previously is about 0.5s. Less but good $\endgroup$
    – L.K.
    Commented Feb 15, 2017 at 18:33
  • $\begingroup$ @L.K. I think another important consideration, even for the preparation of the graphics objects, is whether you do need to try and plot all those points. There is no way that you can actually see that many points on a computer screen, or in most media printouts, so perhaps pruning the list to a more manageable size (plotting every ten points etc) would help. $\endgroup$
    – MarcoB
    Commented Feb 15, 2017 at 18:48
  • $\begingroup$ @L.K. From a more fundamental standpoint, your matrix is very sparse, and has a relatively simple structure. I think it might be worth it to see if you can manipulate the math to determine whether you want (or need) to calculate all eigenvalues: there are numerical methods to calculate only a fraction of those, e.g. by magnitude (see the Method options for Eigenvalues). Perhaps some clever pencil-and-paper math might reduce the size of your problem. $\endgroup$
    – MarcoB
    Commented Feb 15, 2017 at 18:50
  • $\begingroup$ thanks for the valuable informations. For sure I will check the possibilities as you have mentioned. $\endgroup$
    – L.K.
    Commented Feb 15, 2017 at 19:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.