Ashwin Jayaprakash | 1 Dec 2011 02:00
Picon

Re: Concurrent indexed queue

I realized only today that my attempt at describing my data structure using ascii art was a bad idea. Formatting got messed up. Just for my ref, here's an image of the same:






Wouldn't you need multiple datastructures to have indexed access to a queue?

Perhaps something like this?

1. The simple queue on the left just ensures the insertion order 2. But first you'd have to use a map where the values are a list of nodes. Each node in that list has a certain version of the data 3. Add the node to that list (middle of figure) atomically, then enqueue a pointer to that node into the main queue 4. The consumer will keep reading from the head of the queue, follow the pointer to the versioned node (the list in the middle) 1. It will remove the first versioned node from the list in the middle 2. If there are any other nodes, then it will keep going down that list and toggle those nodes are alreadySeen until it hits the end 5. Obviously it will see this versioned chain again further down the queue. But it now knows that it has already seen it, so it will clear that versioned node 1. It can follow that chain if there are any newer versions (Like Step 4.2)


This would be a really useful datastructure to have as an open source library (hint hint).

_______________________________________________
Concurrency-interest mailing list
Concurrency-interest <at> cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
blue | 1 Dec 2011 11:38
Favicon

Obtain a University Degree based on your professional experience.

AFFORDABLE ONLINE BACHEL0R'S, MASTER'S & DOCT0RATE DEGREES

Add Bache1or's, Master's or Doctorate Degrees to your resume in just a few weeks and open avenues to
promotion and better jobs!

At your Own Pace!
At your Own Schedule!
At your Own Convenience!

No Examination!
No Study!
No Class!

Regardless of your age, sex, marital status, or location, you can receive a degree in your desired field.
All you need is sufficient work, military, or life experience and you are already on your way to an instant
degree in your relevant field.

Earn a recognized University Degree based on work or life experience within weeks!
Get your desired degree on the basis of your Prior Knowledge and Professional Experience.

Give us a call NOW!

1-404-549-4731

Please leave us your:
1) Your Name
3) Phone No. 

We will get back to you ASAP
Mohan Radhakrishnan | 5 Dec 2011 08:01
Picon

Re: Basic question about memory barriers

I think this corresponds to  "8.2.2 Memory Ordering in P6 and
More Recent Processor Families" in Intel® 64 and IA-32 Architectures
Software Developer’s Manual ? They mention fence instructions there.

Thanks,
Mohan

On Mon, Nov 28, 2011 at 3:48 PM, David Holmes <davidcholmes <at> aapt.net.au> wrote:
> Mohan Radhakrishnan writes:
>>      1. Who issues the memory barriers ?
>
> In the context of Java it is the runtime support code of the JVM together
> with the code emitted by the JIT.
>
>>      2. Can I look at memory barriers in machine code ? Is it done by
>> the processor ?
>
> The "barriers" depend on the architecture. They can be explicit
> synchronization instructions; modes applied to loads and stores; or specific
> instruction sequences (eg dependent loads) that produce the desired effect.
> See the Java Memory Model Cookbook for compiler writers to learn more:
>
> http://g.oswego.edu/dl/jmm/cookbook.html
>
> David Holmes
> -----------
>
>>
>> Thanks,
>> Mohan
>> _______________________________________________
>> Concurrency-interest mailing list
>> Concurrency-interest <at> cs.oswego.edu
>> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>>
>
Ruslan Cheremin | 7 Dec 2011 11:57
Picon
Gravatar

AtomicReferenceFieldUpdater - methods set, get, compareAndSet semantics

There is an interesting discussion on stackoverflow
http://stackoverflow.com/questions/8262982/atomicreferencefieldupdater-methods-set-get-compareandset-semantics/
-- about j.u.c.ARFUpdater spec. The confusing part of spec is:

Note that the guarantees of the compareAndSet method in this class are
weaker than in other atomic classes. Because this class cannot ensure
that all uses of the field are appropriate for purposes of atomic
access, it can guarantee atomicity and volatile semantics only with
respect to other invocations of compareAndSet and set.

As one of users supposed, this part of spec is about atomics
implementation on platforms without hardware support for atomic
instructions. So, atomics there must be emulated with locks, and, to
preserve atomicity of CAS-like operations, all accesses must be done
throught ARFUpdater methods, and not via direct field access (for
stores, actually -- direct field loads seems to be OK).

This interpretation seems to be legal and consistent, but nobody can't
find direct authoritive sources, which support such interpretation.
Can somebody clearify the reasoning behind this part of spec?

----
Cheremin Ruslan
David Holmes | 7 Dec 2011 13:00
Picon

Re: AtomicReferenceFieldUpdater - methods set, get, compareAndSet semantics

The user is correct. On implementations that require locks, none of the
field updater classes can guarantee atomicity except with regards to other
methods of the field updater.

In practice I'm only aware of AtomicLongFieldUpdater actually having a
lock-based implementation.

David Holmes
------------

> -----Original Message-----
> From: concurrency-interest-bounces <at> cs.oswego.edu
> [mailto:concurrency-interest-bounces <at> cs.oswego.edu]On Behalf Of Ruslan
> Cheremin
> Sent: Wednesday, 7 December 2011 8:57 PM
> To: concurrency-interest <at> cs.oswego.edu
> Subject: [concurrency-interest] AtomicReferenceFieldUpdater - methods
> set,get, compareAndSet semantics
>
>
> There is an interesting discussion on stackoverflow
> http://stackoverflow.com/questions/8262982/atomicreferencefieldupd
ater-methods-set-get-compareandset-semantics/
-- about j.u.c.ARFUpdater spec. The confusing part of spec is:

Note that the guarantees of the compareAndSet method in this class are
weaker than in other atomic classes. Because this class cannot ensure
that all uses of the field are appropriate for purposes of atomic
access, it can guarantee atomicity and volatile semantics only with
respect to other invocations of compareAndSet and set.

As one of users supposed, this part of spec is about atomics
implementation on platforms without hardware support for atomic
instructions. So, atomics there must be emulated with locks, and, to
preserve atomicity of CAS-like operations, all accesses must be done
throught ARFUpdater methods, and not via direct field access (for
stores, actually -- direct field loads seems to be OK).

This interpretation seems to be legal and consistent, but nobody can't
find direct authoritive sources, which support such interpretation.
Can somebody clearify the reasoning behind this part of spec?

----
Cheremin Ruslan
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest <at> cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Mattias De Wael | 8 Dec 2011 15:29
Picon
Favicon

Java ForkJoin demo applications

Dear

In the paper of Doug Lea "A Java Fork/Join Framework" a battery of demo-apps is used to provide data about the performance of the framework. These demo-applications can be found on Doug Lea's Homepage. 

The demo code, however, is written for what seems to be a early version of the framework (Version 1.3.4 with FJTasks instead of ForkJoinTasks, FJRunnerGroups instead of ForkJoinPool, etc.)
Is anyone aware of an implementation of these demo-applications for the framework in its current state (JDK7), and where I can find them?

Thanks in advance,


Mattias De Wael
Vrije Universiteit Brussel
Faculty of Sciences, DINF - SOFT
Room 10F736, Pleinlaan 2, B-1050 Brussels, Belgium
e-mail: madewael <at> vub.ac.be

_______________________________________________
Concurrency-interest mailing list
Concurrency-interest <at> cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Adrian Tarau | 8 Dec 2011 21:04
Picon
Gravatar

LongAdder in JDK?

There are any plans to include LongAdder in JDK(I searched 
concurrency-interest <at> cs.oswego.edu on MarkMail but I coudn't find an 
answer to my question)? There are some good use cases for this 
structure, like holding a hit ratio? You might use a concurrent map but 
threads will block when updating atomic hits and misses counters, which 
happens in my case(16 threads).

Is this the stable version of the LongAdder? 
http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/jsr166e/?pathrev=MAIN

Thank you,
Adrian Tarau.
Dr Heinz M. Kabutz | 8 Dec 2011 21:23
Picon
Favicon
Gravatar

Re: Java ForkJoin demo applications

Thanks for the pointer, Mattias, I did not know about these demos and was looking for something like this.

I've started translating them to Java 7, in order to figure out how Fork/Join is supposed to work.  Here is my first example, the Fibonacci calculator, which is a silly example as it is O(2^n).  But it's a good one to get to know what you can do with Fork/Join.  In the compute() method, if n is above a threshold, we call invokeAll() on the two new tasks Fib(n-1) and Fib(n-2) and then we join() both results together in the end.  Also in my version I decided to rather not have a volatile shared field that we had in Doug's sample.  We don't need it, since the value is going to be returned from compute() anyway.  The reason it had to be volatile in Doug's sample is that it was set by the forking thread and then updated by the forked thread.  It was later read back again by the forking thread.  In my version it is a lot simpler.

Of course, we all know that fib can be implemented very easily in O(n) using an iterative solution, but that's not the point of this exercise.

import java.util.concurrent.*;

/**
 * Recursive task-based version of Fibonacci. Computes:
 * <pre>
 * Computes fibonacci(n) = fibonacci(n-1) + fibonacci(n-2);  for n> 1
 *          fibonacci(0) = 0;
 *          fibonacci(1) = 1.
 * </pre>
 *
 * Based on Fib.java found on
 * http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/taskDemo/demos.html
 * <at> author Heinz Kabutz
 */

public class Fib extends RecursiveTask<Integer> {
  // Performance-tuning constant:
  private static int sequentialThreshold = 0;
  private final int n;

  public Fib(int n) {
    this.n = n;
  }

  protected Integer compute() {
    if (n <= 1) {
      // fib(0) = 0; fib(1) = 1
      return n;
    } else if (n <= sequentialThreshold) {
      return seqFib(n);
    } else {
      Fib f1 = new Fib(n - 1);
      Fib f2 = new Fib(n - 2);
      invokeAll(f1, f2);
      return f1.join() + f2.join();
    }
  }

  // Sequential version for arguments less than threshold
  static int seqFib(int n) {
    if (n <= 1)
      return n;
    else
      return seqFib(n - 1) + seqFib(n - 2);
  }

  public static void main(String[] args) throws InterruptedException {
    int procs;
    int num;
    try {
      procs = Integer.parseInt(args[0]);
      num = Integer.parseInt(args[1]);
      if (args.length > 2) sequentialThreshold = Integer.parseInt(args[2]);
    } catch (Exception e) {
      System.out.println("Usage: java Fib <threads> <number> [<sequentialThreshold>]");
      return;
    }

    ForkJoinPool pool = new ForkJoinPool(procs);
    Fib f = new Fib(num);
    long time = System.currentTimeMillis();
    int result = pool.invoke(f);
    time = System.currentTimeMillis() - time;
    System.out.println(pool);
    System.out.println("Fib: Size: " + num + " Answer: " + result);
    System.out.println("time = " + time);
  }
}

The output on my 8 core machine, with increasing number of threads and a sequentialThreshold of 20, gives me:

java.util.concurrent.ForkJoinPool <at> 4302a01f[Running, parallelism = 1, size = 1, active = 0, running = 0, steals = 1, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 5920
java.util.concurrent.ForkJoinPool <at> 5999ae9c[Running, parallelism = 2, size = 2, active = 0, running = 0, steals = 5, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 3391
java.util.concurrent.ForkJoinPool <at> 49cda7e7[Running, parallelism = 3, size = 3, active = 0, running = 0, steals = 9, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 2255
java.util.concurrent.ForkJoinPool <at> 5cca548b[Running, parallelism = 4, size = 4, active = 0, running = 0, steals = 9, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1962
java.util.concurrent.ForkJoinPool <at> 6dc8f3cd[Running, parallelism = 5, size = 5, active = 1, running = 1, steals = 25, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1618
java.util.concurrent.ForkJoinPool <at> d38d2fc[Running, parallelism = 6, size = 6, active = 0, running = 0, steals = 34, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1855
java.util.concurrent.ForkJoinPool <at> da3a52c[Running, parallelism = 7, size = 7, active = 0, running = 0, steals = 31, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1485
java.util.concurrent.ForkJoinPool <at> 3f0dbef1[Running, parallelism = 8, size = 8, active = 0, running = 0, steals = 51, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1425
java.util.concurrent.ForkJoinPool <at> c390508[Running, parallelism = 16, size = 16, active = 0, running = 0, steals = 184, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1444
java.util.concurrent.ForkJoinPool <at> fa5e4e4[Running, parallelism = 32, size = 32, active = 0, running = 0, steals = 339, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1449

Regards Heinz -- Dr Heinz M. Kabutz (PhD CompSci) Author of "The Java(tm) Specialists' Newsletter" Sun Java Champion IEEE Certified Software Development Professional http://www.javaspecialists.eu Tel: +30 69 72 850 460 Skype: kabutz

On 12/8/11 4:29 PM, Mattias De Wael wrote:
Dear

In the paper of Doug Lea "A Java Fork/Join Framework" a battery of demo-apps is used to provide data about the performance of the framework. These demo-applications can be found on Doug Lea's Homepage. 

The demo code, however, is written for what seems to be a early version of the framework (Version 1.3.4 with FJTasks instead of ForkJoinTasks, FJRunnerGroups instead of ForkJoinPool, etc.)
Is anyone aware of an implementation of these demo-applications for the framework in its current state (JDK7), and where I can find them?

Thanks in advance,


Mattias De Wael
Vrije Universiteit Brussel
Faculty of Sciences, DINF - SOFT
Room 10F736, Pleinlaan 2, B-1050 Brussels, Belgium
e-mail: madewael <at> vub.ac.be

_______________________________________________ Concurrency-interest mailing list Concurrency-interest <at> cs.oswego.edu http://cs.oswego.edu/mailman/listinfo/concurrency-interest
_______________________________________________
Concurrency-interest mailing list
Concurrency-interest <at> cs.oswego.edu
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Doug Lea | 8 Dec 2011 21:41
Favicon

Re: Java ForkJoin demo applications

On 12/08/11 09:29, Mattias De Wael wrote:

> In the paper of Doug Lea "A Java Fork/Join Framework" a battery of demo-apps is
> used to provide data about the performance of the framework.

Variants of these and others are available in our misc
performance test directory
http://gee.cs.oswego.edu/cgi-bin/viewcvs.cgi/jsr166/src/test/loops/

including: Integrate IntegrateGamma Fib LeftSpineFib DynamicFib
DynamicLeftSpineFib  DynamicAsyncFib ScalarLongSort BoxedLongSort
NQueensCS AsyncNQueensCS FJSums MatrixMultiply LU Microscope
TorusSpanningTree FJJacobi FJPhaserJacobi Heat

See near the bottom of
http://gee.cs.oswego.edu/dl/concurrency-interest/index.html
for  some notes about loops tests.

-Doug
Dr Heinz M. Kabutz | 8 Dec 2011 21:54
Picon
Favicon
Gravatar

Re: Java ForkJoin demo applications

Sorry, the compute() function should have been this:

  protected Integer compute() {
    if (n <= 1) {
      // fib(0) = 0; fib(1) = 1
      return n;
    } else if (n <= sequentialThreshold) {
      return seqFib(n);
    } else {
      Fib f1 = new Fib(n - 1);
      f1.fork();
      Fib f2 = new Fib(n - 2);
      return f2.compute() + f1.join();
    }
  }


Regards Heinz -- Dr Heinz M. Kabutz (PhD CompSci) Author of "The Java(tm) Specialists' Newsletter" Sun Java Champion IEEE Certified Software Development Professional http://www.javaspecialists.eu Tel: +30 69 72 850 460 Skype: kabutz

On 12/8/11 10:23 PM, Dr Heinz M. Kabutz wrote:
Thanks for the pointer, Mattias, I did not know about these demos and was looking for something like this.

I've started translating them to Java 7, in order to figure out how Fork/Join is supposed to work.  Here is my first example, the Fibonacci calculator, which is a silly example as it is O(2^n).  But it's a good one to get to know what you can do with Fork/Join.  In the compute() method, if n is above a threshold, we call invokeAll() on the two new tasks Fib(n-1) and Fib(n-2) and then we join() both results together in the end.  Also in my version I decided to rather not have a volatile shared field that we had in Doug's sample.  We don't need it, since the value is going to be returned from compute() anyway.  The reason it had to be volatile in Doug's sample is that it was set by the forking thread and then updated by the forked thread.  It was later read back again by the forking thread.  In my version it is a lot simpler.

Of course, we all know that fib can be implemented very easily in O(n) using an iterative solution, but that's not the point of this exercise.

import java.util.concurrent.*;

/**
 * Recursive task-based version of Fibonacci. Computes:
 * <pre>
 * Computes fibonacci(n) = fibonacci(n-1) + fibonacci(n-2);  for n> 1
 *          fibonacci(0) = 0;
 *          fibonacci(1) = 1.
 * </pre>
 *
 * Based on Fib.java found on
 * http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/taskDemo/demos.html
 * <at> author Heinz Kabutz
 */

public class Fib extends RecursiveTask<Integer> {
  // Performance-tuning constant:
  private static int sequentialThreshold = 0;
  private final int n;

  public Fib(int n) {
    this.n = n;
  }

  protected Integer compute() {
    if (n <= 1) {
      // fib(0) = 0; fib(1) = 1
      return n;
    } else if (n <= sequentialThreshold) {
      return seqFib(n);
    } else {
      Fib f1 = new Fib(n - 1);
      Fib f2 = new Fib(n - 2);
      invokeAll(f1, f2);
      return f1.join() + f2.join();
    }
  }

  // Sequential version for arguments less than threshold
  static int seqFib(int n) {
    if (n <= 1)
      return n;
    else
      return seqFib(n - 1) + seqFib(n - 2);
  }

  public static void main(String[] args) throws InterruptedException {
    int procs;
    int num;
    try {
      procs = Integer.parseInt(args[0]);
      num = Integer.parseInt(args[1]);
      if (args.length > 2) sequentialThreshold = Integer.parseInt(args[2]);
    } catch (Exception e) {
      System.out.println("Usage: java Fib <threads> <number> [<sequentialThreshold>]");
      return;
    }

    ForkJoinPool pool = new ForkJoinPool(procs);
    Fib f = new Fib(num);
    long time = System.currentTimeMillis();
    int result = pool.invoke(f);
    time = System.currentTimeMillis() - time;
    System.out.println(pool);
    System.out.println("Fib: Size: " + num + " Answer: " + result);
    System.out.println("time = " + time);
  }
}

The output on my 8 core machine, with increasing number of threads and a sequentialThreshold of 20, gives me:

java.util.concurrent.ForkJoinPool <at> 4302a01f[Running, parallelism = 1, size = 1, active = 0, running = 0, steals = 1, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 5920
java.util.concurrent.ForkJoinPool <at> 5999ae9c[Running, parallelism = 2, size = 2, active = 0, running = 0, steals = 5, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 3391
java.util.concurrent.ForkJoinPool <at> 49cda7e7[Running, parallelism = 3, size = 3, active = 0, running = 0, steals = 9, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 2255
java.util.concurrent.ForkJoinPool <at> 5cca548b[Running, parallelism = 4, size = 4, active = 0, running = 0, steals = 9, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1962
java.util.concurrent.ForkJoinPool <at> 6dc8f3cd[Running, parallelism = 5, size = 5, active = 1, running = 1, steals = 25, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1618
java.util.concurrent.ForkJoinPool <at> d38d2fc[Running, parallelism = 6, size = 6, active = 0, running = 0, steals = 34, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1855
java.util.concurrent.ForkJoinPool <at> da3a52c[Running, parallelism = 7, size = 7, active = 0, running = 0, steals = 31, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1485
java.util.concurrent.ForkJoinPool <at> 3f0dbef1[Running, parallelism = 8, size = 8, active = 0, running = 0, steals = 51, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1425
java.util.concurrent.ForkJoinPool <at> c390508[Running, parallelism = 16, size = 16, active = 0, running = 0, steals = 184, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1444
java.util.concurrent.ForkJoinPool <at> fa5e4e4[Running, parallelism = 32, size = 32, active = 0, running = 0, steals = 339, tasks = 0, submissions = 0]
Fib: Size: 45 Answer: 1134903170
time = 1449

Regards Heinz -- Dr Heinz M. Kabutz (PhD CompSci) Author of "The Java(tm) Specialists' Newsletter" Sun Java Champion IEEE Certified Software Development Professional http://www.javaspecialists.eu Tel: +30 69 72 850 460 Skype: kabutz

On 12/8/11 4:29 PM, Mattias De Wael wrote:
Dear

In the paper of Doug Lea "A Java Fork/Join Framework" a battery of demo-apps is used to provide data about the performance of the framework. These demo-applications can be found on Doug Lea's Homepage. 

The demo code, however, is written for what seems to be a early version of the framework (Version 1.3.4 with FJTasks instead of ForkJoinTasks, FJRunnerGroups instead of ForkJoinPool, etc.)
Is anyone aware of an implementation of these demo-applications for the framework in its current state (JDK7), and where I can find them?

Thanks in advance,


Mattias De Wael
Vrije Universiteit Brussel
Faculty of Sciences, DINF - SOFT
Room 10F736, Pleinlaan 2, B-1050 Brussels, Belgium
e-mail: madewael <at> vub.ac.be

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

Gmane