Hi Konstantina --

I've attached the draft helper module that our intern did last summer. For an array A, the current interface supports:

        proc A.subIsSingle(): bool -- returns whether or not the subdomain
          owned by the current locale can be described as a single
          subdomain or not

        proc A.mySubdomain(): domain -- returns the subdomain owned by
          the current locale if it's a singleton

        iter A.multisubdomains(): domain -- yields the subdomains owned
          by the locale (works whether there's just one or multiple)

So, for example, the following code snippet should print out the ownership
information for an array A:

        use DistPlus;

        for loc in Locales do
          on loc {
            write("Locale ", here.id, " owns: ");
            if A.subIsSingle() {
              writeln(A.mySubdomain());
            } else {
              for subdom in A.multisubdomains() {
                write(subdom, " ");
              }
              writeln();
            }
          }

This hasn't received much testing yet, so let us know if you come across any errors. As mentioned previously, this is on the TODO list for the upcoming release, so if you have suggested changes to the interface or naming, that would be good input as well. (Personally, I'm trying to remember if there's any reason that the interface wasn't defined on domains as well as arrays (or instead of)).

Thanks,
-Brad






On Fri, 7 Mar 2014, Konstantina Panagiotopoulou wrote:

Yeah, that did the trick!!
Please let me know if you ve found the extra code.

Thanks a lot Brad!

-Konstantina




2014-03-06 21:24 GMT+00:00 Brad Chamberlain <[email protected]>:


 So, for a test program like this

use BlockDist;
config var n = 5;

const ProblemSpace = {1..n, 1..n},
BlockSpace = ProblemSpace dmapped Block(boundingBox=ProblemSpace);

coforall loc in Locales do
on loc{
 var myInds = BlockSpace._value.locDoms[here.id].myBlock;

writeln("locale: ", here.id, " myInds: ", myInds);
}

compiler says:
myInds.chpl:13: error: unresolved access of '[domain(2,int(64),false)]
LocBlockDom(2,int(64),false)' by '[int(64)]'


Oh, right -- I see my oversight.  The issue is that the Block()
distribution reshapes the Locales array as a 2D array and the locDoms[]
array is over that 2D array, so you'd need to know the locale's position in
that 2D array.  The variation on this would be to do the following (which
should be truly nD, and which I actually compiled since I'm not running off
to lunch anymore):

coforall locid in BlockSpace.dist._value.targetLocDom do
  on BlockSpace.dist._value.targetLocales[locid] {
    var myInds = BlockSpace._value.locDoms[locid].myBlock;


    writeln("locale: ", here.id, " myInds: ", myInds);
  }

This essentially peeks under the covers in the distribution to ask how
it's storing the locales domain (targetLocDom) and array (targetLocales).
As with the previous approach, it should be considered a hacky workaround
until a more formal interface is in-place.


Speaking of which, let me see if I can dig up that work from the
internship...


-Brad



/* 
use this file to query for the subdomain the current locale owns.
Ex) const Space = {1..10};
   const SpaceMap = Space dmapped Block(Space);
   var A : [SpaceMap] int;
   
   for L in Locales do 
     on L do writeln(A.mySubdomain());
--------------------------------------------------
if there are 4 locales, the output will be:

  {1..5, 1..5}
  {1..5, 6..10}
  {6..10, 1..5}
  {6..10, 6..10}
--------------------------------------------------

Note that these features are a work in progress, and are subject 
to change.
*/ 

// currently supported distributions
use BlockDist, CyclicDist, BlockCycDist, ReplicatedDist;
 
// TODO: Replicated doesn't use  targetLocDom. Do we need to have each 
// distribution define its own proc?
proc _array.locGridDom() {
  return _value.dom.dist.targetLocDom;
}

proc _array.locGrid() {
  return _value.dom.dist.targetLocales;
}

// wrapper to hide _value from user
proc _array.subIsSingle() param {
  return _value.dsiSubIsSingle();
}

// allows the user to determine which function they should call
// if true, then the chunk owned by each Locale can be expressed 
//   by a single domain
// if false, then the chunk is expressed as multiple domains (See BlockCyclic)
proc BlockArr.dsiSubIsSingle() param return true;

proc CyclicArr.dsiSubIsSingle() param return true;

proc ReplicatedArr.dsiSubIsSingle() param  return true;

proc BlockCyclicArr.dsiSubIsSingle() param return false;

proc DefaultRectangularArr.dsiSubIsSingle() param return true;

proc DefaultSparseArr.dsiSubIsSingle() param return true;

proc DefaultAssociativeArr.dsiSubIsSingle() param return true;

// wrapper to hide _value from the user
proc _array.mySubdomain(loc : locale = here) {
  if !_value.dsiSubIsSingle() then
    compilerError("Array's local domain is not a single domain");
  return _value.dsiMySubdomain(loc);
}

proc DefaultRectangularArr.dsiMySubdomain(loc : locale) {
  return dom.ranges;
}

proc DefaultSparseArr.dsiMySubdomain(loc : locale) {
  return dom.nnzDom;
}

// cover's Opaque too
proc DefaultAssociativeArr.dsiMySubdomain(loc : locale) {
  return dom.tableDom;
}

// Block and Cyclic are easiest, simply return the single domain
proc BlockArr.dsiMySubdomain(loc : locale) {
  return myLocArr.locDom.myBlock;
}

proc CyclicArr.dsiMySubdomain(loc : locale) {
  return myLocArr.locDom.myBlock;
}

// Replicated ony uses one domain, but there are local copies we should return
proc ReplicatedArr.dsiMySubdomain(loc : locale) {
  return localArrs[here.id].myDom.domLocalRep;
}

iter _array.multiSubdomains(loc : locale = here) {
  if _value.dsiSubIsSingle() then 
    yield _value.dsiMySubdomain(loc);
  else 
    for d in _value.multiSubdomains(loc) do yield d;
}

// essentially enumerateBlocks()
// basically add blocksize to the start indices
iter BlockCyclicArr.multiSubdomains(loc : locale) {
  for i in myLocArr.indexDom.myStarts {
    var temp : rank*range;
    for param j in 1..rank {
      var lo: idxType;
      if rank == 1 then lo = i;
      else lo = i(j);
      temp(j) = lo .. min(lo + myLocArr.indexDom.globDom.dist.blocksize(j)-1, 
myLocArr.indexDom.globDom.whole.dim(j).high);
    }
    const r : domain(rank, idxType, stridable) = temp;
    yield r; // yield a domain so the user can use procs like 
expand/exterior/etc.
  }
}
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works. 
Faster operations. Version large binaries.  Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to