sarat poluri <sarat.pol...@gmail.com> wrote on 11/10/2009 02:03:23 PM:

> Hi,
> 
> How can i distribute a n-dimensional array as blocks across all places 
and
> then initialize each element of that array?
> 
> i have an array which is first declared as a 5-D array and then inside a
> function the array is initialized with the appropriate distribution 
taking
> the bounds of the region from the parameters of that function.
> 
> class ATFInitMatrix
> {
> var ATF_dim:Array[Int](1) = Array.make[Int](0..2);
> 
>         var ATF_rm000:Array[Double](5);
> 
> public def ATF_Init_matrix(var px:int, var py:int, var pz:int):boolean
> {
>  var dim5:Array[Int](1) = Array.make[Int](0..4);
> 
>         ATF_dim(0) = px;
>         ATF_dim(1) = py;
>         ATF_dim(2) = pz;
> 
>     /* Allocate dynamic arrays */
>     dim5(0) = ATF_dim(0)+2;
>     dim5(1) = ATF_dim(1)+2;
>     dim5(2) = ATF_dim(2)+2;
>     dim5(3) = 1;
>     dim5(4) = 1;
> 
>     val R1 = [0..dim5(0), 0..dim5(1),0..dim5(2),0..dim5(3),0..dim5(4)];
>     val D1  = Dist.makeBlock(R1, 0);
> 
>     ATF_rm000 = Array.make[Double](D1);
> }
> 
> public def ATF_Reset():boolean
> {
>      finish ateach(val p(i,j,k,l,n): Point(5) in ATF_rm000.dist)
>     {
>            ATF_rm000(p) = 0.0;
>     }
> }
> 
> The ATF_Reset function throws a badplaceexception. What are the options
> available to do this. should i declare the ATF_rm000 array as a val 
instead
> of var, in which case how do i declare first and initialize later or is
> there another approach.
> 
> Please advice.

Hi, Sarat,

You are not getting a BadPlaceException because you're accessing the wrong
point in the distribution.  You are getting it because you are trying to
access the field ATF_rm000 from the current object, which lives in place 
0.

In the below, I'll assume you're using X10 1.7.  If you are using X10 2.0,
the solution will be different.

I would make ATFInitMatrix a value class (thus ATF_rm000 becomes a val
field that you have to initialize early).  Then you can access all of its
fields at any place.
        Igor
-- 
Igor Peshansky  (note the spelling change!)
IBM T.J. Watson Research Center
XJ: No More Pain for XML's Gain (http://www.research.ibm.com/xj/)
X10: Parallel Productivity and Performance (http://x10.sf.net/)


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to