ForkJoinTasks seem to quit without throwing, on larger tasks.

View: New views
8 Messages — Rating Filter:   Alert me  

ForkJoinTasks seem to quit without throwing, on larger tasks.

by Qin, Henry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ForkJoinTasks seem to quit without throwing, on larger tasks.

Hi,

In the following example, it appears that forkjoin simply quits without completing its task.

If you change Integer.MAX_VALUE to 1000, the task is completed correctly.

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

//            if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

If someone has come across the behavior before, could they please share a work-around?

If this is indeed a hard limitation on the size of tasks that ForkJoinTasks can accomplish, perhaps it should be documented? The current documentation speaks of an ideal ForkJoinTask as being between 100 and 10000 computations, but does not mention that the framework will simply quit with larger tasks.

Note that Ive tried to extend ForkJoinTask directly as well, and not just RecursiveAction.


Thanks,

~Henry


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

Re: ForkJoinTasks seem to quit without throwing, on larger tasks.

by David Holmes-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

ForkJoinTasks seem to quit without throwing, on larger tasks.
Does it also quit at, say, 10000?
 
I think you are seeing the JIT compiler at work. The whole loop does nothing visible so can simply be elided.
 
> int tcount = 0; 
> while (tcount < Integer.MAX_VALUE)  
>   tcount++;
 
The JIT threshhold for the loop is around 1500 if I recall correctly. Try making tcount a field instead and refer to it elsewhere. Though even then, the loop could be replaced with a simple assignment (not sure the JIT will see that though :) )
 
David Holmes
-----Original Message-----
From: concurrency-interest-bounces@... [mailto:concurrency-interest-bounces@...]On Behalf Of Qin, Henry
Sent: Thursday, 17 September 2009 8:57 AM
To: concurrency-interest@...
Subject: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

Hi,

In the following example, it appears that forkjoin simply quits without completing its task.

If you change Integer.MAX_VALUE to 1000, the task is completed correctly.

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

//            if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

If someone has come across the behavior before, could they please share a work-around?

If this is indeed a hard limitation on the size of tasks that ForkJoinTasks can accomplish, perhaps it should be documented? The current documentation speaks of an ideal ForkJoinTask as being between 100 and 10000 computations, but does not mention that the framework will simply quit with larger tasks.

Note that Ive tried to extend ForkJoinTask directly as well, and not just RecursiveAction.


Thanks,

~Henry


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

Re: ForkJoinTasks seem to quit without throwing, on larger tasks.

by Qin, Henry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
ForkJoinTasks seem to quit without throwing, on larger tasks.

The problem is not that the loop is not looping. What happens is that the print statement in the code (which is not in the loop) doesn’t print all the numbers from 1 to 1000, as it would when you change Integer.MAX_VALUE to 1000 or even 2000.

 

That is, it is only printing some of those numbers (it’s not always the same number of numbers, but always less than the full 1000). That leads me to believe that forkjoin is simply giving up when the task grows too large (I have no idea why it might do this, but that’s what it looks like).

 

Thanks,

~Henry

 

From: David Holmes [mailto:davidcholmes@...]
Sent: Wednesday, September 16, 2009 4:09 PM
To: Qin, Henry; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

 

Does it also quit at, say, 10000?

 

I think you are seeing the JIT compiler at work. The whole loop does nothing visible so can simply be elided.

 

> int tcount = 0; 

> while (tcount < Integer.MAX_VALUE)  

>   tcount++;

 

The JIT threshhold for the loop is around 1500 if I recall correctly. Try making tcount a field instead and refer to it elsewhere. Though even then, the loop could be replaced with a simple assignment (not sure the JIT will see that though :) )

 

David Holmes

-----Original Message-----
From: concurrency-interest-bounces@... [mailto:concurrency-interest-bounces@...]On Behalf Of Qin, Henry
Sent: Thursday, 17 September 2009 8:57 AM
To: concurrency-interest@...
Subject: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

Hi,

In the following example, it appears that forkjoin simply quits without completing its task.

If you change Integer.MAX_VALUE to 1000, the task is completed correctly.

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

//            if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

If someone has come across the behavior before, could they please share a work-around?

If this is indeed a hard limitation on the size of tasks that ForkJoinTasks can accomplish, perhaps it should be documented? The current documentation speaks of an ideal ForkJoinTask as being between 100 and 10000 computations, but does not mention that the framework will simply quit with larger tasks.

Note that I’ve tried to extend ForkJoinTask directly as well, and not just RecursiveAction.

 

Thanks,

~Henry


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

Re: ForkJoinTasks seem to quit without throwing, on larger tasks.

by David Holmes-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
ForkJoinTasks seem to quit without throwing, on larger tasks.
Henry,
 
Please clarify. The only occurrence of Integer.MAX_VALUE is in the loop that I quoted so I don't see what affect changing it can have on the println.
 
Another possibility is that you're hitting an exception (an Error not Exception) - such as OutOfMemoryError - and so you fail silently. I'm not sure what happens with uncaught exceptions in the FJ framework.
 
(I don't have jsr166y installed locally so can't try this directly right now.)
 
David Holmes
-----Original Message-----
From: Qin, Henry [mailto:Henry.Qin@...]
Sent: Thursday, 17 September 2009 9:21 AM
To: dholmes@...; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

The problem is not that the loop is not looping. What happens is that the print statement in the code (which is not in the loop) doesn’t print all the numbers from 1 to 1000, as it would when you change Integer.MAX_VALUE to 1000 or even 2000.

 

That is, it is only printing some of those numbers (it’s not always the same number of numbers, but always less than the full 1000). That leads me to believe that forkjoin is simply giving up when the task grows too large (I have no idea why it might do this, but that’s what it looks like).

 

Thanks,

~Henry

 

From: David Holmes [mailto:davidcholmes@...]
Sent: Wednesday, September 16, 2009 4:09 PM
To: Qin, Henry; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

 

Does it also quit at, say, 10000?

 

I think you are seeing the JIT compiler at work. The whole loop does nothing visible so can simply be elided.

 

> int tcount = 0; 

> while (tcount < Integer.MAX_VALUE)  

>   tcount++;

 

The JIT threshhold for the loop is around 1500 if I recall correctly. Try making tcount a field instead and refer to it elsewhere. Though even then, the loop could be replaced with a simple assignment (not sure the JIT will see that though :) )

 

David Holmes

-----Original Message-----
From: concurrency-interest-bounces@... [mailto:concurrency-interest-bounces@...]On Behalf Of Qin, Henry
Sent: Thursday, 17 September 2009 8:57 AM
To: concurrency-interest@...
Subject: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

Hi,

In the following example, it appears that forkjoin simply quits without completing its task.

If you change Integer.MAX_VALUE to 1000, the task is completed correctly.

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

//            if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

If someone has come across the behavior before, could they please share a work-around?

If this is indeed a hard limitation on the size of tasks that ForkJoinTasks can accomplish, perhaps it should be documented? The current documentation speaks of an ideal ForkJoinTask as being between 100 and 10000 computations, but does not mention that the framework will simply quit with larger tasks.

Note that I’ve tried to extend ForkJoinTask directly as well, and not just RecursiveAction.

 

Thanks,

~Henry


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

Re: ForkJoinTasks seem to quit without throwing, on larger tasks.

by Qin, Henry :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
ForkJoinTasks seem to quit without throwing, on larger tasks.

First, I just realized that the code below had an if statement commented out. That was a mistake that was not in the code I was compiling and testing. That limits the amount of tasks created.

 

It’s exactly as you said,  the only occurrence of Integer.MAX_VALUE is in the loop, and the println appears to be completely separate in the code.

What I observe is that when I change that value (the place where integer.MAX_VALUE currently is), it affects whether or not all the prints are executed.

 

The expected behavior of the code is to print all the numbers from 1 to 1000, although not necessarily in that order. The code as it is below (without the conditional commented out) only prints some of the numbers from 1 to 1000. However, when I change Integer.MAX_VALUE to 1000 or 2000, then the code behaves as expected, printing all the numbers from 1 to 1000.

 

For clarity, here is the code again, without the incorrect comment:

 

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

          if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

 

 

From: David Holmes [mailto:davidcholmes@...]
Sent: Wednesday, September 16, 2009 4:28 PM
To: Qin, Henry; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

 

Henry,

 

Please clarify. The only occurrence of Integer.MAX_VALUE is in the loop that I quoted so I don't see what affect changing it can have on the println.

 

Another possibility is that you're hitting an exception (an Error not Exception) - such as OutOfMemoryError - and so you fail silently. I'm not sure what happens with uncaught exceptions in the FJ framework.

 

(I don't have jsr166y installed locally so can't try this directly right now.)

 

David Holmes

-----Original Message-----
From: Qin, Henry [mailto:Henry.Qin@...]
Sent: Thursday, 17 September 2009 9:21 AM
To: dholmes@...; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

The problem is not that the loop is not looping. What happens is that the print statement in the code (which is not in the loop) doesn’t print all the numbers from 1 to 1000, as it would when you change Integer.MAX_VALUE to 1000 or even 2000.

 

That is, it is only printing some of those numbers (it’s not always the same number of numbers, but always less than the full 1000). That leads me to believe that forkjoin is simply giving up when the task grows too large (I have no idea why it might do this, but that’s what it looks like).

 

Thanks,

~Henry

 

From: David Holmes [mailto:davidcholmes@...]
Sent: Wednesday, September 16, 2009 4:09 PM
To: Qin, Henry; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

 

Does it also quit at, say, 10000?

 

I think you are seeing the JIT compiler at work. The whole loop does nothing visible so can simply be elided.

 

> int tcount = 0; 

> while (tcount < Integer.MAX_VALUE)  

>   tcount++;

 

The JIT threshhold for the loop is around 1500 if I recall correctly. Try making tcount a field instead and refer to it elsewhere. Though even then, the loop could be replaced with a simple assignment (not sure the JIT will see that though :) )

 

David Holmes

-----Original Message-----
From: concurrency-interest-bounces@... [mailto:concurrency-interest-bounces@...]On Behalf Of Qin, Henry
Sent: Thursday, 17 September 2009 8:57 AM
To: concurrency-interest@...
Subject: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

Hi,

In the following example, it appears that forkjoin simply quits without completing its task.

If you change Integer.MAX_VALUE to 1000, the task is completed correctly.

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

      //     if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

If someone has come across the behavior before, could they please share a work-around?

If this is indeed a hard limitation on the size of tasks that ForkJoinTasks can accomplish, perhaps it should be documented? The current documentation speaks of an ideal ForkJoinTask as being between 100 and 10000 computations, but does not mention that the framework will simply quit with larger tasks.

Note that I’ve tried to extend ForkJoinTask directly as well, and not just RecursiveAction.

 

Thanks,

~Henry


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

Re: ForkJoinTasks seem to quit without throwing, on larger tasks.

by David Holmes-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
ForkJoinTasks seem to quit without throwing, on larger tasks.
Henry,
 
Did you check for OutOfMemoryError?
 
The loop (assuming it isn't compiled away) affects the lifetime of the task and hence the amount of memory needed.
 
I'll see if I can run this on another system ... not sure if FJ has been pushed into JDK7 yet.
 
David
-----Original Message-----
From: Qin, Henry [mailto:Henry.Qin@...]
Sent: Thursday, 17 September 2009 9:39 AM
To: dholmes@...; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

First, I just realized that the code below had an if statement commented out. That was a mistake that was not in the code I was compiling and testing. That limits the amount of tasks created.

 

It’s exactly as you said,  the only occurrence of Integer.MAX_VALUE is in the loop, and the println appears to be completely separate in the code.

What I observe is that when I change that value (the place where integer.MAX_VALUE currently is), it affects whether or not all the prints are executed.

 

The expected behavior of the code is to print all the numbers from 1 to 1000, although not necessarily in that order. The code as it is below (without the conditional commented out) only prints some of the numbers from 1 to 1000. However, when I change Integer.MAX_VALUE to 1000 or 2000, then the code behaves as expected, printing all the numbers from 1 to 1000.

 

For clarity, here is the code again, without the incorrect comment:

 

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

          if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

 

 

From: David Holmes [mailto:davidcholmes@...]
Sent: Wednesday, September 16, 2009 4:28 PM
To: Qin, Henry; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

 

Henry,

 

Please clarify. The only occurrence of Integer.MAX_VALUE is in the loop that I quoted so I don't see what affect changing it can have on the println.

 

Another possibility is that you're hitting an exception (an Error not Exception) - such as OutOfMemoryError - and so you fail silently. I'm not sure what happens with uncaught exceptions in the FJ framework.

 

(I don't have jsr166y installed locally so can't try this directly right now.)

 

David Holmes

-----Original Message-----
From: Qin, Henry [mailto:Henry.Qin@...]
Sent: Thursday, 17 September 2009 9:21 AM
To: dholmes@...; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

The problem is not that the loop is not looping. What happens is that the print statement in the code (which is not in the loop) doesn’t print all the numbers from 1 to 1000, as it would when you change Integer.MAX_VALUE to 1000 or even 2000.

 

That is, it is only printing some of those numbers (it’s not always the same number of numbers, but always less than the full 1000). That leads me to believe that forkjoin is simply giving up when the task grows too large (I have no idea why it might do this, but that’s what it looks like).

 

Thanks,

~Henry

 

From: David Holmes [mailto:davidcholmes@...]
Sent: Wednesday, September 16, 2009 4:09 PM
To: Qin, Henry; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

 

Does it also quit at, say, 10000?

 

I think you are seeing the JIT compiler at work. The whole loop does nothing visible so can simply be elided.

 

> int tcount = 0; 

> while (tcount < Integer.MAX_VALUE)  

>   tcount++;

 

The JIT threshhold for the loop is around 1500 if I recall correctly. Try making tcount a field instead and refer to it elsewhere. Though even then, the loop could be replaced with a simple assignment (not sure the JIT will see that though :) )

 

David Holmes

-----Original Message-----
From: concurrency-interest-bounces@... [mailto:concurrency-interest-bounces@...]On Behalf Of Qin, Henry
Sent: Thursday, 17 September 2009 8:57 AM
To: concurrency-interest@...
Subject: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

Hi,

In the following example, it appears that forkjoin simply quits without completing its task.

If you change Integer.MAX_VALUE to 1000, the task is completed correctly.

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

      //     if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

If someone has come across the behavior before, could they please share a work-around?

If this is indeed a hard limitation on the size of tasks that ForkJoinTasks can accomplish, perhaps it should be documented? The current documentation speaks of an ideal ForkJoinTask as being between 100 and 10000 computations, but does not mention that the framework will simply quit with larger tasks.

Note that I’ve tried to extend ForkJoinTask directly as well, and not just RecursiveAction.

 

Thanks,

~Henry


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

Re: ForkJoinTasks seem to quit without throwing, on larger tasks.

by David Holmes-6 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
ForkJoinTasks seem to quit without throwing, on larger tasks.
Henry,
 
ForkJoinPool uses daemon threads by default so your application is terminating before the task is done.
 
David
-----Original Message-----
From: Qin, Henry [mailto:Henry.Qin@...]
Sent: Thursday, 17 September 2009 9:39 AM
To: dholmes@...; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

First, I just realized that the code below had an if statement commented out. That was a mistake that was not in the code I was compiling and testing. That limits the amount of tasks created.

 

It’s exactly as you said,  the only occurrence of Integer.MAX_VALUE is in the loop, and the println appears to be completely separate in the code.

What I observe is that when I change that value (the place where integer.MAX_VALUE currently is), it affects whether or not all the prints are executed.

 

The expected behavior of the code is to print all the numbers from 1 to 1000, although not necessarily in that order. The code as it is below (without the conditional commented out) only prints some of the numbers from 1 to 1000. However, when I change Integer.MAX_VALUE to 1000 or 2000, then the code behaves as expected, printing all the numbers from 1 to 1000.

 

For clarity, here is the code again, without the incorrect comment:

 

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

          if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

 

 

From: David Holmes [mailto:davidcholmes@...]
Sent: Wednesday, September 16, 2009 4:28 PM
To: Qin, Henry; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

 

Henry,

 

Please clarify. The only occurrence of Integer.MAX_VALUE is in the loop that I quoted so I don't see what affect changing it can have on the println.

 

Another possibility is that you're hitting an exception (an Error not Exception) - such as OutOfMemoryError - and so you fail silently. I'm not sure what happens with uncaught exceptions in the FJ framework.

 

(I don't have jsr166y installed locally so can't try this directly right now.)

 

David Holmes

-----Original Message-----
From: Qin, Henry [mailto:Henry.Qin@...]
Sent: Thursday, 17 September 2009 9:21 AM
To: dholmes@...; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

The problem is not that the loop is not looping. What happens is that the print statement in the code (which is not in the loop) doesn’t print all the numbers from 1 to 1000, as it would when you change Integer.MAX_VALUE to 1000 or even 2000.

 

That is, it is only printing some of those numbers (it’s not always the same number of numbers, but always less than the full 1000). That leads me to believe that forkjoin is simply giving up when the task grows too large (I have no idea why it might do this, but that’s what it looks like).

 

Thanks,

~Henry

 

From: David Holmes [mailto:davidcholmes@...]
Sent: Wednesday, September 16, 2009 4:09 PM
To: Qin, Henry; concurrency-interest@...
Subject: RE: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

 

Does it also quit at, say, 10000?

 

I think you are seeing the JIT compiler at work. The whole loop does nothing visible so can simply be elided.

 

> int tcount = 0; 

> while (tcount < Integer.MAX_VALUE)  

>   tcount++;

 

The JIT threshhold for the loop is around 1500 if I recall correctly. Try making tcount a field instead and refer to it elsewhere. Though even then, the loop could be replaced with a simple assignment (not sure the JIT will see that though :) )

 

David Holmes

-----Original Message-----
From: concurrency-interest-bounces@... [mailto:concurrency-interest-bounces@...]On Behalf Of Qin, Henry
Sent: Thursday, 17 September 2009 8:57 AM
To: concurrency-interest@...
Subject: [concurrency-interest] ForkJoinTasks seem to quit without throwing,on larger tasks.

Hi,

In the following example, it appears that forkjoin simply quits without completing its task.

If you change Integer.MAX_VALUE to 1000, the task is completed correctly.

import jsr166y.*;

public class ForkPlay extends RecursiveAction{

    int myInt;

    public ForkPlay(int i){ myInt = i;}

    public void compute(){

        try{

      //     if (myInt > 1000) return;

            (new ForkPlay(myInt+1)).fork();

            System.out.println(myInt);

            int tcount = 0;

            while (tcount < Integer.MAX_VALUE)

                tcount++;

        }

        catch (Exception e){

            e.printStackTrace();

        }

    }

    static ForkJoinPool pool;

    public static void main(String[] args) throws Exception{

            pool = new ForkJoinPool(7);

            pool.invoke(new ForkPlay(1));

    }

}

If someone has come across the behavior before, could they please share a work-around?

If this is indeed a hard limitation on the size of tasks that ForkJoinTasks can accomplish, perhaps it should be documented? The current documentation speaks of an ideal ForkJoinTask as being between 100 and 10000 computations, but does not mention that the framework will simply quit with larger tasks.

Note that I’ve tried to extend ForkJoinTask directly as well, and not just RecursiveAction.

 

Thanks,

~Henry


_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

Re: ForkJoinTasks seem to quit without throwing, on larger tasks.

by Doug Lea :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Qin, Henry wrote:
> Hi,
>
> In the following example, it appears that forkjoin simply quits without
> completing its task.
>

Your tasks never join their subtasks, so the call to
   pool.invoke(new ForkPlay(1))
will return as soon as ForkPlay(1) forks a single
task, prints, and then exits a loop that will
terminate as soon as it is optimized. So,
as correctly guessed by David, the number of printed lines you see
depends on how soon the compiler optimizes ForkPlay.compute.

You don't see the other tasks output because your
main() terminates upon return of ForkPlay(1).

-Doug


> If you change Integer.MAX_VALUE to 1000, the task is completed correctly.
>
> import jsr166y.*;
>
> public class ForkPlay extends RecursiveAction{
>
>     int myInt;
>
>     public ForkPlay(int i){ myInt = i;}
>
>     public void compute(){
>
>         try{
>
> //            if (myInt > 1000) return;
>
>             (new ForkPlay(myInt+1)).fork();
>
>             System.out.println(myInt);
>
>             int tcount = 0;
>
>             while (tcount < Integer.MAX_VALUE)
>
>                 tcount++;
>
>         }
>
>         catch (Exception e){
>
>             e.printStackTrace();
>
>         }
>
>     }
>
>     static ForkJoinPool pool;
>
>     public static void main(String[] args) throws Exception{
>
>             pool = new ForkJoinPool(7);
>
>             pool.invoke(new ForkPlay(1));
>
>     }
>
> }
>
> If someone has come across the behavior before, could they please share
> a work-around?
>
> If this is indeed a hard limitation on the size of tasks that
> ForkJoinTasks can accomplish, perhaps it should be documented? The
> current documentation speaks of an ideal ForkJoinTask as being between
> 100 and 10000 computations, but does not mention that the framework will
> simply quit with larger tasks.
>
> Note that I’ve tried to extend ForkJoinTask directly as well, and not
> just RecursiveAction.
>
>
> Thanks,
>
> ~Henry
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest@...
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest



_______________________________________________
Concurrency-interest mailing list
Concurrency-interest@...
http://cs.oswego.edu/mailman/listinfo/concurrency-interest