Hi Brian,

In our implementation, operations on associative domains are parallel safe by 
default. You can add and remove keys safely inside of parallel constructs.
You can toggle this safety when declaring the associative domain:
    var dom : domain(int, parSafe=false);

Associative arrays are not as safe, and one should take precautions when using 
them in parallel. For example, if one tasks reassigns a domain while another 
task is iterating over the array, you may very well encounter errors in your 
program.

With enough parallelism and a large enough problem size, I think your test 
would expose a similar issue where the underlying array inside the domain is 
reallocated. Once the underlying array is resized to store more indices, 
references to those elements (returned from the array access) are no longer 
valid.

Also, if you haven't found it already, the associative domain/array primer may 
be a useful resource (though not for the question of parallel safety):
https://github.com/chapel-lang/chapel/blob/release/1.11/test/release/examples/primers/associative.chpl

-Ben

From: Brian Guarraci <[email protected]<mailto:[email protected]>>
Date: Friday, April 24, 2015 at 9:43 AM
To: 
"[email protected]<mailto:[email protected]>"
 
<[email protected]<mailto:[email protected]>>
Subject: Re: [Chapel-developers] associative array questions

I found the answer to my first question in the reference (I missed this before):


20.3.2 Associative Array Indexing

For associative arrays such assignment will add the index to the array’s 
domain, and the array can be indexed with the newly added indices:

On Fri, Apr 24, 2015 at 8:01 AM, Brian Guarraci 
<[email protected]<mailto:[email protected]>> wrote:
Hi,

I have a few questions that don't seem covered in the docs:

1) The associative array example seems to imply that you need to first update 
the domain before you use the key as an accessor, however I've empirically 
found that you can do the assignment and the key gets added.  Is this expected 
behavior?

2) Regarding concurrency, it seems intuitively the case that operations on an 
associate domain and the array should be thread / task safe, but i'm curious if 
there are any precautions I should be taking.  I've empirically found that it 
seems to be safe, but wonder what the official guidance is.

Here's a little snippet I used to test some ideas:

use Random;

var Indices: domain(real);
var Entries: [Indices] real;

proc writeEntryForIndex(idx: real) {
  writeln("key: ", idx, " value: ", Entries[idx]);
}

proc dumpEntries() {
  writeln('dumping entries');
  for idx in Indices.sorted() {
    writeEntryForIndex(idx);
  }
  writeln();
}

// add w/o previously updating the domain
Entries[0] = 2.71828;
dumpEntries();

Entries[1] = 3.141592;
dumpEntries();

// add a bunch of keys in parallel
coforall i in 1..here.maxTaskPar {
  var randStream: RandomStream = new RandomStream();
  for j in 1..10 {
    var key = randStream.getNext();
    var value = randStream.getNext();
    writeln("task #", j, " adding key: ", key, " value: ", value);
    Entries[key] = value;
  }
}

dumpEntries();


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to