Hi, Sarat,

These are not the errors I was getting from 2.0.  For the code in my
message, I got:

./ATFInitMatrix.x10:8: Cannot read fields of the proto value proto 
ATFInitMatrix.this
./ATFInitMatrix.x10:9: Cannot read fields of the proto value proto 
ATFInitMatrix.this
./ATFInitMatrix.x10:10: Cannot read fields of the proto value proto 
ATFInitMatrix.this
./ATFInitMatrix.x10:13: Method or static constructor not found for 
ATF_dim(x10.lang.Int{_self15360==0})
./ATFInitMatrix.x10:14: Method or static constructor not found for 
ATF_dim(x10.lang.Int{_self15416==1})
./ATFInitMatrix.x10:15: Method or static constructor not found for 
ATF_dim(x10.lang.Int{_self15472==2})

because the code is using ATF_dim before the constructor is done.

The way to fix those is to create a local variable to store the ATF_dim
array, and assign it to the field at the end of the constructor, like
this:

class ATFInitMatrix {
    global val ATF_dim:Array[Int](1);
    global val ATF_rm000:Array[Double](5);

    public def this(var px:int, var py:int, var pz:int) {
        val dim5:Array[Int](1) = Array.make[Int](0..4);
        val atfdim:Array[Int](1) = Array.make[Int](0..2);

        atfdim(0) = px;
        atfdim(1) = py;
        atfdim(2) = pz;

        /* Allocate dynamic arrays */
        dim5(0) = atfdim(0)+2;
        dim5(1) = atfdim(1)+2;
        dim5(2) = atfdim(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_dim = atfdim;
        ATF_rm000 = Array.make[Double](D1);
    }
    ...
}

Hope this helps,
        Igor

sarat poluri <sarat.pol...@gmail.com> wrote on 12/01/2009 02:17:45 AM:

> Hi,
> 
> If i declare ATF_rm000 as global val "Final field "ATF_rm000" might 
> not have been initialized" error is shown. In which case i would be 
> back to square one.
> 
> Thanks,
> Sarat
> 
> On Tue, Nov 24, 2009 at 5:00 PM, Igor Peshansky <ig...@us.ibm.com> 
wrote:
> Hi, Sarat,
> 
> X10 2.0 doesn't have value classes anymore.  The pattern for what
> you want to do is to make all fields global.  The rest of the solution
> is the same, however.
> 
> So, you'd have something like
> 
> class ATFInitMatrix {
>   global val ATF_dim:Array[Int](1) = Array.make[Int](0..2);
>   global val ATF_rm000:Array[Double](5);
> 
>   public def this(var px:int, var py:int, var pz:int) {
>      val 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);
>   }
>   ...
> }
> 
> Hope this helps,
>        Igor
> 
> sarat poluri <sarat.pol...@gmail.com> wrote on 11/24/2009 04:25:35 PM:
> 
> > Hi Igor,
> >
> > I am using X10 2.0. So, how would the solution be different in this
> > case?
> >
> > Thanks,
> > Sarat
> >
> > On Tue, Nov 10, 2009 at 1:58 PM, Igor Peshansky <ig...@us.ibm.com>
> > wrote:
> > 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/)


------------------------------------------------------------------------------
Join us December 9, 2009 for the Red Hat Virtual Experience,
a free event focused on virtualization and cloud computing. 
Attend in-depth sessions from your desk. Your couch. Anywhere.
http://p.sf.net/sfu/redhat-sfdev2dev
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to