Use the hypercube tree rather than the binary tree.

/*
 * Copyright 2015 Cray Inc.
 * Other additional copyright holders may be indicated within.
 *
 * The entirety of this work is licensed under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 *
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*

   Support for the visualization tool "chplvis"

   This module provides access to and enables hooks to dump out
   task and communication information for post-run visualization
   of the tasks and communication.

*/
module VisualDebug
{

  use String;

  pragma "no doc"
  extern proc chpl_now_time():real;

  //
  // Data Generation for the Visual Debug tool  (offline)
  //

  pragma "no doc"
  extern proc chpl_vdebug_start ( rootname: c_string, time:real);

  pragma "no doc"
  extern proc chpl_vdebug_stop ();

  pragma "no doc"
  extern proc chpl_vdebug_tag ( tagname: c_string);

  pragma "no doc"
  extern proc chpl_vdebug_pause ();

  pragma "no doc"
  extern proc chpl_vdebug_nolog ();

/* Tree "coforall procedure .... calls one of the above rotunes */

pragma "no doc"
  enum vis_op {v_start, v_stop, v_tag, v_pause};

pragma "no doc"
iter hc_id2com ( id: int, off: int ) {
   var offset = off;
   var ix = 1;
   while (offset > 0) {
      yield (id+offset, ix);
      offset = offset >> 1;
      ix = ix + 1;
   }
}

pragma "no doc"
proc VDebugTree (what: vis_op, name: string, time: real, id: int = 0,
                   n: int = numLocales, off: int = -1) {
      var offset = 1;
      if off < 0 then
         while offset >> 1 + id < n do offset = offset << 1;
      else
         offset = off;

      chpl_vdebug_nolog();
      coforall (rid, shift) in hc_id2com(id, offset) do
         if rid < n then
             on Locales[rid] do VDebugTree (what, name, time, rid, n, offset >> shift);

     /* Do the op at the root  */
     select what {
         when vis_op.v_start    do chpl_vdebug_start (name.c_str(), time);
         when vis_op.v_stop     do chpl_vdebug_stop ();
         when vis_op.v_tag      do chpl_vdebug_tag (name.c_str());
         when vis_op.v_pause    do chpl_vdebug_pause ();
     }
}

/*
  Start logging events for VisualDebug.  Open a new set of data
  files, one for each locale, for chplvis.  This routine should be
  called only once for each program.  It creates a directory with the
  rootname and creates the files in that directory.  The files are
  named with the rootname and "-n" is added where n is the locale
  number.

  :arg rootname:  Directory name and rootname for files.
*/
  proc startVdebug ( rootname : string ) {
    var now = chpl_now_time();
    //coforall l in Locales do
    //  on l do chpl_vdebug_start (rootname.c_str(), now);
    VDebugTree (vis_op.v_start, rootname, now);
  }

/*
  Add a tag to the data for chplvis to allow "view points" in the data.

  :arg tagname: name of the tag
*/
  proc tagVdebug ( tagname : string ) {
    //coforall l in Locales[1..] do
    //  on l do chpl_vdebug_tag (tagname.c_str(), 0);
    //chpl_vdebug_tag (tagname.c_str(), 0);
    VDebugTree (vis_op.v_tag, tagname, 0);
  }

/*
  Stop collecting VisualDebug data and close the data files.
*/
  proc stopVdebug () {
    // chpl_vdebug_stop();
    // coforall l in Locales[1..] do
    //  on l do chpl_vdebug_stop();
    VDebugTree (vis_op.v_stop, "", 0);
  }

/*
  Suspend collection of VisualDebug data.
*/
  proc pauseVdebug () {
    //coforall l in Locales[1..] do
    //  on l do chpl_vdebug_tag (tagname.c_str(), 1);
    //chpl_vdebug_tag(tagname.c_str(), 1);
    VDebugTree (vis_op.v_pause, "", 0);
  }

/*
  Resume collection of VisualDebug data for chplvis after a pauseVdebug().
  This also generates a tag record visible by chplvis.

  :arg tagname: name of the tag
*/
  proc resumeVdebug ( tagname : string ) {
    //coforall l in Locales[1..] do
    //  on l do chpl_vdebug_resume ();
    //chpl_vdebug_resume(tagname);
    VDebugTree (vis_op.v_tag, tagname, 0);
  }

}

/*
 * Copyright 2015 Cray Inc.
 * Other additional copyright holders may be indicated within.
 *
 * The entirety of this work is licensed under the Apache License,
 * Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License.
 *
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*

   Support for the visualization tool "chplvis"

   This module provides access to and enables hooks to dump out
   task and communication information for post-run visualization
   of the tasks and communication.

*/
module VisualDebug
{

  use String;

  pragma "no doc"
  extern proc chpl_now_time():real;

  //
  // Data Generation for the Visual Debug tool  (offline)
  //

  pragma "no doc"
  extern proc chpl_vdebug_start ( rootname: c_string, time:real);

  pragma "no doc"
  extern proc chpl_vdebug_stop ();

  pragma "no doc"
  extern proc chpl_vdebug_tag ( tagname: c_string);

  pragma "no doc"
  extern proc chpl_vdebug_pause ();

  pragma "no doc"
  extern proc chpl_vdebug_nolog ();

/* Tree "coforall procedure .... calls one of the above rotunes */

pragma "no doc"
  enum vis_op {v_start, v_stop, v_tag, v_pause};

pragma "no doc"
  proc VDebugTree (what: vis_op, name: string, time: real, id: int = 0) {
      var child = id * 2 + 1;
      chpl_vdebug_nolog();
      cobegin {
         /* left */
         if child < numLocales then
             on Locales[child] do VDebugTree (what, name, time, child);
         /* right */
         if child+1 < numLocales then
             on Locales[child+1] do VDebugTree (what, name, time, child+1);
     }
         /* Do the op at the root  */
         select what {
            when vis_op.v_start    do chpl_vdebug_start (name.c_str(), time);
            when vis_op.v_stop     do chpl_vdebug_stop ();
            when vis_op.v_tag      do chpl_vdebug_tag (name.c_str());
            when vis_op.v_pause    do chpl_vdebug_pause ();
         }
  }

/*
  Start logging events for VisualDebug.  Open a new set of data
  files, one for each locale, for chplvis.  This routine should be
  called only once for each program.  It creates a directory with the
  rootname and creates the files in that directory.  The files are
  named with the rootname and "-n" is added where n is the locale
  number.

  :arg rootname:  Directory name and rootname for files.
*/
  proc startVdebug ( rootname : string ) {
    var now = chpl_now_time();
    //coforall l in Locales do
    //  on l do chpl_vdebug_start (rootname.c_str(), now);
    VDebugTree (vis_op.v_start, rootname, now);
  }

/*
  Add a tag to the data for chplvis to allow "view points" in the data.

  :arg tagname: name of the tag
*/
  proc tagVdebug ( tagname : string ) {
    //coforall l in Locales[1..] do
    //  on l do chpl_vdebug_tag (tagname.c_str(), 0);
    //chpl_vdebug_tag (tagname.c_str(), 0);
    VDebugTree (vis_op.v_tag, tagname, 0);
  }

/*
  Stop collecting VisualDebug data and close the data files.
*/
  proc stopVdebug () {
    // chpl_vdebug_stop();
    // coforall l in Locales[1..] do
    //  on l do chpl_vdebug_stop();
    VDebugTree (vis_op.v_stop, "", 0);
  }

/*
  Suspend collection of VisualDebug data.
*/
  proc pauseVdebug () {
    //coforall l in Locales[1..] do
    //  on l do chpl_vdebug_tag (tagname.c_str(), 1);
    //chpl_vdebug_tag(tagname.c_str(), 1);
    VDebugTree (vis_op.v_pause, "", 0);
  }

/*
  Resume collection of VisualDebug data for chplvis after a pauseVdebug().
  This also generates a tag record visible by chplvis.

  :arg tagname: name of the tag
*/
  proc resumeVdebug ( tagname : string ) {
    //coforall l in Locales[1..] do
    //  on l do chpl_vdebug_resume ();
    //chpl_vdebug_resume(tagname);
    VDebugTree (vis_op.v_tag, tagname, 0);
  }

}


Change the size in each dimension in the block2D example from var to const

git-svn-id: 88467cb1fb04b8a755be7e1ee1026be4190196ef@15448 3a8e244f-b0f2-452b-bcba-4c88e055c3ca

/*
 * Block Distribution Example
 *
 * This example demonstrates a simple use of the Block distribution to
 * distribute a 2D array of integers across multiple locales.  Try it
 * with 4 locales by running it with the command-line argument -nl 4.
 * Note that you will need to set CHPL_COMM to gasnet.  Then try it
 * varying the numbers of locales and by changing the problem size
 * (--n=16).
 *
 * WARNING: Support for distributions is very much a work-in-progress
 * and many features that work with non-distributed arrays and domains
 * will not work with distributed arrays and domains.  Think of this
 * example as a preview.
 *
 */

//
// Standard module MultiBlockDist defines the Block distribution.
//
use MultiBlockDist;

//
// Size of each dimension of our domain.  Note that int(64) is the
// default for domains and arrays distributed with the Block
// distribution.
//
config const n: int(64) = 8;

//
// Declare and initialize an instance of the Block distribution Dist,
// a distributed domain Dom, and a distributed array A.  By default,
// the Block distribution distributes the domain across all locales.
//
var Dist = new Block(rank=2, bbox=[1..n, 1..n]);
var Dom: domain(2,int(64)) distributed Dist = [1..n, 1..n];
var A: [Dom] int;

//
// Output the domain and array.  They print just like non-distributed
// domains and arrays.
//
writeln("Domain");
writeln(Dom);
writeln();

writeln("Array");
writeln(A);
writeln();

//
// Output the locale ID numbers for each array element, determining
// this information by applying ".locale" to each array element.
//
writeln("Distribution Map");
for i in 1..n {
  for j in 1..n {
    write(A(i,j).locale.id, " ");
  }
  writeln();
}
writeln();

//
// Loop over the array using a serial for-loop and assign each element
// and increasing number.
//
var j = 1;
for a in A {
  a = j;
  j += 1;
}
writeln("Initialized array");
writeln(A);
writeln();

//
// In parallel, subtract one from each element of the array.
//
forall i in Dom do {
  A(i) = A(i) - 1;
}
writeln("Subtracted 1 via parallel iteration over the domain");
writeln(A);
writeln();

//
// In parallel, iterate over the array and set each element to 0.
//
forall a in A do {
  a = 0;
}
writeln("Zeroed via parallel iteration over the array");
writeln(A);

/*
 * Block Distribution Example
 *
 * This example demonstrates a simple use of the Block distribution to
 * distribute a 2D array of integers across multiple locales.  Try it
 * with 4 locales by running it with the command-line argument -nl 4.
 * Note that you will need to set CHPL_COMM to gasnet.  Then try it
 * varying the numbers of locales and by changing the problem size
 * (--n=16).
 *
 * WARNING: Support for distributions is very much a work-in-progress
 * and many features that work with non-distributed arrays and domains
 * will not work with distributed arrays and domains.  Think of this
 * example as a preview.
 *
 */

//
// Standard module MultiBlockDist defines the Block distribution.
//
use MultiBlockDist;

//
// Size of each dimension of our domain.  Note that int(64) is the
// default for domains and arrays distributed with the Block
// distribution.
//
config var n: int(64) = 8;

//
// Declare and initialize an instance of the Block distribution Dist,
// a distributed domain Dom, and a distributed array A.  By default,
// the Block distribution distributes the domain across all locales.
//
var Dist = new Block(rank=2, bbox=[1..n, 1..n]);
var Dom: domain(2,int(64)) distributed Dist = [1..n, 1..n];
var A: [Dom] int;

//
// Output the domain and array.  They print just like non-distributed
// domains and arrays.
//
writeln("Domain");
writeln(Dom);
writeln();

writeln("Array");
writeln(A);
writeln();

//
// Output the locale ID numbers for each array element, determining
// this information by applying ".locale" to each array element.
//
writeln("Distribution Map");
for i in 1..n {
  for j in 1..n {
    write(A(i,j).locale.id, " ");
  }
  writeln();
}
writeln();

//
// Loop over the array using a serial for-loop and assign each element
// and increasing number.
//
var j = 1;
for a in A {
  a = j;
  j += 1;
}
writeln("Initialized array");
writeln(A);
writeln();

//
// In parallel, subtract one from each element of the array.
//
forall i in Dom do {
  A(i) = A(i) - 1;
}
writeln("Subtracted 1 via parallel iteration over the domain");
writeln(A);
writeln();

//
// In parallel, iterate over the array and set each element to 0.
//
forall a in A do {
  a = 0;
}
writeln("Zeroed via parallel iteration over the array");
writeln(A);