I have a problem with NMinimize function that does not seem able to use the 8 processors of my machine (16 kernels with hyperthreading) to calculate the function to be minimized. If I calculated for given values of the parameters the same function Mathematica uses several processors. To do that I use ParallelTable function. But when I use NMinimize my computer use only one processor.
here is the function to minimize :
func = Total[
ParallelTable[(mmoyen0[datamhtcor[[j, 1]], datamhtcor[[j, 2]],
datamhtcor[[j, 3]], -10, 0., 2, 2, 2] -
datamhtcor[[j, 4]])^2, {j, 1, Length[datamhtcor]}]]
*where mmoyen0 is another function which diagonalize matrices. It depends on variables (b, db, t) and parameters (dist,ee, gx,gy,gz) datamhtcor are a list of experimental data {magnetic field B, small variation of B,Temperature, axial anisotropy, rhombic anisotropy, Lande factor x, Lande factor y, Lande factor x}
SetAttributes[mmoyen0, Listable]
mmoyen0[(b_)?NumericQ, (db_)?NumericQ, (t_)?NumericQ, (dist_)?
NumericQ, (ee_)?NumericQ, (gx_)?NumericQ, (gy_)?NumericQ, (gz_)?
NumericQ] :=
Module[{i, mm},
mm = Table[
msurh0[b, db, t, dist, ee, gx, gy, gz, cossintetaphi[[i, 1]],
cossintetaphi[[i, 2]], cossintetaphi[[i, 3]]], {i, 1,
Length[cossintetaphi]}];
Total[mm, {1}]]/Length[cossintetaphi];
msurh0 is the following function
msurh0[(b_)?NumericQ, (db_)?NumericQ, (t_)?NumericQ, (dist_)?
NumericQ, (ee_)?NumericQ, (gx_)?NumericQ, (gy_)?NumericQ, (gz_)?
NumericQ, (cos_)?NumericQ, (sincos_)?NumericQ, (sinsin_)?
NumericQ] :=
mx20[b, db, t, dist, ee, gx, gy, gz, cos, sincos, sinsin] sincos +
my20[b, db, t, dist, ee, gx, gy, gz, cos, sincos, sinsin] sinsin +
mz20[b, db, t, dist, ee, gx, gy, gz, cos, sincos, sinsin] cos
and mx20 is
mx20[(b_)?NumericQ, (db_)?NumericQ, (t_)?NumericQ, (dist_)?
NumericQ, (ee_)?NumericQ, (gx_)?NumericQ, (gy_)?NumericQ, (gz_)?
NumericQ, (cos_)?NumericQ, (sincos_)?NumericQ, (sinsin_)?
NumericQ] :=
Module[{kk, nak, \[Beta], i, som1, som2, en1, en2},
nak = 8.314282370753999 10^7; \[Beta] = 4.66864374 10^-5;
kk = 0.695054;
(*calcul de la dérivée suivant l'axe x*)
som1 = 0; som2 = 0;
en1 =
Sort[Eigenvalues[
matx20[b, db/2, gx, gy, gz, dist, ee, cos, sincos,
sinsin, \[Beta]]]];
en2 =
Sort[Eigenvalues[
matx20[b, -db/2, gx, gy, gz, dist, ee, cos, sincos,
sinsin, \[Beta]]]];
som1 = Total[Exp[-en1/(kk t)]];
som2 = Total[Exp[-en2/(kk t)]];
nak t (Log[som1] - Log[som2])/db/5585];
To calculate the function func Mathematica use several processors but when this function is used in NMinimize, Mathematica use only one processor
Do you have any suggestions to force Mathematica to use several processors to calculate the func function. It is really a pity to see that Mathematica only use 6% of power of my computer (I have 16 possible kernels on my machine)
Regards
Yves
Attachments: