Hot answers tagged kernel
16
Since one may not always accurately predict when MemoryContrained is needed, I recommend setting up a watch-dog task. Belisarius described how to do this here in answer to my question. I will reproduce it below as answers that are merely links are discouraged.
In Mathematica 8 you could start a memory watchdog, something along
the lines of:
...
16
You can select which kernel is used by your notebook from the menu item Evaluation -> Notebook's Kernel. By default you will probably only have one kernel called Local available. If your Mathematica license allows for it (typically licenses allow for two simultaneous kernels on a machine), you can add new kernels by selecting the Evaluation -> Kernel ...
15
Here is the method I outlined. I'll illustrate on a small example where we split matrix into top and bottom halves.
In[794]:= SeedRandom[1111];
halfsize = 3;
mat = RandomInteger[{-4, 4}, {2*halfsize, 10}]
Out[796]= {{-3, -1, 3, -3, 3, 3, 3, 3, 4, 2}, {3, 3, -3, 0, 0,
1, -2, -4, 0, -1}, {-3, 4, 3, 0, -2, 4, 3, -2, -2, -2}, {2, 2, 4,
0, -4, 4, -1, -4, ...
12
In the days when computers were slower, and the kernel took a long time to start up (in wall time), a little package was made to help with cleaning up without having to restart the kernel.
This package is still included with Mathematica, and is found in AddOns\ExtraPackages\Utilities\CleanSlate.m (within the Mathematica installation directory). It is more ...
12
In addition to Mr.Wizard's answer.
In many cases it is very practical to stop the evaluation when the actual amount of free physical memory in your system becomes less than specified threshold. You can get the amount of free physical memory very efficiently via NETLink call to GlobalMemoryStatusEx function of kernel32.dll. Here I define a getFreePhysMem[] ...
11
There is an easy way to keep your data in the notebook itself and NOT to save them in external file - using Compress. As @Leonid says here and I already mentioned this before in this answer for similar case with Interpolation function. Start from some output you need:
sol = NDSolve[{D[u[t, x], t] == D[u[t, x], x, x], u[0, x] == 0,
u[t, 0] == Sin[t], ...
11
This message is issued by Function itself. To see this, try
Function[Module[{slot = 1}, Slot[slot]]]
If Function has named formal parameters, the message goes away:
Function[x, Module[{slot = 1}, Slot[slot]]]
So to fix this first we need to find out where is the argument passed to ParallelEvaluate wrapped by Function. Fortunately the parallel tools ...
10
Yes, the Mathematica application on Mac OS contains a few external binaries, which are mostly used for importing and exporting. These files have suffix .exe:
$ find "/Applications/Mathematica 8.app" -name '*.exe'|wc -l
49
But even though .exe is a prefix common for Windows executables, it doesn’t mean that it can’t be used for other things. In fact, Mac OS ...
10
I use a shortcut key Ctrl+Q for Quit[], allowing rapid clearing of all sessions variables. Here is how you can add this to Mathematica:
You will be editing KeyEventTranslations.tr. This is an important system file so be careful. Start by copying the file you are going to edit from the $InstallationDirectory to $UserBaseDirectory in the same tree. This ...
8
I have the following commands in my init.m file, which can be found in $UserBaseDirectory/Kernel/init.m.
eraseAll := ClearAll[Evaluate[$Context<>"*"]];
eraseAll::usage="eraseAll clears all values, definitions, attributes, messages and defaults associated with symbols in the current context"
removeAll := Remove[Evaluate[$Context<>"*"]];
...
8
You can put your calculation inside TimeConstrained. However in your case, probably the better idea is to restrict the used memory. That's done with MemoryConstrained.
If you don't want to figure out the available memory yourself, see here for how to do it automatically.
For example this terminates a calculation if the calculation needs more than 1 GB of ...
8
You can make use of either TimeConstrained or MemoryConstrained to terminate evaluation when it runs out of time or memory respectively.
For example, if you have a function that has a reasonable memory footprint, but takes time to evaluate, you can abort evaluation after a certain amount of time (in seconds) has elapsed, as:
...
8
The option to save a variable, a value, in a notebook, that I find simple and deserves a chance is to store them in the notebook's tagging rules. You can compress it if you want, or you can autoload it through an initialization cell or through the NotebookDynamicExpression too.
The core is this:
r = RandomReal[{-1, 1}, 1000000];
...
8
Since graphics can no longer be exported without access to a front end, even with remote connections you have to have X11 installed and working on your local machine. Therefore, the first thing you should do is: go to the web site http://xquartz.macosforge.org/landing/ and download the latest version of X11 appropriate for your OS X version. After installing ...
8
In addition to assigning to In, the Mathematica main loop assigns the input to InString before it is parsed as an expression. You can then retrieve InString[1] and parse the result with ToExpression, wrapping it in Defer to prevent it from evaluating immediately:
In[5]:= ToExpression[InString[1], StandardForm, Defer]
Out[5]= Round[SessionTime[]]
You can ...
8
Here is a very simple example of how to use MathLink for this sort of communication. I will use normal code blocks for kernel A and quoted code blocks for kernel B. You must evaluate these in the order shown.
link = LinkCreate["a uniquely named link"];
link = LinkConnect["a uniquely named link"];
LinkActivate[link];
MathLink`AddSharingLink[link];
...
8
Try this out:
Lets say you have a variable called kernelA in one notebook using Kernel A. Then:
CurrentValue[$FrontEndSession, {TaggingRules, "KernelA"}] = kernelA
In your other notebook, running Kernel B just evaluate
variableFromOthernotebook = CurrentValue[$FrontEndSession, {TaggingRules, "KernelA"}]
Edit
An alternative that might be faster ...
8
As J.M. pointed out, this can be achieved by using an init.m file.
init.m files are loaded on startup. The documentation can be found here.
To load the VectorAnalysis package on each startup, you can write the init file using Export. The snippet below will append a Needs["VectorAnalysis`"] to the kernel init.m file:
initFileName = ...
8
Not a full answer, but a little too long for a comment.
You may need to pay a close attention to licensing. If the results of your computation are used on a single machine (e.g. somehow saved to a database or used further in the computation), you may only need a professional single-machine license. If they are going to be used by other employees / machines ...
8
I would not classify this as a bug. The behaviour of a Slot expression that is not directly contained within a Function expression is not defined by the documentation, and is unreliable in practice. Consider the following two functions:
f[x_] := x + 100
g[x_] := x + # &[100]
They appear to be essentially equivalent, but it just so happens that the ...
7
webMathematica is probably the most secure solution. Unless someone hacks your sever there is no way to get to the source of your program.
Using webMathematica you could easily use standard Web services. Check out the documentation
So e.g., you can create a macro in Excel and then it looks like
In this way you use standard web technology and keep all ...
7
This is easily fixed by:
Send[kernels:{___kernel}, expr_] := Table[Send[k, expr], {k, kernels}]
instead of
Send[kernels:{___kernel}, expr_] := Send[#, expr]& /@ kernels
While changing Parallel.m is one possibility, we can also
change the DownValues programmatically:
Parallel`Developer`Send;
Unprotect[Parallel`Developer`Send];
...
6
Since you have defined your function recursively, you will first need to solve the recurrence equation using RSolve to get the general form.
For example:
F = f /. First @ RSolve[{f[n] == x f[n - 1], f[1] == x}, f, n]
(* Function[{n}, x^n] *)
Exponent[F[k], x]
(* k *)
6
Does Exponent do what you expect from degreeOf[]?
f = (x^3 + 1)^3 + 1;
Exponent[f, x]
(* ==> 9 *)
6
A version of this question has been asked before on StackOverflow. You can look at the answers there for some options. To summarize, Mathematica currently does not natively support such a fine-grained encapsulation, which would certainly be a nice thing to have (IMO).
One simple thing you can do is to load the entire package via
Block[{$ContextPath}, ...
6
If there is such a thing, I want to know it for windows and linux based OS'es also.
Battling with the same problem I have found 2 partial solutions:
ctrl+s before hitting shift+enter (I think it's command+s for Mac's)
if you ignored #1 then you might still be able to screenshot the code and reenter it
I have tried TextRecognize to restore the text from ...
6
Could use $Pre to wrap things in MemoryConstrained. I'll illustrate with an unusually tight constraint.
SetAttributes[memcon, HoldAll]
memcon[new_] := MemoryConstrained[new, 10^4]
$Pre = memcon;
Examples:
ByteCount[Range[10^6]]
(* Out[4]= $Aborted *)
s = N[SparseArray[Table[{2^i, 4} -> i, {i, 20}]]]
(* Out[5]= $Aborted *)
6
As soon as you set your notebook context to 'unique to this Notebook', the notebook's context is no longer Global`, but, well, unique to the notebook.
I can't test right now, but assuming you are not in an explicitly opened context (like after Begin or BeginPackage), I think the following should work:
ClearAll@@{$Context<>"*"}
At least it works in ...
5
As an alternative to DumpSave, what I've done in the past was to Compress the relevant results and store them within the same notebook. You can optionally set things up so that your data/results would self-uncompress themselves upon being called the first time. For one example of such use, see this answer.
In any case, the advantage of this approach is ...
5
Of course this is just an academic technical exercise and cannot be really used due to legal restrictions of the CDF license.
On Linux and Windows with JLink this seems to work easily:
[rolfm@localhost cdffun]$ cat CDFFun.java
/********************************************************
* CDFFun.java
* ...
Only top voted, non community-wiki answers of a minimum length are eligible





