Splitting large for loop over multiple processors [message #92830] |
Wed, 09 March 2016 02:40  |
joellama
Messages: 8 Registered: July 2013
|
Junior Member |
|
|
Hi all,
I know, I know before I get lots of hate that I shouldn't have a for loop in my code...this isn't my code, it's code someone else wrote and I just haven't got the time go through and vectorise it.
Basically I have an output array that is say
out = fltarr(nx, ny, nz) where nx=ny=nz=100 each
The way the code is currently written it has
for i = 0, nx-1 do begin
for j = 0, ny-1 do begin
for k = 0, nz-1 do begin
.... a lot of calculations
endfor
endfor
endfor
Basically, all I want to do is split this over all the cores on my mac pro so that it does say
0 - nx/6 on cpu 1
nx/6 - 2*nx/6 on cpu 2 etc...
I saw this article http://www.exelisvis.com/Company/PressRoom/Blogs/TabId/836/A rtMID/2928/ArticleID/14744/Using-IDL-IDLBridge-to-run-multip le-processes-in-parallel.aspx
but the example isn't exactly easy to follow.
If anyone has any tips I would really appreciate it.
|
|
|
Re: Splitting large for loop over multiple processors [message #92861 is a reply to message #92830] |
Tue, 15 March 2016 08:30  |
Jeremy Bailin
Messages: 618 Registered: April 2008
|
Senior Member |
|
|
On Wednesday, March 9, 2016 at 5:40:50 AM UTC-5, Joe Llama wrote:
> Hi all,
>
> I know, I know before I get lots of hate that I shouldn't have a for loop in my code...this isn't my code, it's code someone else wrote and I just haven't got the time go through and vectorise it.
>
> Basically I have an output array that is say
>
> out = fltarr(nx, ny, nz) where nx=ny=nz=100 each
>
> The way the code is currently written it has
>
> for i = 0, nx-1 do begin
> for j = 0, ny-1 do begin
> for k = 0, nz-1 do begin
> .... a lot of calculations
> endfor
> endfor
> endfor
>
> Basically, all I want to do is split this over all the cores on my mac pro so that it does say
>
> 0 - nx/6 on cpu 1
> nx/6 - 2*nx/6 on cpu 2 etc...
>
> I saw this article http://www.exelisvis.com/Company/PressRoom/Blogs/TabId/836/A rtMID/2928/ArticleID/14744/Using-IDL-IDLBridge-to-run-multip le-processes-in-parallel.aspx
>
> but the example isn't exactly easy to follow.
>
> If anyone has any tips I would really appreciate it.
I'd suggest Michael Galloy's library:
http://michaelgalloy.com/2015/05/26/a-simple-multicore-libra ry-for-idl.html
-Jeremy.
|
|
|