Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have my Mathematica code in a .m file and I run it from the command line with some parameters. I was wondering, if there is no overlap in input and output files, can I run the same .m file simultaneously with different inputs? Will this create any problems? My code is pretty huge, so I don't want to try that unless I am sure.

I use the following command on the unix/linux commandline:

for i in $var
do
math -noprompt -script "scriptname.m" "parameter1" "parameter2"
done

I would like to run something like:

for i in $var
do
math -noprompt -script "scriptname.m" "parameter1" "parameter2" &
done

So that they would run in parallel. Is this possible?

share|improve this question

2 Answers 2

up vote 8 down vote accepted

It is possible, and I do it routinely. The limitation is the number of kernels your license allows you to run simultaneously. This I believe is reported by $MaxLicenseProcesses:

Mathematica graphics

Of course you need to be careful not to write to the same files etc!

share|improve this answer
    
Thanks a lot! That helps! –  preeti Aug 7 '12 at 20:31

It is indeed possible and I use this all the time. Instead of the for ... & done you might want to check out gnu parallel. It's great for running parallel processes from the command line.
parallel can be told how many processes to run in parallel, so you don't run out of licences or memory. Here is an example:

parallel -j4 "math -noprompt -script scriptname.m parameter1 parameter2" ::: $var

where -jN tells how many parallel processes to run at once.

Pro tip for windows users: If you install Git (for windows) you get a working native unix-like environment based on msys (including bash and perl). By copying the parallel script (written in perl) to GITINSTALLDIR\bin everything just works.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.