Thanks a lot. It solved the issue. I will surely look into the sample
codes.
Thanks and Regards
Sparsh Mittal
On Wed, Feb 13, 2013 at 5:06 PM, Josh Milthorpe
<josh.miltho...@anu.edu.au>wrote:
> Sorry... I responded to Dave's email before seeing this one!
>
> The main method must remain static or the X10 compiler won't recognise it
> as the program main method.
>
> However to call an instance method on Test, you need an instance of the
> class. Therefore:
>
> public static def main(args: Array[String](1)) {
> val test = new Test();
>
> finish for(var k: Int =0; k< 5; k++) {
> val kk = k;
> async test.funcWorker(kk );
>
> }
> Console.OUT.println("I am done " );
> }
>
>
> It is certainly more difficult to learn X10 without a background in Java,
> but it's not impossible. The Programmer's Guide is a good start (
> http://x10-lang.org/documentation/practical-x10-programming/programmers-guide.html).
> Wherever possible you should learn from good examples that are available,
> like the sample codes that come with the distribution
> (~/x10-trunk/x10.dist/samples) and
> http://x10-lang.org/documentation/code-examples/small-examples.html . I
> also distribute a number of small samples with ANUChem (
> https://sourceforge.net/projects/anuchem/) - see the samples subdirectory.
>
> Cheers,
>
> Josh
>
>
>
> On 14/02/13 09:19, Sparsh Mittal wrote:
>
> Thanks for your reply. However, even after making it a var, I get
> complaint:
>
> *Cannot access a non-static field field Test.currentWorkCounter:
> x10.lang.Int from a static context
> *
> And to avoid it, I will have to make other two functions as non-static,
> but then the whole program does not run properly and it complains:
>
> *x10c++: No main method found
> 1 error.
> *
> Please help me, since I am not from Java background hence I am getting
> such errors. Thanks.
>
>
> Thanks and Regards
> Sparsh Mittal
>
>
>
> On Wed, Feb 13, 2013 at 4:07 PM, David P Grove <gro...@us.ibm.com> wrote:
>
>> Hi,
>>
>> "val" roughly corresponds to "final" in Java (or const in C++) To
>> declare an instance field you want to be able to modify you need to use
>> "var"
>>
>> var currentWorkCounter: Int =-1 ;
>>
>> --dave
>>
>>
>> Sparsh Mittal <sparsh0mit...@gmail.com> wrote on 02/13/2013 12:11:46 PM:
>>
>> >
>> > Hello
>> > Here is the minimum working example of what I am trying to do. I
>> > want to make currentWorkCounter a non-static member, which multiple
>> > functions in the class can use and modify. However, compiler does
>> > not allow. Can you please tell how to accomplish.
>> >
>> > //Does not compile due to non-static member.
>> > import x10.io.Console;
>> > import x10.lang.Int;
>> >
>> > public class Test {
>> >
>> > val currentWorkCounter: Int =-1 ;
>> >
>> > public static def funcWorker (myNumber: Int) {
>> > val answer:Int;
>> >
>> > atomic {
>> > currentWorkCounter = currentWorkCounter +1;
>> > answer =currentWorkCounter;
>> > }
>> >
>> > Console.OUT.println(myNumber+" did "+ answer);
>> >
>> > }
>> >
>> > public static def main(args: Array[String](1)) {
>> >
>> >
>> > finish for(var k: Int =0; k< 5; k++) {
>> > val kk = k;
>> >
>> > async funcWorker(kk );
>> > }
>> >
>> > Console.OUT.println("I am done " );
>> >
>> >
>> > }
>> > }
>> >
>>
>> > Thanks and Regards
>> > Sparsh Mittal
>> >
>> ------------------------------------------------------------------------------
>> > Free Next-Gen Firewall Hardware Offer
>> > Buy your Sophos next-gen firewall before the end March 2013
>> > and get the hardware for free! Learn more.
>> > http://p.sf.net/sfu/sophos-d2d-feb
>> > _______________________________________________
>> > X10-users mailing list
>> > X10-users@lists.sourceforge.net
>> > https://lists.sourceforge.net/lists/listinfo/x10-users
>>
>>
>> ------------------------------------------------------------------------------
>> Free Next-Gen Firewall Hardware Offer
>> Buy your Sophos next-gen firewall before the end March 2013
>> and get the hardware for free! Learn more.
>> http://p.sf.net/sfu/sophos-d2d-feb
>> _______________________________________________
>> X10-users mailing list
>> X10-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/x10-users
>>
>>
>
>
> ------------------------------------------------------------------------------
> Free Next-Gen Firewall Hardware Offer
> Buy your Sophos next-gen firewall before the end March 2013
> and get the hardware for free! Learn more.http://p.sf.net/sfu/sophos-d2d-feb
>
>
>
> _______________________________________________
> X10-users mailing
> listX10-users@lists.sourceforge.nethttps://lists.sourceforge.net/lists/listinfo/x10-users
>
>
>
>
> ------------------------------------------------------------------------------
> Free Next-Gen Firewall Hardware Offer
> Buy your Sophos next-gen firewall before the end March 2013
> and get the hardware for free! Learn more.
> http://p.sf.net/sfu/sophos-d2d-feb
> _______________________________________________
> X10-users mailing list
> X10-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/x10-users
>
>
------------------------------------------------------------------------------
Free Next-Gen Firewall Hardware Offer
Buy your Sophos next-gen firewall before the end March 2013
and get the hardware for free! Learn more.
http://p.sf.net/sfu/sophos-d2d-feb
_______________________________________________
X10-users mailing list
X10-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/x10-users