[concurrency-interest] Strange behaviour when sorting an uniform array

Lukas Krecan lukas.krecan at gmail.com
Tue May 25 03:07:03 EDT 2010


 Hi,
   I have been playing with extra166y library and found that when I try to
sort an uniform array (full of ones) it takes ages. With older version of
the library it even threw StackOverflowError. After update it runs for
minutes (I always kill the process after while so I do not know if it ends
successfully).

Probably it's nothing new for you, maybe it's expected behaviour. But for me
it's confusing and I just wanted to let you know about the issue in case you
were not aware of it.
      Best regards
        Lukas Krecan

-------------------------------------
package net.krecan.forkjoin;

import java.util.Random;

import jsr166y.ForkJoinPool;
import extra166y.Ops;
import extra166y.ParallelLongArray;


public class SortTest {
    private static final int THREADS = 2;
    private static final int SIZE = 40000000;

    public static void testSort()
    {
        ForkJoinPool fjPool = new ForkJoinPool(THREADS);
        ParallelLongArray pa = ParallelLongArray.createEmpty(SIZE, fjPool);
        createData(pa);
        System.out.println("Sorting "+pa.summary());
        long start = System.currentTimeMillis();
        pa.sort();
        System.out.println("Done in
"+(System.currentTimeMillis()-start)+"ms.");
        System.out.println(pa.summary());


    }
    private static void createData(ParallelLongArray pa) {
        long start = System.currentTimeMillis();
        System.out.println("Creating data using "+THREADS+" threads.");
        pa.setLimit(SIZE);
        final Random rand = new Random();
        pa.replaceWithGeneratedValue(new Ops.LongGenerator(){
            public synchronized long op() {
                return 1L;//rand.nextLong();
            }
        });
        System.out.println("Done in
"+(System.currentTimeMillis()-start)+"ms.");
    }

    public static void main(String[] args) {
        testSort();
    }

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20100525/94d80673/attachment.html>


More information about the Concurrency-interest mailing list