# how to realized parallelization computing on 12 CPUs on linux OS

Mathematica 10.3.0 linux Question description: The data I use is a sample of m stocks, each stock has transaction data of n days. The unit of my sample is a 48*1 matrix, which is data for one stock per day. Following is my script:

(*f[x_] is the function to process the data of all days for one stock. The
parameter is used to determine which stock will be processed. *)

f[x_]:=eachdayprocess[ghdparam=Table[0,{i,1,1016},{k,1,48}];
astocklist=Import["/vol6/home/xuefz/dataprocess/batch/server/astocklist.txt"];
aslist=StringTake[astocklist,{(x-1)*9+1,(x-1)*9+8}];
date=Import["/vol6/home/xuefz/dataprocess/server/date.txt"];
For[j=1,j<1017,j++,path="/vol6/home/xuefz/dataprocess/bs/"<>StringTake[date,{(j-1)*9+1,(j-1)*9+8}]<>"/"<>aslist<>".mat";
If[FileExistsQ[path],bs=Flatten[Import[path],1],Continue[]];
bms=bs[[All,1]]-bs[[All,2]];
ghdparam[[j]]=Transpose[bms]
Export["/vol6/home/xuefz/dataprocess/batch/ghdparam/"<>aslist<>"pmltc.mat",ghdparam];
Clear[path,bs,bms];]]

ParallelTable[f[x],{x,100}]//AbsoluteTiming


Now I want to run the script in a computer with 12 CPUs which is based on linux OS. However, every time, only one CPU is used. I wonder how to realized parallelization computing on 12 CPUs.

bms just looks like this:

bms={12.,7.,3.,11.,1.,2.,-2.,1.,0.,-7.,2.,0.,-1.,-3.,-4.,4.,3.,-2.,-11.,-12.,-7.,-8.,-7.,-4.,-4.,-1.,0.,-4.,-11.,0.,-5.,0.,0.,-1.,4.,-10.,2.,-3.,-4.,-9.,-7.,-15.,-8.,-12.,-13.,-26.,-16.,-20.}


[UPDATE]Here is an example. Running the following two scripts, we will get the same outputs. The difference between them is that the "parallelization mode" takes shorter time. What I want is to run the "parallelization mode" in several CPUs because if you run the "parallelization mode" directly, only one CPU will be used.

(*common mode*)
For[i = 1, i < 100, i++, aa = Table[0, {i, 1, 200}];
For[j = 1, j < 201, j++, aa[[j]] = i + j;];
Export["c:\\" <> ToString[i]<>".mat", aa];]

(*parallelization mode*)
f[x_] = dosomework[
For[j = 1, j < 201, j++, aa[[j]] = x + j;];
Export["c:\\" <> ToString[i]<>".mat", aa]];
ParallelTable[f[x], {x, 100}] // AbsoluteTiming

• Could you provide a minimal working example? – Sascha Aug 18 '16 at 5:46
• I guess, you should share the definitions of your intermediate variables to all kernels. So, something like DistributeDefinitions[{list of all your variables}] should be run before 'ParallelTable' – Rom38 Aug 18 '16 at 7:08
• @Sascha I've given an example which has the same logic with the first script. Wish you give me some help, thank you! – Gregory Xue Aug 18 '16 at 14:05
• @Rom38 I am trying it, thank you! – Gregory Xue Aug 18 '16 at 14:19
• @Rom38 Hi, it doesn't work, because 'ParallelTable' will distribute the variable to sunkernels automatically. And what I need is to distribute to different CPUs. – Gregory Xue Aug 19 '16 at 2:22