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]> 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