Group Abstract Group Abstract

Message Boards Message Boards

0
|
7.8K Views
|
4 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Script ran with MathKernel -script much slower than in the notebook

Posted 11 years ago
4 Replies

I was wondering if it was related to parallelization or something. I tried the Parallelize command on the table command itself but I received errors.

Hm, strange. With Mathematica 10 and Mathematica 9 on Windows I get about 12.1 sec in all cases.

I'm using a local directory (I called it "C:\Users\arnoudb.WRI\scriptslowdown\") because my Documents directory is a network backed directory, which can lead to slowness itself (you might want to see if you have the same issue, saving locally to a drive is usually faster, especially when you are writing a lot of data (which is not an issue in this case though)).

POSTED BY: Arnoud Buzing

Hi I don't think so. It is mainly numerical stuff. Since I cannot share my test data and my actual procedure I have created a minimal working example that shows the same trend though in a much smaller way.

Here is my example:

SetDirectory["C:\\Users\\username\\Documents\\"];


OutputBackup=$Output;
MessageBackup=$Messages;
debugFile=OpenWrite["Debug.txt",FormatType->OutputForm,TotalWidth -> Infinity];
logFile=OpenWrite["LogFile.txt",FormatType->OutputForm,TotalWidth -> Infinity];
AppendTo[$Output,debugFile];
AppendTo[$Messages,debugFile];


TotalPressure=30 10^5;
TotalPressureError=500 0.15/100 6894.75729; (*0.15% of full scale reading which is 500 psi *)
StaticPressure=2352011;
StaticPressureError=500 0.15/100 6894.75729; (*0.15% of full scale reading which is 500 psi *)
\[Gamma]=1.4;
TotalTemperature=20+273.15;
TotalTemperatureError=1;


WriteString[logFile,
StringJoin[
"MonteCarlo analysis took ",ExportString[
AbsoluteTiming[MCRes=Module[{P0x,px,Machx,T0x,Tx},
Table[
{
P0x=TotalPressure+RandomReal[{-TotalPressureError,TotalPressureError}],
px=StaticPressure+RandomReal[{-StaticPressureError,StaticPressureError}],
T0x=TotalTemperature+RandomReal[{-TotalTemperatureError,TotalTemperatureError}],
Machx=Sqrt[2/(\[Gamma]-1) ((P0x/px)^((\[Gamma]-1)/\[Gamma])-1)],
Tx=T0x/(1+(\[Gamma]-1)/2 Machx^2)},
{iMC,1,1000000}]];][[1]],"CSV"],"s to complete"]];


Close[logFile];
Close[debugFile];

When I run this from a brand new Mathematica 9.0 session it takes 20 seconds to execute. When I run it from command line

 "/cygdrive/c/Program\ Files/Wolfram\ Research/Mathematica/9.0/MathKernel.exe -script MinimalWorkingExample.m"

it takes 30 seconds to complete.

The type of operations performed are similar to the one I have to except that I have also a FindRoot and a loop that I made to converge over some values. Those will take time but my expectations were they ought to take the same time independently from the way you run it.

Does your code have any TimeConstrained or MemoryConstrained expressions in it? [#49655]

POSTED BY: Arnoud Buzing
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard