Tag Info

Hot answers tagged

19

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


17

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

As people have figured out in the comments, this was a quite deliberate decision on our part. One which I can take a significant amount of credit/responsibility/blame for. First a little bit about the extra kernel. The kernel is enabled using a password which causes it to run in Wolfram Player mode. It runs using the same binary as the regular kernel, ...


15

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


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, ...


15

To access the errors, you need to invoke the Front End directly from the kernel. In effect, you end up telling the kernel to tell the FE to tell the kernel to do something, so that the FE can report any errors it finds. The method I use is SetAttributes[getFrontEndErrors, HoldAll]; getFrontEndErrors[gexpr_] := Module[{nb}, ...


14

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], ...


13

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 (which is available both under 32 ...


13

You need to daemonize your script: nohup math -script test.txt 0<&- &>/dev/null & Now this will run as a background process with no output captured. If your script does indeed produce output, just replace /dev/null with the filename. In order to daemonize something you need to disconnect all the automatically connected streams (stdin, ...


12

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


12

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


11

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

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]; ...


9

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


9

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: ...


9

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


9

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


9

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


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

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

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

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

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

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


8

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


8

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]; ...


8

To give references to the first part of your question: The best description about the main evaluation loop I have ever read can be found in (as already stated in the comments) Power Programming with Mathematica: The Kernel by David Wagner. A free pdf version of this book can be downloaded here. Therein, he refers to the tutorial Mathematica Internals: A ...


8

This turns out to be easy. In Windows 7: Add C:\Program Files\Wolfram Research\Mathematica\9.0\ to the path. Write procedures for what you want to do in The Wolfram Language, and save in a .m file. Add MathKernel.exe -script filename.m to the Windows Task Scheduler. Specify that the job runs in the directory containing the .m file. That seems to be it. ...


8

You can use GNU screen to make a sort of persistent terminal that allows you to resume work wherever you left off. Take a look at the many tutorials available. It's not completely clear from your question whether the better solution is this, or nohup (see Stefan's answer). Use nohup if your workflow is non-interactive: log in, start a batch job that ...


7

Updated This happens because your DynamicModule returns a dynamic object of which x is passed on to the front-end before the scheduled task starts, so the front-end-x cannot be modified anymore by any process (more details at the end). The problem can be further simplified. This works: RemoveScheduledTask@ScheduledTasks[]; DynamicModule[{x = 0}, ...



Only top voted, non community-wiki answers of a minimum length are eligible