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


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

  • $\begingroup$ Why do you use TimeUsed rather than AbsoluteTiming? $\endgroup$ – Yves Klett Nov 8 '13 at 12:43
  • $\begingroup$ @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. $\endgroup$ – Sumit Nov 8 '13 at 13:21
  • $\begingroup$ Are the jobs different? In your example they could simply be tied into one ParallelTable. $\endgroup$ – Yves Klett Nov 8 '13 at 13:36
  • $\begingroup$ @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. $\endgroup$ – Sumit Nov 9 '13 at 9:39

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

  • $\begingroup$ 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. $\endgroup$ – Sumit Nov 8 '13 at 13:29
  • $\begingroup$ Could ParallelSubmit be called "retroactively", i.e. execute one cell first, and then another inside ParallelSubmit? $\endgroup$ – shrx Dec 8 '13 at 16:12
  • $\begingroup$ @shrx I do not quite get your meaning... $\endgroup$ – Yves Klett Dec 10 '13 at 8:45
  • $\begingroup$ @YvesKlett Like this: Pause[1]; ParallelSubmit[Pause[1]]; and it should take 1 second to complete. $\endgroup$ – 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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