Eventually I'll get the hang of this. Thanks for all your help.

On Aug 27, 2009, at 6:13 PM, Igor Peshansky wrote:

> Jim LaGrone <[email protected]> wrote on 08/27/2009 06:43:57 PM:
>
>>
>> On Aug 27, 2009, at 3:55 PM, Igor Peshansky wrote:
>>
>>> You can also use the place-local idiom, as follows:
>>>
>>>     val norms = Array.make[Double](Dist.makeUnique(), (Point)=>0.0);
>>>     finish ateach ( (p) in distS.places() ) {
>>>        for ( (i, j) in distS | p ) { // at this point, p == here
>>>           norms(p.id) += Math.sqrt(S(i,j).real*S(i,j).real +
>>>              S(i,j).image*S(i,j).image);
>>>        }
>>>     }
>>>     rawNormPower2 = norms.sum(); // a distributed reduction
>>>
>>> Here, norms is an array with a unique distribution (which has one
>>> point
>>> per place).  The ateach loop again spawns parallel iterations on  
>>> each
>>> place (but now there's one per place covered by the distribution).
>>> The
>>> body of the ateach has a sequential loop that runs over the part of
>>> distS
>>> that lives in that place.  Each iteration of that sequential loop
>>> updates
>>> the local element of norms.  There is no need for atomic, since all
>>> updates happen sequentially.  Once the ateach loop is done, a
>>> (distributed)
>>> reduction is performed over the norms array, and the sum is stored
>>> in the
>>> final result location.
>>
>>
>> Using this method and Java backend, I have
>>
>>   rawNormPower2 = 0;
>>   val norms = Array.make[Double](Dist.makeUnique(), (Point)=>0.0);
>>   finish ateach( (p) in distS.places() ){   //line 327
>>      for( (i,j) in distS | p ){
>>         norms(p.id) += Math.sqrt(S(i1,j1).real*S(i1,j1).real +
>>               S(i1,j1).image*S(i1,j1).image);
>>      }
>>   }
>>   rawNormPower2 = norms.sum()/( N*Mc );  //line 333
>>
>>
>> but get this
>>
>> /Users/jlagrone/GradSchool/Research/workspace/X10-code/SSCA3-X10/src-
>> par/State.x10:327: Could not infer type for formal parameter.
>> /Users/jlagrone/GradSchool/Research/workspace/X10-code/SSCA3-X10/src-
>> par/State.x10:327: Could not infer type for formal parameter.
>> /Users/jlagrone/GradSchool/Research/workspace/X10-code/SSCA3-X10/src-
>> par/State.x10:333: No valid method call found for sum() in
>> x10.lang.Array[x10.lang.Double].
>
> Sorry, this will teach me to actually test the code before sending  
> it out.
> Line 327 should be "finish for ( p in distS.places() ) async (p) {".
> In line 33, replace "sum()" by "reduce((a:Int,b:Int)=>a+b, 0)".
>

First -

        reduce((a:Int,b:Int)=>a+b, 0) doesn't compile.
        The API looks like this should work:

                reduce(Double.+,0)

        It compiles but I don't know about the correctness.

Second -

   Using this code:

        val norms = Array.make[Double](Dist.makeUnique(), (Point)=>0.0);
        finish for ( p in distS.places() ) async(p){
                for( (i,j) in distS | p ){
                        norms(p.id) += Math.sqrt(S(i,j).real*S(i,j).real +
                                        S(i,j).image*S(i,j).image);     
                }
        }

   I get this output for places 3, 2, & 1:

BAD PLACE EXCEPTION
BAD PLACE EXCEPTION
BAD PLACE EXCEPTION
x10.lang.BadPlaceException: object=State Object {/*object values  
omitted*/} access at place=(Place 3)
        at x10.runtime.Runtime.placeCheck(Runtime.java:699)
        at State$2.apply(State.java:674)
        at x10.runtime.Activity.now(Activity.java:222)
        at x10.runtime.Activity.run(Activity.java:156)
        at x10.runtime.Worker$3.apply(Worker.java:330)
        at x10.runtime.impl.java.Runtime.runAt(Runtime.java:96)
        at x10.runtime.Worker.loop(Worker.java:317)
        at x10.runtime.Worker.join(Worker.java:246)
        at x10.runtime.Pool$5.apply(Pool.java:418)
        at x10.runtime.impl.java.Runtime.runAt(Runtime.java:96)
        at x10.runtime.Pool.join(Pool.java:410)
        at x10.runtime.FinishState.waitForFinish(FinishState.java:83)
        at x10.runtime.Runtime.stopFinish(Runtime.java:1068)
        at State.formImage(State.java:731)
        at State.stage1(State.java:1417)
        at RUN_knowledgeFormation.main(RUN_knowledgeFormation.java:466)
        at RUN_knowledgeFormation$Main$1.apply(RUN_knowledgeFormation.java:48)
        at x10.runtime.Activity.now(Activity.java:222)
        at x10.runtime.Activity.run(Activity.java:127)
        at x10.runtime.Worker$3.apply(Worker.java:330)
        at x10.runtime.impl.java.Runtime.runAt(Runtime.java:96)
        at x10.runtime.Worker.loop(Worker.java:317)
        at x10.runtime.Runtime.start(Runtime.java:143)
        at RUN_knowledgeFormation$Main.main(RUN_knowledgeFormation.java:35)
        at x10.runtime.impl.java.Runtime.run(Runtime.java:46)
        at java.lang.Thread.run(Thread.java:613)



A query on Place.MAX_PLACES returns 4 and I'm using a dual-core with  
Java backend.

Any suggestions?

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
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users

Reply via email to