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.

How can I execute more than one input cell simultaneously using different processor. For example consider this two cells

Grid[ParallelTable[ContourPlot[Sin[m x] Sin[n y] - Cos[n x] Cos[m y],
{x, 0, 2 Pi}, {y, 0, 2 Pi},MaxRecursion -> 5], {m, 2}, {n, 2}]]//TimeUsed
T1end=DateString[]

and

T2begin=DateString[]
Grid[ParallelTable[ContourPlot[Sin[m x] Cos[n y] - Cos[m x] Sin[n y],
{x, 0, 2 Pi}, {y, 0, 2 Pi},MaxRecursion -> 5], {m, 2}, {n, 2}]]//TimeUsed

I hit the shift+enter for the second cell after 3 second of the first one but the execution starts after finishing the first cell and I always get T2begin=T1end.

where; T2begin = Starting time of second job (given by DateString[]) and T1end = Finishing time of first job.

What I want is to use half of the processors for the first job and use the aother half for the second job simultaneously (starting from the moment I hit the shift+enter) which will give T2begin < T1end, i.e. the second job will start before the completion of first job.

(I am working with 8 processors.)

share|improve this question
    
Why do you use TimeUsed rather than AbsoluteTiming? –  Yves Klett Nov 8 '13 at 12:43
    
@YvesKlett: TimeUsed[] is not anything important here. Only thing I want to assure that the second job starts before the first job ends and you get T2begin-T1end < 0. –  Sumit Nov 8 '13 at 13:21
    
Are the jobs different? In your example they could simply be tied into one ParallelTable. –  Yves Klett Nov 8 '13 at 13:36
    
@YvesKlett : sorry for not clarifying that. Yes, they are two different jobs with completely different structure and cant' be executed simultaneously. I have to run them one after another and while doing so the second one always starts after finishing the first one. –  Sumit Nov 9 '13 at 9:39

2 Answers 2

One way (other than using one ParallelTable) to do this with ParallelSubmit`:

Pause[1]; Pause[1]; // AbsoluteTiming

(* {2.000000, Null}*)

ParallelSubmit[Pause[1]]; ParallelSubmit[Pause[1]];
WaitAll[%] // AbsoluteTiming

(* {1.006000, Null}*)

share|improve this answer
    
thanks @YvesKlett. but I need a little more than that. Each of the jobs have several parallel jobs. So I want to allot 4 processor for the first job and then go for the second job and use another 4 processor to execute them. I have to submit them one after another, executing two different cell and I want them to run together. –  Sumit Nov 8 '13 at 13:29
    
Could ParallelSubmit be called "retroactively", i.e. execute one cell first, and then another inside ParallelSubmit? –  shrx Dec 8 '13 at 16:12
    
@shrx I do not quite get your meaning... –  Yves Klett Dec 10 '13 at 8:45
    
@YvesKlett Like this: Pause[1]; ParallelSubmit[Pause[1]]; and it should take 1 second to complete. –  shrx Dec 10 '13 at 20:38

I think in this case it is better to run two copies of the program. The first is to do the calculations for the first problem, the second - on the second. Communication is possible through export and import files. The number of processes for parallel computing have to adjust manually.

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.