X10 X10 Jonathan Lee Jonathan Lee Daniel Lee Daniel Lee
What is X10? What is X10? Programming language designed for high- Programming language designed for high- performance, high-productivity performance, high-productivity computing on high-end computers computing on high-end computers Development at IBM Research Development at IBM Research Object oriented (OO) Language Object oriented (OO) Language Intended to have simple and clear Intended to have simple and clear semantics semantics
Key Design Decisions Key Design Decisions Introduce a new programming language Introduce a new programming language Use the Java programming language as a Use the Java programming language as a starting point starting point Added a Added a few new things, took away some old few new things, took away some old things things Uses partitioned global address space Uses partitioned global address space (PGAS) model (PGAS) model
Programming Model: Places Programming Model: Places Collection of data objects and activities (think of Collection of data objects and activities (think of as threads) that operate on the data as threads) that operate on the data Can think of as a Can think of as a “ “virtual shared-memory multi- virtual shared-memory multi- processor” ” processor Every X10 activity runs in a place Every X10 activity runs in a place Can get reference to the current place with the Can get reference to the current place with the constant here constant here Places are ordered and the methods Places are ordered and the methods next() and next() and can be used to cycle through them () can be used to cycle through them prev() prev
Programming Model: PGAS Programming Model: PGAS X10 uses PGAS (Partitioned Global X10 uses PGAS (Partitioned Global Address Space) Address Space) Each place has Each place has “ “partition partition” ” of address of address space space Scalar objects are allocated completely at a Scalar objects are allocated completely at a single place single place Elements of an array may be distributed Elements of an array may be distributed across multiple places across multiple places
X10 Activities, Places, PGAS X10 Activities, Places, PGAS Diagram Diagram X10 activities, places, and PGAS
Programming Construct: async async Programming Construct: Can create asynchronous activities using Can create asynchronous activities using async statement statement async async async (P) S (P) S Spawns an activity at the place designated by Spawns an activity at the place designated by P to execute S P to execute S Creates parallelism! Creates parallelism! Can be thought of as extremely Can be thought of as extremely lightweight threads lightweight threads
Async Example Example Async System.out.println println(1); (1); System.out. async (place.next()) { (place.next()) { async System.out.println println(2); (2); System.out. } } System.out.println println(3); (3); System.out.
Data Structures: Region Data Structures: Region Regions: Regions: Just a collection of points Just a collection of points Simple contiguous ranges: [0:N] Simple contiguous ranges: [0:N] Multidimensional blocks: [0:N,0:M] Multidimensional blocks: [0:N,0:M] Can create arbitrary regions of any dimension Can create arbitrary regions of any dimension
Data Structures: Region Data Structures: Region Region Operations: Region Operations: Union: Union: R1 || R2 R1 || R2 Intersection: Intersection: R1 && R2 R1 && R2 Set Difference: Set Difference: R1 - R2 R1 - R2
Data Structures: Distributions Data Structures: Distributions Distributions: Maps Distributions: Maps each point in a region each point in a region to a specific place to a specific place Built in Built in Distributions: Distributions: Constant: Constant: all points map to a single place all points map to a single place Block: contiguous sets of Block: contiguous sets of points equally divided points equally divided among places among places Cyclic: Every Nth point Cyclic: Every Nth point assigned to a place assigned to a place
Data Structures: Distributions Data Structures: Distributions Distribution Operations: Distribution Operations: Also include: Also include: Range Restriction: Range Restriction: D | R D | R Place Restriction: Place Restriction: D | D | P P Indexing for places: Indexing for places: D[p] D[p] Example: Block Star Distribution Example: Block Star Distribution Distribution d = dist.factory.block([0,N],places); Distribution d = dist.factory.block([0,N],places); Distribution blockstar blockstar = [0:-1,0:-1]->here; = [0:-1,0:-1]->here; Distribution for (point p : d) { for (point p : d) { blockstar = = blockstar blockstar || [0:M]->d[i]; || [0:M]->d[i]; blockstar } }
Data Structures: Arrays Data Structures: Arrays X10 Arrays: X10 Arrays: Takes a distribution as a parameter Takes a distribution as a parameter to assign data to to assign data to places places Example: Example: double[.] double[.] data = new double[[0:N]->here]; data = new double[[0:N]->here]; Built in and user defined functions Built in and user defined functions support support Scans Scans Overlays Overlays Reductions Reductions Lifting Lifting Initialization Initialization
Programming Construct: for Programming Construct: for for (point p : R) S for (point p : R) S Pointwise Pointwise for for sequential iteration by a single for for sequential iteration by a single activity activity Equivalent to Equivalent to Java Java foreach foreach loops loops ν Example: Example: ν Region r = [0:N]; [0:N]; Region r = int[.] x = new [.] x = new int int[ [r- r->here]; >here]; int for (point p(i) : r) { p(i) : r) { for (point x[p] = i * 2; i * 2; x[p] = } }
Programming Construct: Programming Construct: foreach foreach foreach foreach (point p : R) S (point p : R) S For parallel iteration in a single place For parallel iteration in a single place for (point p : R) ≡ ν ≡ for (point p : R) async async (here) { S } (here) { S } ν ν Example: Example: ν Region r = [0:N]; [0:N]; Region r = int int[.] x = new [.] x = new int int[ [r- r->here]; >here]; foreach (point (point p(i) : r) { p(i) : r) { foreach x[p] = i * 2; i * 2; x[p] = } }
Programming Construct: ateach ateach Programming Construct: ateach ateach (point p : D) S (point p : D) S For parallel iteration across multiple places For parallel iteration across multiple places for (point p : D) ≡ ν ≡ for (point p : D) async async (D[p]) { S } (D[p]) { S } ν ν Example: Example: ν Distribution d = [0:4]->place(0) || [0:4]->place(0) || Distribution d = [5:9]->place(1); [5:9]->place(1); int[.] x = new [.] x = new int int[d]; [d]; int ateach (point (point p(i) : r) { p(i) : r) { ateach x[p] = i * 2; i * 2; x[p] = } }
Programming Construct: future Programming Construct: future f = future(P) E f = future(P) E Spawns an activity at place P to execute expression E Spawns an activity at place P to execute expression E When When parent activity wants the result of E, it executes parent activity wants the result of E, it executes a f.force() a f.force() Parent activity blocks until the Parent activity blocks until the future activity completes future activity completes ν Example: Example: ν Distribution d = [0:4]->place(0) || Distribution d = [0:4]->place(0) || [5:9]->place(1); [5:9]->place(1); int[.] x = new [.] x = new int int[d] (point (i)) { return [d] (point (i)) { return i; }; i; }; int Future<int int> fx5 = future (place(1)) { > fx5 = future (place(1)) { x[5] }; x[5] }; Future< … … int x5 = fx5.force(); x5 = fx5.force(); int
Synchronization: Clocks Synchronization: Clocks X10 X10’ ’s synchronization mechanism s synchronization mechanism Acts much like a barrier Acts much like a barrier Activities register with a clock Activities register with a clock An activity can perform a An activity can perform a next next operation to operation to indicate that it is ready to advance all the clocks indicate that it is ready to advance all the clocks it is registered with it is registered with When all activities registered with clock perform When all activities registered with clock perform next command, activities on clock can continue continue next command, activities on clock can
Synchronization: finish Synchronization: finish finish S finish S Essentially a join Essentially a join Must block until Must block until all child all child activities recursively activities recursively complete complete Also acts as Also acts as aggregation point for aggregation point for exceptions exceptions
Recommend
More recommend