Re: how to write ParallelSubmit in a Do loop? trying to use up all CPU

• To: undisclosed-recipients:;
• Subject: [mg131455] Re: how to write ParallelSubmit in a Do loop? trying to use up all CPU
• From: Sseziwa Mukasa <mukasa at gmail.com>
• Date: Tue, 9 Jul 2013 06:50:09 -0400 (EDT)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• Delivered-to: l-mathgroup@wolfram.com
• Delivered-to: mathgroup-outx@smc.vnet.net
• Delivered-to: mathgroup-newsendx@smc.vnet.net
• References: <20130708032047.1772769BF@smc.vnet.net>

```First of all, Do always returns Null, but the assignment still happened, evaluate job[0] to check.

However for your computation to work you need to distribute the definition of step and enclose the local value of i in ParallelSubmit:

t = AbsoluteTime[];
initial = 1
final = 20000000
step = (final - initial + 1)/8
Clear["job"]
Clear["i"]

DistributeDefinitions[step]
Do[job[i]=ParallelSubmit[{i},Table[Prime[k], {k, step*i + 1, step*(i + 1)}]]
, {i, 0, 7}]

Clear["a"]
Table[a[jj], {jj, 1, 8}] = WaitAll[Table[job[j], {j, 0, 7}]]

time2 = AbsoluteTime[] - t

Regards,
Sseziwa

On Jul 7, 2013, at 11:20 PM, alex <0899607 at gmail.com> wrote:

> when it comes a heavily calculation, it takes time, but not fully cpu usage
> i found a scrip using ParallelSubmit, which is quite powerful and really shorten the time in calculating
>
> =
http://mathematica.stackexchange.com/questions/10969/parallelization-problem-in-linearsolve-and-minimize
>
>
> t = AbsoluteTime[];
> job1 = ParallelSubmit[Table[Prime[k], {k, 1, 2500000}]];
> job2 = ParallelSubmit[Table[Prime[k], {k, 2500001, 5000000}]];
> job3 = ParallelSubmit[Table[Prime[k], {k, 5000001, 7500000}]];
> job4 = ParallelSubmit[Table[Prime[k], {k, 7500001, 10000000}]];
> job5 = ParallelSubmit[Table[Prime[k], {k, 10000001, 12500000}]];
> job6 = ParallelSubmit[Table[Prime[k], {k, 12500001, 15000000}]];
> job7 = ParallelSubmit[Table[Prime[k], {k, 15000001, 17500000}]];
> job8 = ParallelSubmit[Table[Prime[k], {k, 17500001, 20000000}]];
> {a1, a2, a3, a4, a5, a6, a7, a8} =
> WaitAll[{job1, job2, job3, job4, job5, job6, job7, job8}];
> time2 = AbsoluteTime[] - t
>
> t = AbsoluteTime[];
>
>
>
>
>
> then i try to rewrite the script by using Do loop, so i can just setup the initial and final value then it can be separated into 8 parts automatically , but i failed.
>
>
> t = AbsoluteTime[];
> initial = 1
> final = 20000000
> step = (final - initial + 1)/8
> Clear["job"]
> Clear["i"]
>
> Do[job[i]=ParallelSubmit[Table[Prime[k], {k, step*i + 1, step*(i + 1)}]]
> , {i, 0, 7}]
>
> Clear["a"]
> Table[a[jj], {jj, 1, 8}] = WaitAll[Table[job[j], {j, 0, 7}]]
>
> time2 = AbsoluteTime[] - t
>
>
>
> it keeps showing Null, it seems that it cant replace the variable in Do loop exactly, it is still a variable.
>
> how do i rewrite the scrip? to make it be separated into 8 parts automatically?
> thank you for your help ^^
>

```

• Prev by Date: Omega tau podcasts on Wolfram|Alpha and Methematica
• Next by Date: Re: color surface according to absolut value of the gradient
• Previous by thread: how to write ParallelSubmit in a Do loop? trying to use up all CPU
• Next by thread: Unwanted parentheses appearing in a notebook that is opened by a