I am attempting to complete the following quadruple sum:

ParExpr12 = 1/(2 eta)*ParallelSum[(coeff[[n1,n2]]*coeff[[n3,n4]]*(r12ExpUnit[n1, n2, n3, n4] + r12ExpUnit[n1, n2, n4, n3] + 
   r12ExpUnit[n2, n1, n3, n4] + r12ExpUnit[n2, n1, n4, n3])), {n1,1, K}, {n2, 1, K}, {n3, 1, K}, {n4, 1, K}]

Here, coeff is an 11x11 Sparse Array. When I simply use Sum, the calculation takes up to 6 hours if K=11, but it will run. However, when trying Parallelize, ParallelSum, or anything of the sort, I get the following messages:

Part::pkspec1: The expression n1 cannot be used as a part specification.

This message occurs for n1,n2,n3, and n4 and the calculation will never finish. It also seems as though n1,n2,n3,n4 are being treated as "null."

Can someone explain what I'm doing wrong or any other way to streamline this calculation? Thanks!

  • 1
    $\begingroup$ I can't seem to reproduce the error you see. Can you include the definitions of the other parameters? Note also that you shouldn't use K as a variable, since it is a built-in symbol (and more in general, you should stay away from uppercase symbols, since you may have conflicts with the built-ins); use e.g. k instead. $\endgroup$ – MarcoB Jul 6 '16 at 21:06
  • 1
    $\begingroup$ I can't believe it, but it seems that using the capital K was actually the problem. Thank you so much! $\endgroup$ – Paularooskies Jul 6 '16 at 21:10
  • $\begingroup$ Glad it helped! $\endgroup$ – MarcoB Jul 6 '16 at 21:16
  • $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! $\endgroup$ – Michael E2 Jul 6 '16 at 21:54