forked from github-linguist/linguist
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request github-linguist#2589 from mandel/master
Add the X10 language.
- Loading branch information
Showing
22 changed files
with
1,669 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -674,3 +674,6 @@ | |
[submodule "vendor/grammars/sublime-typescript"] | ||
path = vendor/grammars/sublime-typescript | ||
url = https://github.com/Microsoft/TypeScript-Sublime-Plugin | ||
[submodule "vendor/grammars/X10"] | ||
path = vendor/grammars/X10 | ||
url = [email protected]:x10-lang/x10-highlighting.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* This file is part of the X10 project (http://x10-lang.org). | ||
* | ||
* This file is licensed to You under the Eclipse Public License (EPL); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.opensource.org/licenses/eclipse-1.0.php | ||
* | ||
* (C) Copyright IBM Corporation 2006-2014. | ||
*/ | ||
|
||
import x10.io.Console; | ||
|
||
/** | ||
* A simple illustration of loop parallelization within a single place. | ||
*/ | ||
public class ArraySum { | ||
|
||
var sum:Long; | ||
val data:Rail[Long]; | ||
|
||
public def this(n:Long) { | ||
// Create a Rail with n elements (0..(n-1)), all initialized to 1. | ||
data = new Rail[Long](n, 1); | ||
sum = 0; | ||
} | ||
|
||
def sum(a:Rail[Long], start:Long, last:Long) { | ||
var mySum: Long = 0; | ||
for (i in start..(last-1)) { | ||
mySum += a(i); | ||
} | ||
return mySum; | ||
} | ||
|
||
def sum(numThreads:Long) { | ||
val mySize = data.size/numThreads; | ||
finish for (p in 0..(numThreads-1)) async { | ||
val mySum = sum(data, p*mySize, (p+1)*mySize); | ||
// Multiple activities will simultaneously update | ||
// this location -- so use an atomic operation. | ||
atomic sum += mySum; | ||
} | ||
} | ||
|
||
public static def main(args:Rail[String]) { | ||
var size:Long = 5*1000*1000; | ||
if (args.size >=1) | ||
size = Long.parse(args(0)); | ||
|
||
Console.OUT.println("Initializing."); | ||
val a = new ArraySum(size); | ||
val P = [1,2,4]; | ||
|
||
//warmup loop | ||
Console.OUT.println("Warming up."); | ||
for (numThreads in P) | ||
a.sum(numThreads); | ||
|
||
for (numThreads in P) { | ||
Console.OUT.println("Starting with " + numThreads + " threads."); | ||
a.sum=0; | ||
var time: long = - System.nanoTime(); | ||
a.sum(numThreads); | ||
time += System.nanoTime(); | ||
Console.OUT.println("For p=" + numThreads | ||
+ " result: " + a.sum | ||
+ ((size==a.sum)? " ok" : " bad") | ||
+ " (time=" + (time/(1000*1000)) + " ms)"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This file is part of the X10 project (http://x10-lang.org). | ||
* | ||
* This file is licensed to You under the Eclipse Public License (EPL); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.opensource.org/licenses/eclipse-1.0.php | ||
* | ||
* (C) Copyright IBM Corporation 2006-2014. | ||
*/ | ||
|
||
import x10.xrx.Runtime; | ||
|
||
/** | ||
* Demonstrate how to instantiate the X10 runtime as an executor service | ||
* submit jobs to the runtime, wait jobs to complete and cancel all jobs | ||
* | ||
* Compile with: x10c -O -EXECUTOR_MODE=true Cancellation.x10 | ||
* Run with: X10_CANCELLABLE=true X10_NPLACES=4 x10 -DX10RT_IMPL=JavaSockets Cancellation | ||
*/ | ||
class Cancellation { | ||
static def job(id:Long, iterations:Long) = ()=>{ | ||
at (Place.places().next(here)) async { | ||
for (i in 1..iterations) { | ||
finish for (p in Place.places()) { | ||
at (p) async Console.OUT.println(here+" says hello (job " + id + ", iteration " + i + ")"); | ||
} | ||
Console.ERR.println(); | ||
System.sleep(200); | ||
} | ||
} | ||
}; | ||
|
||
public static def main(args:Rail[String]):void { | ||
val w1 = Runtime.submit(job(1, 5)); | ||
w1.await(); Console.ERR.println("Job 1 completed\n"); | ||
val w2 = Runtime.submit(job(2, 1000)); | ||
System.threadSleep(1000); | ||
val c1 = Runtime.cancelAll(); | ||
try { w2.await(); } catch (e:Exception) { Console.ERR.println("Job 2 aborted with exception " + e +"\n"); } | ||
c1.await(); // waiting for cancellation to be processed | ||
System.threadSleep(1000); | ||
Runtime.submit(job(3, 1000)); | ||
Runtime.submit(job(4, 1000)); | ||
System.threadSleep(1000); | ||
val c2 = Runtime.cancelAll(); | ||
c2.await(); | ||
Console.ERR.println("Goodbye\n"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* This file is part of the X10 project (http://x10-lang.org). | ||
* | ||
* This file is licensed to You under the Eclipse Public License (EPL); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.opensource.org/licenses/eclipse-1.0.php | ||
* | ||
* (C) Copyright IBM Corporation 2006-2014. | ||
*/ | ||
|
||
import x10.io.Console; | ||
|
||
/** | ||
* This is a small program to illustrate the use of | ||
* <code>async</code> and <code>finish</code> in a | ||
* prototypical recursive divide-and-conquer algorithm. | ||
* It is obviously not intended to show a efficient way to | ||
* compute Fibonacci numbers in X10.<p> | ||
* | ||
* The heart of the example is the <code>run</code> method, | ||
* which directly embodies the recursive definition of | ||
* <pre> | ||
* fib(n) = fib(n-1)+fib(n-2); | ||
* </pre> | ||
* by using an <code>async</code> to compute <code>fib(n-1)</code> while | ||
* the current activity computes <code>fib(n-2)</code>. A <code>finish</code> | ||
* is used to ensure that both computations are complete before | ||
* their results are added together to compute <code>fib(n)</code> | ||
*/ | ||
public class Fibonacci { | ||
|
||
public static def fib(n:long) { | ||
if (n<=2) return 1; | ||
|
||
val f1:long; | ||
val f2:long; | ||
finish { | ||
async { f1 = fib(n-1); } | ||
f2 = fib(n-2); | ||
} | ||
return f1 + f2; | ||
} | ||
|
||
public static def main(args:Rail[String]) { | ||
val n = (args.size > 0) ? Long.parse(args(0)) : 10; | ||
Console.OUT.println("Computing fib("+n+")"); | ||
val f = fib(n); | ||
Console.OUT.println("fib("+n+") = "+f); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* This file is part of the X10 project (http://x10-lang.org). | ||
* | ||
* This file is licensed to You under the Eclipse Public License (EPL); | ||
* You may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* http://www.opensource.org/licenses/eclipse-1.0.php | ||
* | ||
* (C) Copyright IBM Corporation 2006-2014. | ||
*/ | ||
|
||
import x10.array.*; | ||
import x10.compiler.Foreach; | ||
import x10.compiler.Inline; | ||
|
||
|
||
/** | ||
* This is a sample program illustrating how to use | ||
* X10's array classes. It also illustrates the use | ||
* of foreach to acheive intra-place parallelism. | ||
* | ||
* The program solves a set of 2D partial differential | ||
* equations by iteratively applying a 5-point stencil | ||
* operation until convergence is reached. | ||
*/ | ||
public class HeatTransfer_v0 { | ||
static val EPSILON = 1.0e-5; | ||
|
||
val N:Long; | ||
val A:Array_2[Double]{self!=null}; | ||
val Tmp:Array_2[Double]{self!=null}; | ||
|
||
public def this(size:Long) { | ||
N = size; | ||
A = new Array_2[Double](N+2, N+2); // zero-initialized N+2 * N+2 array of doubles | ||
for (j in 1..N) A(0, j) = 1; // set one border row to 1 | ||
Tmp = new Array_2[Double](A); | ||
} | ||
|
||
final @Inline def stencil(x:Long, y:Long):Double { | ||
return (A(x-1,y) + A(x+1,y) + A(x,y-1) + A(x,y+1)) / 4; | ||
} | ||
|
||
def run() { | ||
val is = new DenseIterationSpace_2(1,1,N,N); | ||
var delta:Double; | ||
do { | ||
// Compute new values, storing in tmp | ||
delta = Foreach.blockReduce(is, | ||
(i:Long, j:Long)=>{ | ||
Tmp(i,j) = stencil(i,j); | ||
// Reduce max element-wise delta (A now holds previous values) | ||
return Math.abs(Tmp(i,j) - A(i,j)); | ||
}, | ||
(a:Double, b:Double)=>Math.max(a,b), 0.0 | ||
); | ||
|
||
// swap backing data of A and Tmp | ||
Array.swap(A, Tmp); | ||
} while (delta > EPSILON); | ||
} | ||
|
||
def prettyPrintResult() { | ||
for (i in 1..N) { | ||
for (j in 1..N) { | ||
Console.OUT.printf("%1.4f ",A(i,j)); | ||
} | ||
Console.OUT.println(); | ||
} | ||
} | ||
|
||
public static def main(args:Rail[String]) { | ||
val n = args.size > 0 ? Long.parse(args(0)) : 8; | ||
Console.OUT.println("HeatTransfer example with N="+n+" and epsilon="+EPSILON); | ||
Console.OUT.println("Initializing data structures"); | ||
val ht = new HeatTransfer_v0(n); | ||
Console.OUT.println("Beginning computation..."); | ||
val start = System.nanoTime(); | ||
ht.run(); | ||
val stop = System.nanoTime(); | ||
Console.OUT.printf("...completed in %1.3f seconds.\n", ((stop-start) as double)/1e9); | ||
if (n <= 10) { | ||
ht.prettyPrintResult(); | ||
} | ||
} | ||
} |
Oops, something went wrong.