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 populate it, I'm using an expensive 4 Do loop
Do[ Do[ Do[ Do[ Print[m, n, p, q]; k = (m - 1) nC + n; l = (p - 1) nC + q; If[k <= l, A[[k, l]] = cf[Nfunc, xi, yi, wix, wiy, m, n, p, q], 0]; , {q, 1, J, 1}] , {p, 1, I, 1}] , {n, 1, J, 1}] , {m, 1, I, 1}] Knowing that $A_{kl}$ for a $I=J=2$, its components are (mnpq)
$$ \begin{bmatrix} (1111) & (1112) & (1121) & (1122)\\ & (1212) & (1221) & (1222)\\ symm. & & (2121) & (2122)\\ & & & (2222)\\ \end{bmatrix} $$
Does anyone know a more efficient way to populate it? Maybe using a bult-in function?
UPDATE
cf = Compile[{{Nfunc, _Real, 2}, {xi, _Real, 1}, {yi, _Real, 1}, {wix, _Real, 1}, {wiy, _Real, 1}, {m, _Integer}, {n, _Integer}, {p, _Integer}, {q, _Integer}}, Module[{sum}, sum = 0.0; For[i = 1, i <= Length@xi, i++, For[j = 1, j <= Length@yi, j++, sum = sum + (8 \[Pi]^2)/ a^2 m p Cos[(m \[Pi] xi[[i]])/((1/ 2) a)] Sin[(n \[Pi] yi[[j]])/((1/ 2) b)] Cos[(p \[Pi] xi[[i]])/((1/ 2) a)] Sin[(q \[Pi] yi[[j]])/((1/2) b)]*wix[[i]]* wiy[[j]]*Nfunc[[i, j]]; ] ]; sum], CompilationTarget -> "C", RuntimeAttributes -> {Listable}, Parallelization -> True, RuntimeOptions -> "Speed"]; 
Do. $\endgroup$cf? Is itListablein any of its arguments? I.e. wouldcf[nFunc, xi, yi, wix, wiy, m, n, p, {q1, q2, q3}]correctly give a list of three values? $\endgroup$Do$\endgroup$m,n,p,qare integers. All others are lists.cf = Compile[{{Nfunc, _Real, 2}, {xi, _Real, 1}, {yi, _Real, 1}, {wix, _Real, 1}, {wiy, _Real, 1}, {m, _Integer}, {n, _Integer}, {p, _Integer}, {q, _Integer}}.$\endgroup$cf, will it work? For instance, if I want to findSin[x]for x = 1, 2, 3, ..., 100 I don't need to loop, I just doSin[Range[100]]. I'm asking whether this applies to your functioncf. $\endgroup$