Brian Dolan
Brian Dolan

Reputation: 3136

How do I set an array size using an atomic variable in Chapel?

In pursuing A3C I need to set multiple global and local parameters. The global parameters need to have shared size. I think this means atomic variables, but it's still new to me.

var n: atomic int,
    x: [1..n] real;  # a vector of global size

proc localDude(){
  n +=1;  # increase the size of n
}

I understand the array will grow and shrink with the domain, but I'm having a hard time getting the semantics together. Thanks!

Upvotes: 2

Views: 182

Answers (1)

memorableusername
memorableusername

Reputation: 502

So there are a few things.

  1. Domains take their bounds by value, not by reference. Thus, modifying a variable used by a domain to construct its bounds does not modify the domain (example).
  2. Arrays do take their domain by reference, and so assigning to the used domain variable does make the array change (example).
  3. Domains are not a supported Atomic type yet, so having a global atomic domain will not work. However you could use a sync variable as a lock so that modifications are serialized. There is an example of this on the learn Chapel in Y minutes tutorial, near the bottom (search for mutex)

Upvotes: 3

Related Questions