comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: CUDA version of RANDOMN?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Re: CUDA version of RANDOMN? [message #61998] Fri, 15 August 2008 17:58
hotplainrice@gmail.co is currently offline  hotplainrice@gmail.co
Messages: 15
Registered: July 2008
Junior Member
On Aug 16, 3:15 am, wlandsman <wlands...@gmail.com> wrote:
> On Aug 15, 11:28 am, wlandsman <wlands...@gmail.com> wrote:
>
>
>
>> On Aug 15, 11:16 am, "hotplainr...@gmail.com" <hotplainr...@gmail.com>
>> wrote:
>
>>> On Aug 16, 12:28 am, wlandsman <wlands...@gmail.com> wrote:
>
>>>> On Aug 15, 10:11 am, "hotplainr...@gmail.com" <hotplainr...@gmail.com>
>>>> wrote:
>
>>>> > Hey guys,
>
>>>> > I need to write a kernel to replace the IDL RANDOMN POISSON
>
>>>> > for loop
>>>> >   for loop
>>>> >      for loop
>>>> >                        c = data[x,y,b]
>>>> >                         if c gt 0.0 then begin
>>>> >                                 n = RANDOMN( seedP, POISSON=c )
>>>> >                         endif else begin
>>>> >                                 n = 0
>>>> >                         endelse
>>>> >                        data[x,y,b] = n
>>>> >     endfor
>>>> >   endfor
>>>> > endfor
>
>>>> > Could someone point out an example code of how RANDOMN POISSON so that
>>>> > I can implement it in CUDA?
>
>>>> Your best bet is to probably look at the Poisson generating algorithm
>>>> in "Numerical Recipes in C" if you are going to implement it CUDA.
>
>>>> I have implemented the "Numerical Recipes in C" algorithm into the IDL
>>>> procedure poidev.pro at http://idlastro.gsfc.nasa.gov/ftp/pro/math/poidev.pro.
>>>> Although poidev.pro is normally slower than calling randomn(POISSON=),
>>>> it has advantages for just the problem you describe, which can be
>>>> written as simply
>
>>>>           data = poidev(data)
>
>>>> rather than using a triple FOR loop.   --Wayne
>
>>> Thanks for the reply. I was about to use your code until I discovered
>>> the problem of achieving this.
>
>>>                         c = data[x,y,b]
>>>                         if c gt 0.0 then begin
>>>                                 n = RANDOMN( seedP, POISSON=c )
>>>                         endif else begin
>>>                                 n = 0
>>>                         endelse
>
>>> I guess the only way is to code a poisson kernel and then do tiling on
>>> the data.
>
>> Yes, that does mean the code becomes 3 lines instead of 1
>
>> g = where( data GT 0, Ng ,complement=g1, Ncomplement=Ng1)
>> if Ng GT 0 then data[g] = poidev(data[g])
>> if Ng1 GT 0 then data[g1] = 0
>
>> --Wayne
>
> I still made it too complicated.    poidev automatically sets any
> negative numbers to zero (since the Poisson distribution is not
> defined for negative numbers).    So the original code
>
> data  = poidev(data)
>
> should be fine.   --Wayne

Thanks Wayne, that function helped me decrease times by half and
provided me with some code if I want to implement it in GPUs.
Re: CUDA version of RANDOMN? [message #61999 is a reply to message #61998] Fri, 15 August 2008 10:15 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Aug 15, 11:28 am, wlandsman <wlands...@gmail.com> wrote:
> On Aug 15, 11:16 am, "hotplainr...@gmail.com" <hotplainr...@gmail.com>
> wrote:
>
>
>
>> On Aug 16, 12:28 am, wlandsman <wlands...@gmail.com> wrote:
>
>>> On Aug 15, 10:11 am, "hotplainr...@gmail.com" <hotplainr...@gmail.com>
>>> wrote:
>
>>>> Hey guys,
>
>>>> I need to write a kernel to replace the IDL RANDOMN POISSON
>
>>>> for loop
>>>>   for loop
>>>>      for loop
>>>>                        c = data[x,y,b]
>>>>                         if c gt 0.0 then begin
>>>>                                 n = RANDOMN( seedP, POISSON=c )
>>>>                         endif else begin
>>>>                                 n = 0
>>>>                         endelse
>>>>                        data[x,y,b] = n
>>>>     endfor
>>>>   endfor
>>>> endfor
>
>>>> Could someone point out an example code of how RANDOMN POISSON so that
>>>> I can implement it in CUDA?
>
>>> Your best bet is to probably look at the Poisson generating algorithm
>>> in "Numerical Recipes in C" if you are going to implement it CUDA.
>
>>> I have implemented the "Numerical Recipes in C" algorithm into the IDL
>>> procedure poidev.pro at http://idlastro.gsfc.nasa.gov/ftp/pro/math/poidev.pro.
>>> Although poidev.pro is normally slower than calling randomn(POISSON=),
>>> it has advantages for just the problem you describe, which can be
>>> written as simply
>
>>>           data = poidev(data)
>
>>> rather than using a triple FOR loop.   --Wayne
>
>> Thanks for the reply. I was about to use your code until I discovered
>> the problem of achieving this.
>
>>                         c = data[x,y,b]
>>                         if c gt 0.0 then begin
>>                                 n = RANDOMN( seedP, POISSON=c )
>>                         endif else begin
>>                                 n = 0
>>                         endelse
>
>> I guess the only way is to code a poisson kernel and then do tiling on
>> the data.
>
> Yes, that does mean the code becomes 3 lines instead of 1
>
> g = where( data GT 0, Ng ,complement=g1, Ncomplement=Ng1)
> if Ng GT 0 then data[g] = poidev(data[g])
> if Ng1 GT 0 then data[g1] = 0
>
> --Wayne

I still made it too complicated. poidev automatically sets any
negative numbers to zero (since the Poisson distribution is not
defined for negative numbers). So the original code

data = poidev(data)

should be fine. --Wayne
Re: CUDA version of RANDOMN? [message #62002 is a reply to message #61999] Fri, 15 August 2008 08:28 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Aug 15, 11:16 am, "hotplainr...@gmail.com" <hotplainr...@gmail.com>
wrote:
> On Aug 16, 12:28 am, wlandsman <wlands...@gmail.com> wrote:
>
>
>
>> On Aug 15, 10:11 am, "hotplainr...@gmail.com" <hotplainr...@gmail.com>
>> wrote:
>
>>> Hey guys,
>
>>> I need to write a kernel to replace the IDL RANDOMN POISSON
>
>>> for loop
>>>   for loop
>>>      for loop
>>>                        c = data[x,y,b]
>>>                         if c gt 0.0 then begin
>>>                                 n = RANDOMN( seedP, POISSON=c )
>>>                         endif else begin
>>>                                 n = 0
>>>                         endelse
>>>                        data[x,y,b] = n
>>>     endfor
>>>   endfor
>>> endfor
>
>>> Could someone point out an example code of how RANDOMN POISSON so that
>>> I can implement it in CUDA?
>
>> Your best bet is to probably look at the Poisson generating algorithm
>> in "Numerical Recipes in C" if you are going to implement it CUDA.
>
>> I have implemented the "Numerical Recipes in C" algorithm into the IDL
>> procedure poidev.pro at http://idlastro.gsfc.nasa.gov/ftp/pro/math/poidev.pro.
>> Although poidev.pro is normally slower than calling randomn(POISSON=),
>> it has advantages for just the problem you describe, which can be
>> written as simply
>
>>           data = poidev(data)
>
>> rather than using a triple FOR loop.   --Wayne
>
> Thanks for the reply. I was about to use your code until I discovered
> the problem of achieving this.
>
>                         c = data[x,y,b]
>                         if c gt 0.0 then begin
>                                 n = RANDOMN( seedP, POISSON=c )
>                         endif else begin
>                                 n = 0
>                         endelse
>
> I guess the only way is to code a poisson kernel and then do tiling on
> the data.

Yes, that does mean the code becomes 3 lines instead of 1

g = where( data GT 0, Ng ,complement=g1, Ncomplement=Ng1)
if Ng GT 0 then data[g] = poidev(data[g])
if Ng1 GT 0 then data[g1] = 0

--Wayne
Re: CUDA version of RANDOMN? [message #62003 is a reply to message #62002] Fri, 15 August 2008 08:16 Go to previous message
hotplainrice@gmail.co is currently offline  hotplainrice@gmail.co
Messages: 15
Registered: July 2008
Junior Member
On Aug 16, 12:28 am, wlandsman <wlands...@gmail.com> wrote:
> On Aug 15, 10:11 am, "hotplainr...@gmail.com" <hotplainr...@gmail.com>
> wrote:
>
>
>
>> Hey guys,
>
>> I need to write a kernel to replace the IDL RANDOMN POISSON
>
>> for loop
>>   for loop
>>      for loop
>>                        c = data[x,y,b]
>>                         if c gt 0.0 then begin
>>                                 n = RANDOMN( seedP, POISSON=c )
>>                         endif else begin
>>                                 n = 0
>>                         endelse
>>                        data[x,y,b] = n
>>     endfor
>>   endfor
>> endfor
>
>> Could someone point out an example code of how RANDOMN POISSON so that
>> I can implement it in CUDA?
>
> Your best bet is to probably look at the Poisson generating algorithm
> in "Numerical Recipes in C" if you are going to implement it CUDA.
>
> I have implemented the "Numerical Recipes in C" algorithm into the IDL
> procedure poidev.pro at http://idlastro.gsfc.nasa.gov/ftp/pro/math/poidev.pro.
> Although poidev.pro is normally slower than calling randomn(POISSON=),
> it has advantages for just the problem you describe, which can be
> written as simply
>
>           data = poidev(data)
>
> rather than using a triple FOR loop.   --Wayne

Thanks for the reply. I was about to use your code until I discovered
the problem of achieving this.

c = data[x,y,b]
if c gt 0.0 then begin
n = RANDOMN( seedP, POISSON=c )
endif else begin
n = 0
endelse

I guess the only way is to code a poisson kernel and then do tiling on
the data.
Re: CUDA version of RANDOMN? [message #62004 is a reply to message #62003] Fri, 15 August 2008 08:14 Go to previous message
hotplainrice@gmail.co is currently offline  hotplainrice@gmail.co
Messages: 15
Registered: July 2008
Junior Member
On Aug 16, 12:28 am, wlandsman <wlands...@gmail.com> wrote:
> On Aug 15, 10:11 am, "hotplainr...@gmail.com" <hotplainr...@gmail.com>
> wrote:
>
>
>
>> Hey guys,
>
>> I need to write a kernel to replace the IDL RANDOMN POISSON
>
>> for loop
>>   for loop
>>      for loop
>>                        c = data[x,y,b]
>>                         if c gt 0.0 then begin
>>                                 n = RANDOMN( seedP, POISSON=c )
>>                         endif else begin
>>                                 n = 0
>>                         endelse
>>                        data[x,y,b] = n
>>     endfor
>>   endfor
>> endfor
>
>> Could someone point out an example code of how RANDOMN POISSON so that
>> I can implement it in CUDA?
>
> Your best bet is to probably look at the Poisson generating algorithm
> in "Numerical Recipes in C" if you are going to implement it CUDA.
>
> I have implemented the "Numerical Recipes in C" algorithm into the IDL
> procedure poidev.pro at http://idlastro.gsfc.nasa.gov/ftp/pro/math/poidev.pro.
> Although poidev.pro is normally slower than calling randomn(POISSON=),
> it has advantages for just the problem you describe, which can be
> written as simply
>
>           data = poidev(data)
>
> rather than using a triple FOR loop.   --Wayne
Re: CUDA version of RANDOMN? [message #62005 is a reply to message #62004] Fri, 15 August 2008 07:28 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
On Aug 15, 10:11 am, "hotplainr...@gmail.com" <hotplainr...@gmail.com>
wrote:
> Hey guys,
>
> I need to write a kernel to replace the IDL RANDOMN POISSON
>
> for loop
>   for loop
>      for loop
>                        c = data[x,y,b]
>                         if c gt 0.0 then begin
>                                 n = RANDOMN( seedP, POISSON=c )
>                         endif else begin
>                                 n = 0
>                         endelse
>                        data[x,y,b] = n
>     endfor
>   endfor
> endfor
>
> Could someone point out an example code of how RANDOMN POISSON so that
> I can implement it in CUDA?

Your best bet is to probably look at the Poisson generating algorithm
in "Numerical Recipes in C" if you are going to implement it CUDA.

I have implemented the "Numerical Recipes in C" algorithm into the IDL
procedure poidev.pro at http://idlastro.gsfc.nasa.gov/ftp/pro/math/poidev.pro.
Although poidev.pro is normally slower than calling randomn(POISSON=),
it has advantages for just the problem you describe, which can be
written as simply

data = poidev(data)

rather than using a triple FOR loop. --Wayne
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Re: Need help with an Iterative solution in IDL (relative newb question)
Next Topic: Re: A very simple question about map_grid

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 13:39:03 PDT 2025

Total time taken to generate the page: 0.00660 seconds