cl.egans.Array vs. ConstantArray

2 views
Skip to first unread message

Rick Gerkin

unread,
Aug 24, 2010, 11:59:09 PM8/24/10
to ahh-d...@googlegroups.com
class ahh.cl.egans.ConstantArray(parent, basename, *args, **kwargs)
Represents a constant array over all realizations.

class ahh.cl.egans.Array(parent, basename, *args, **kwargs)
Represents a variable array over all realizations.

Does this mean the same block of memory (for an array) is used by all the realizations?  If yes, wouldn't a variable array be corrupted by the parallel execution of realizations?  If no, then what about constants that should be the same for all realizations; wouldn't allocating it multiple times be wasteful?  

Rick  


M.Rule

unread,
Aug 25, 2010, 10:33:36 AM8/25/10
to ahh-d...@googlegroups.com
do check with Cyrus, but the behavior of constant / variable arrays
should be what you expect :
-- a constant array is immutable, shared across realizations
-- a variable array is mutable, and has separate memory across realizations
any departure from the above, I think, would be counterintuitive behavior.

> --
> You received this message because you are subscribed to the Google Groups
> "ahh-discuss" group.
> To post to this group, send email to ahh-d...@googlegroups.com.
> To unsubscribe from this group, send email to
> ahh-discuss...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/ahh-discuss?hl=en.
>

M.Rule

unread,
Aug 25, 2010, 10:53:43 AM8/25/10
to ahh-d...@googlegroups.com
although an alternate valid interpretation might be that a separate
constant array is allocated for each realization. I could imagine some
circumstance where you would want constant arrays that differ across
realizations, for instance, randomly seeding the parameters of a
network of Izh neurons. The constant modifier should in theory permit
more compiler optimizations and might permit more efficient memory
caching.

Cyrus Omar

unread,
Aug 25, 2010, 11:19:24 AM8/25/10
to ahh-d...@googlegroups.com
The purpose of Array and ConstantArray (at least from the script's perspective) are to pass auxiliary data to the GPU, so you do something like

Array(sim, "frozen_noise", frozen_noise)

That means that a single, but mutable, copy of the numpy array frozen_noise is copied in for the simulation. ConstantArray is the same thing but the data is constant.

So no, you don't get a copy per realization in either case. If you want a copy per realization, you have to do it manually now. If you find a good reason to do this and want to encapsulate it in a little node, feel free to do that and I'll put it in.

I'll clarify the documentation a bit.

Cyrus

Rick Gerkin

unread,
Aug 29, 2010, 9:41:39 PM8/29/10
to ahh-d...@googlegroups.com
If all realizations works with the same numpy array copy in parallel, how would it ever be good for one of them to change values in that array?  Then the realizations are not independent.  

Rick  


On Wed, Aug 25, 2010 at 11:19 AM, Cyrus Omar <cyrus...@gmail.com> wrote:
The purpose of Array and ConstantArray (at least from the script's perspective) are to pass auxiliary data to the GPU, so you do something like

Array(sim, "frozen_noise", frozen_noise)

That means that a single, but mutable, copy of the numpy array frozen_noise is copied in for the simulation. ConstantArray is the same thing but the data is constant.

So no, you don't get a copy per realization in either case. If you want a copy per realization, you have to do it manually now. If you find a good reason to do this and want to encapsulate it in a little node, feel free to do that and I'll put it in.

I'll clarify the documentation a bit.

Cyrus

 
--
Richard C. Gerkin
Postdoctoral Fellow, Dept. of Biological Sciences
Carnegie Mellon University

M.Rule

unread,
Aug 29, 2010, 9:46:04 PM8/29/10
to ahh-d...@googlegroups.com
you manually enforce a lack of collisions in your code.

M.Rule

unread,
Aug 29, 2010, 9:47:00 PM8/29/10
to ahh-d...@googlegroups.com
and by that I mean, if you have 10 divisions, allocate 10 times
whatever you thought you needed, and ensure that each division writes
only to *its* portion of the array.

its not really safe.. but remember this is all in C, theres hardly any
built in memory protection.

Cyrus Omar

unread,
Aug 31, 2010, 2:18:53 PM8/31/10
to ahh-d...@googlegroups.com
Yes what Mike said. If you want to have a version of Array that creates a duplicate per realization I can do that too, shouldn't be too hard.

Cyrus
Reply all
Reply to author
Forward
0 new messages