Also - task-private variables are discussed in some detail in our most recent 
release notes:

https://chapel-lang.org/releaseNotes/1.18/01-language.pdf

Vass

-----Original Message-----
From: Vassily Litvinov <[email protected]>
Date: Thursday, October 25, 2018 at 3:06 PM
To: "David G. Wonnacott" <[email protected]>
Cc: Chapel Users Mailing List <[email protected]>
Subject: Re: thread-private variables and arrays?

Hello David,

Another option is to make v a "task-private variable" in your prospective 
"forall I" loop:

forall I in 0..n-1 with (var v = makeV()) {
  initialize v;
  do stuff;
  read v;
}

proc makeV() { var w:[0..m-1] real(64); return w; }

This will call one makeV() per task created by the forall loop.

P.S. Ideally you would do without makeV(), instead writing simply "with (var 
v:[0..m-1] real(64))". Alas this is not implemented at the moment. We are 
planning to make this available in the future.

P.P.S. This probably qualifies as a good StackOverflow question.

Vass

-----Original Message-----
From: "David G. Wonnacott" <[email protected]>
Date: Thursday, October 25, 2018 at 2:11 PM
To: Chapel Users Mailing List <[email protected]>
Subject: thread-private variables and arrays?

I apologize if this is in the documentation somewhere and I've missed it. 
Searches involving the words "chapel" and "private" are turning up a lot of 
non-programming related web pages :-(


I'm working on parallelizing a code that includes a two-dimensional loop nest 
(call it "i" and "j"), in which each iteration of the i loop defines all 
elements of a vector v and then later uses that vector, e.g. something like 
this (may contain typos,
 I just entered this in my email to give the idea):



   var v:[0..m-1] real(64);


   for i in 0 .. n-1 {
      for j in 0 .. m-1 {
         ...
         v[j] = ...
      }


      ..  // lots of other computation


      for j in 0 .. m-1 {
        ... use of v[j]
      }
    }




v is not used anywhere else. I'd like to make the i loop into a "forall", but 
of course then there will be races on v.


I'm guessing that I could just put the declaration of v iside the i loop, to 
get a separate vector for each thread? However, I'm doing some kind of strange 
things with iterators and classes, trying to abstract away some aspects of how 
things are stored,
 so it might be nicer to leave the definition of v outside of the loop nest 
(though, with just the code above, I agree that doing so not only is ugly but 
raises semantic issues about the value of v after the end of the i loop). I 
could also have an array than
 I index by "i", thus "expanding" rather than "privatizing" v.


At the moment, we're exploring a lot of options, so my question is whether 
there are any other options beyond these two (#1 = put v inside the i loop, #2 
= subscript by i as well as v). Possibly locale's would be interesting? That's 
on my "to learn" list,
 so maybe it's time.


Dave W






_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to