"Pi by Quadrature" again (sorry), but this time trying to use
parallelism via partitioning the problem using an parallel array. As a
first step I thought of using the Array[T] class -- or should that be
Array<T> the API page uses both notations, cf.
http://dist.codehaus.org/x10/xdoc/2.0.3/
I had thought that something along the lines of:
val computeSlice = ( p : Point ) => {
val id : int = p(0) ;
val start : long = 1 + id * sliceSize ;
val end : long = ( id + 1 ) * sliceSize ;
var sum : double = 0.0 ;
for ( var i : long = start ; i < end ; ++i ) {
val x : double = ( i - 0.5 ) * delta ;
sum += 1.0 / ( 1.0 + x * x ) ;
}
sum
} ;
val sums = ( new Array[Double] ( numberOfTasks) ).lift
( computeSlice ) ;
<<<< I am not convinced this operation labelled "lift" is actually a
"lift" operation, it is actually "map" isn't it? >>>>
should do the job (rightly or wrongly), but when compiled (successful)
and then executed, I get:
|>x10c++ -o Pi_X10_Parallel Pi_X10_Parallel.x10
x10c++: 1 dynamically checked calls or field accesses.
|> runx10 Pi_X10_Parallel
Uncaught exception at place 0: x10.lang.ClassCastException
x10.lang.ClassCastException
at x10::lang::Throwable::fillInStackTrace()
at x10aux::throwClassCastException()
at Pi_X10_Parallel() [0x41d42e]
at
x10aux::ClassCastNotPrimitive<x10aux::ref<x10::lang::Fun_0_1<double, double> >,
x10aux::ref<x10::lang::Fun_0_1<x10aux::ref<x10::array::Point>, double> >
>::_(x10aux::ref<x10::lang::Fun_0_1<x10aux::ref<x10::array::Point>, double> >,
bool)
at
x10aux::ClassCastPrimitive<x10aux::ref<x10::lang::Fun_0_1<double, double> >,
x10aux::ref<x10::lang::Fun_0_1<x10aux::ref<x10::array::Point>, double> >
>::_(x10aux::ref<x10::lang::Fun_0_1<x10aux::ref<x10::array::Point>, double> >,
bool)
at x10aux::ClassCast<x10aux::ref<x10::lang::Fun_0_1<double,
double> >, x10aux::ref<x10::lang::Fun_0_1<x10aux::ref<x10::array::Point>,
double> > >::_(x10aux::ref<x10::lang::Fun_0_1<x10aux::ref<x10::array::Point>,
double> >, bool)
at x10aux::ref<x10::lang::Fun_0_1<double, double> >
x10aux::class_cast<x10aux::ref<x10::lang::Fun_0_1<double, double> >,
x10aux::ref<x10::lang::Fun_0_1<x10aux::ref<x10::array::Point>, double> >
>(x10aux::ref<x10::lang::Fun_0_1<x10aux::ref<x10::array::Point>, double> >)
at Pi_X10_Parallel::execute(int)
at
Pi_X10_Parallel::main(x10aux::ref<x10::lang::Rail<x10aux::ref<x10::lang::String>
> >)
at x10aux::BootStrapClosure::apply()
at x10_lang_Runtime__closure__1::apply()
at x10::lang::Activity::run()
at x10_lang_Runtime__Worker__closure__0::apply()
at
x10::lang::Runtime__Worker::loop(x10aux::ref<x10::lang::Runtime__Latch>, bool)
at x10::lang::Runtime__Worker::apply()
at x10::lang::Runtime__Pool::apply()
at
x10::lang::Runtime::start(x10aux::ref<x10::lang::VoidFun_0_0>,
x10aux::ref<x10::lang::VoidFun_0_0>)
at int x10aux::template_main<x10::lang::Runtime,
Pi_X10_Parallel>(int, char**)
at main
at __libc_start_main
at Pi_X10_Parallel() [0x41c9e9]
|>
which doesn't really tell me anything useful in terms I can relate to my
code. Using the Java backend:
|> x10c Pi_X10_Parallel.x10
x10c: 1 dynamically checked calls or field accesses.
|> x10 Pi_X10_Parallel
java.lang.ClassCastException
at Pi_X10_Parallel$2.cast(Pi_X10_Parallel.java:110)
at Pi_X10_Parallel.execute(Pi_X10_Parallel.java:115)
at Pi_X10_Parallel.main(Pi_X10_Parallel.java:204)
at Pi_X10_Parallel$Main$2.apply(Pi_X10_Parallel.java:183)
at x10.lang.Runtime$5.apply(Runtime.java:4454)
at x10.lang.Activity.run(Activity.java:217)
at x10.lang.Runtime$Worker$3.apply(Runtime.java:3455)
at x10.runtime.impl.java.Runtime.runAt(Runtime.java:105)
at x10.lang.Runtime$Worker.loop(Runtime.java:3422)
at x10.lang.Runtime$Worker.apply(Runtime.java:3308)
at x10.lang.Runtime$Pool.apply(Runtime.java:3842)
at x10.lang.Runtime.start(Runtime.java:4461)
at Pi_X10_Parallel$Main.main(Pi_X10_Parallel.java:166)
at x10.runtime.impl.java.Runtime.run(Runtime.java:50)
at java.lang.Thread.run(Thread.java:636)
|>
which at least gives me some pointers to lines in error, but only in
terms of the intermediate generated code:
if (rtt != null && ! rtt.instanceof$(self)) throw new
java.lang.ClassCastException();
OK, it is clear from the context of the line in the Java code that the
problematic code in X10 is:
val sums = ( new Array[Double] ( numberOfTasks) ).lift
( computeSlice ) ;
but there is no way this is a reasonable way of debugging things. Have
I just missed something that I should have realized?
--
Russel.
=============================================================================
Dr Russel Winder t: +44 20 7585 2200 voip: sip:[email protected]
41 Buckmaster Road m: +44 7770 465 077 xmpp: [email protected]
London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
------------------------------------------------------------------------------
_______________________________________________
X10-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/x10-users