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. *)



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:


[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
  • 2
    $\begingroup$ Could you provide a minimal working example? $\endgroup$ – Sascha Aug 18 '16 at 5:46
  • 2
    $\begingroup$ 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' $\endgroup$ – Rom38 Aug 18 '16 at 7:08
  • $\begingroup$ @Sascha I've given an example which has the same logic with the first script. Wish you give me some help, thank you! $\endgroup$ – Gregory Xue Aug 18 '16 at 14:05
  • $\begingroup$ @Rom38 I am trying it, thank you! $\endgroup$ – Gregory Xue Aug 18 '16 at 14:19
  • $\begingroup$ @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. $\endgroup$ – Gregory Xue Aug 19 '16 at 2:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.