On 31 Aug 2009, at 8:02 PM, Igor Peshansky wrote:

> Jim LaGrone <jlagr...@cs.uh.edu> wrote on 08/31/2009 05:10:30 PM:
>
>> On 31 Aug 2009, at 11:10 AM, Igor Peshansky wrote:
>>
>>>> tmp_fs_real and tmp_fs_image are Rails[Double].
>>>>
>>>>  val real = tmp_fs_real;
>>>>  val image = tmp_fs_image;
>>>>
>>>>  val Mc_tmp = Mc;  //just made this change
>>>>  val N_tmp = N;     // and this one
>>>>  regionS = [0..N_tmp-1, 0..Mc_tmp-1];
>>>>  distS = Dist.makeBlock(regionS,0);
>>>>  S = Array.make[Complex](distS,
>>>>      (val (i,j):Point) => new Complex ( real(i*Mc_tmp+j), image
>>>> (i*Mc_tmp+j) ) );
>>>
>>> Ah.  I kept thinking of real() and image() as functions, but they
>>> are, in fact, Rails...  That would explain it: Rails are objects,
>>> and thus live in the place they were created.  So, accessing them
>>> from another place will give you a BadPlaceException.
>>>
>>> One possible solution is to make them ValRails (if the algorithm
>>> allows this).  Another is to send the relevant bits using ValRails
>>> into other Rails that live in the appropriate places.
>>
>>
>> Here's what I have:
>>
>> The values of tmp_fs_real and tmp_fs_image are read from a file. I
>> then need to pair up each tmp_fs_real(n) with tmp_fs_image(n) for S 
>> (n).
>>
>>      try{
>>          inputStream = new FileReader( new File(file_path) );
>>
>>          tmp_fs_real  = Rail.makeVal[Double](Mc*N, (i:int) => 0.0);
>>          tmp_fs_imag  = Rail.makeVal[Double](Mc*N, (i:int) => 0.0);
>>          for (i = 0; i < Mc*N; i++){
>>             tmp_fs_real(i) = inputStream.read( LSB.DOUBLE );
>>          }
>>          for (i = 0; i < Mc*N; i++){
>>             tmp_fs_imag(i) = inputStream.read( LSB.DOUBLE );
>>          }
>>          inputStream.close();
>>
>>          val real = tmp_fs_real;
>>          val imag = tmp_fs_imag;
>>       /*simulated SAR signal array*/
>>
>>       val Mc_tmp = Mc;
>>       val N_tmp = N;
>>       regionS = [0..N_tmp-1, 0..Mc_tmp-1];
>>       distS = Dist.makeBlock(regionS,0);
>>
>>       S = Array.make[Complex](distS,
>>          (val (i,j):Point) => new Complex ( real(i*Mc_tmp+j), imag
>> (i*Mc_tmp+j) ) );
>>
>> I will eventually use FFT on S, which is where the work is, so I
>> assume S should be distributed for the work. The API for Rail makes  
>> it
>> look like makeVal() returns a ValRail. The above code still throws  
>> the
>> BPException.
>
> Rail.makeVal() does indeed return a ValRail, but you did not show the
> type of tmp_fs_real.  If you declared it to have the type Rail, then
> X10 will coerce the ValRail from the call to Rail.makeVal() into a
> Rail (by creating a new Rail and copying the values).  So you are
> really accessing a Rail in your loop.
>
> Note that if you did declare it as a ValRail, you would not have been
> able to execute this line:
>
>>             tmp_fs_real(i) = inputStream.read( LSB.DOUBLE );
>
> because setting elements is not supported by a ValRail.
>
> What you could do is this:
>
>>          val real = tmp_fs_real as ValRail[Double];
>>          val imag = tmp_fs_imag as ValRail[Double];
>
> or
>
>>          val real : ValRail[Double] = tmp_fs_real;
>>          val imag : ValRail[Double] = tmp_fs_imag;
>
> The above will convert the Rails to ValRails, and thus make them
> available in all places.
>
> Note that you could also do the following:
>
>>          val inputStream = new FileReader( new File(file_path) );
>>          val real = Rail.makeVal[Double](Mc*N, (i:int) =>
> inputStream.read( LSB.DOUBLE ));
>>          val imag  = Rail.makeVal[Double](Mc*N, (i:int) =>
> inputStream.read( LSB.DOUBLE ));
>>          inputStream.close();
>
> (i.e., use the initializer again).
>
> Note, however, that you'll be sending both ValRails to all places.
> Since you only use a part of the data in each place, you could
> capture only the relevant data in each place, by computing the
> range of indexes used in each place.  To do that, though, you
> would have to forgo the convenient initializer syntax.

I tried the initializers above with this result using the Java backend:

$ x10c -commandlineonly -d ../bin *.x10
x10c: ----------
      1. ERROR in ../bin/State.java (at line 601)
        return (inputStream1).<java.lang.Double>read 
(x10.types.Types.DOUBLE,
      LSB.DOUBLE);
          
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      Unhandled exception type IOException
      ----------
      2. ERROR in ../bin/State.java (at line 613)
        return (inputStream1).<java.lang.Double>read 
(x10.types.Types.DOUBLE,
      LSB.DOUBLE);
          
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^ 
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      Unhandled exception type IOException
      ----------
      2 problems (2 errors)
x10c: Non-zero return code: 255
2 errors.

I have a try-catch, so I don't know what's going on here. Here's my  
code:

       try{
          val inputStream1 = new FileReader( new File(file_path) );

          //these ValRails will be at each place;
          //could optimize by distributing
          val tmp_fs_real  = Rail.makeVal[Double](Mc*N,
             (i:int) => inputStream1.read( LSB.DOUBLE ));
          val tmp_fs_imag  = Rail.makeVal[Double](Mc*N,
             (i:int) => inputStream1.read( LSB.DOUBLE ));
          inputStream1.close();

       /*simulated SAR signal array*/
       val Mc_tmp = Mc;
       val N_tmp = N;
       regionS = [0..N_tmp-1, 0..Mc_tmp-1];
       distS = Dist.makeBlock(regionS,0);
       S = Array.make[Complex](distS,
          (val (i,j):Point) => new Complex ( tmp_fs_real(i*Mc_tmp+j),  
tmp_fs_imag(i*Mc_tmp+j) ) );
       ....
       }
       catch( ioe: IOException )  {
          ioe.printStackTrace(Console.ERR);
          System.exit(1);
       }


Thanks for all the help.

Jim

------------------------------------------------------------------------------
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