2
0
Fork 0
mirror of https://github.com/MartinThoma/LaTeX-examples.git synced 2025-04-26 06:48:04 +02:00
This commit is contained in:
Martin Thoma 2014-03-28 11:51:59 +01:00
parent 860e3c066b
commit d5ad212703
6 changed files with 67 additions and 4 deletions

View file

@ -1,14 +1,16 @@
// file Fibonacci.x10
public class Fibonacci {
public static def fib(n:Int) {
public static def fib(n:Int): Int {
if (n < 2) {
return n;
}
val f1:Int;
val f2:Int;
f1 = fib(n-1);
f2 = fib(n-2);
finish {
async f1 = fib(n-1);
async f2 = fib(n-2);
}
return f1 + f2;
}
@ -16,7 +18,6 @@ public class Fibonacci {
x10.io.Console.OUT.println("This is fibonacci in X10.");
for (var i:Int=0; i < 10; ++i) {
x10.io.Console.OUT.println(i + ": " + fib(i));
fib(i);
}
}
}

View file

@ -0,0 +1,2 @@
val doubleIt = (i:Int) => i * 2
new Array[Int](5, doubleIt)

View file

@ -0,0 +1,18 @@
// push data on concurrent
// list-stack
val node = new Node(data);
atomic {
node.next = head;
head = node;
}
// target defined in
// enclosing scope
atomic def CAS(old:Object, n:Object) {
if (target.equals(old)) {
target = n;
return true;
}
return false;
}

View file

@ -0,0 +1,2 @@
val r = new Random();
val rand = () => r.nextDouble();