Articles

The X10 Programming Language

X10 is an interesting and relatively new language from IBM being developed as part of [[DARPA]]’s High Productivity Computing Systems program.  X10 is designed for high-performance parallel programming using a [[partitioned global address space]] model.  To my mind, I see X10 as being a modern [[Fortran]] … but perhaps that’s a bit disingenuous.  Anyway, what got me looking at this was the following paper:

Constrained Types for Object-Oriented Languages, N. Nystrom, V. Saraswat, J. Parlsberg and C. Grothoff, OOPSLA, 2008. [DOI] [PDF]

Constrained types (which are a form of dependent type) are quite interesting to me, since Whiley supports something similar.  A simple example from the paper is this:

 class List(length:int}{length >= 0} { ... }

This is a constrained list type whose constraint states that the length cannot be negative.  I find the notation here is a bit curious.  X10 divides fields up into two kinds: properties and normal fields.  The distinction is that properties are immutable values, whilst fields make up the mutable state of an object.  Thus, constraints can only be imposed over the properties of a class.  This implies our constrained list cannot have anything added to it, or removed from it. But,  I suppose we can still change the contents of a given cell.

Constraints can also be given for methods, like so:

def search(value: T, lo: int, hi: int)
 {0 <= lo, lo <= hi, hi < length}: ...

The first question that springs to mind here is: what can we do inside a constraint? Obviously, we’ve already seen properties, parameters and ints being used … but what else?  In particular, can we call impure methods from constraints?  Unfortunately, I don’t have definite answer here.  As far as I can tell, X10 has no strong notion of a [[pure function]].  The spec specifically states that X10 functions are “not mathematical functions”.  On the other hand,  I haven’t seen a single constraint which involves a method invocation, so perhaps you simply can’t call methods/functions from constraints.  Sadly, the spec is rather brief on this point.

An interesting design choice they’ve made with X10 is to rely on “pluggable constraint systems”, which presumably stems from work on “pluggable type systems” (see e.g. this):

The X10 compiler allows programs to extend the semantics of the language with compiler plugins.  Plugins may be used to support different constraint systems.

Now, let’s be clear: i’m not a fan of this.  The problem is really that the meaning of programs is no longer clearly defined, and relies on third-party plugins which may be poorly maintained, or subsequently become unavailable, etc.  I think the problem is compounded by the following:

If constraints cannot be solved, an error is reported

To me, this all translates into the following scenario:

“I download and compile an X10 program, but it fails telling me I need such and such plugin; but, it turns out, such and such author is not maintaining it any more and I can’t find it anywhere.”

I’m assuming here that it will be obvious which plugins you need to compile a given program.  If not, then you’re faced with a real challenge deciding which plugin(s) you need.

Anyway, that’s my 2c on X10 … let’s see how it pans out!!

5 comments to The X10 Programming Language

  • UPDATE: I have been reliably informed that constraints may call “property methods” which are effectively macros that expand inline. Thus, they are not true functions and cannot, for example, recurse.

  • Andrew

    Now, let’s be clear: i’m not a fan of this. The problem is really that the meaning of programs is no longer clearly defined, and relies on third-parties plugins which may be poorly maintained, or subsequently become unavailable, etc.

    So… how is this any different from the current situation with software libraries?

  • Hey Andrew,

    So, I do agree with you here, up to a point. In fact, messing around trying to find libraries when compiling some program is what got me thinking about this.

    Having these plugins as part for the compiler just seems more fundamental to me. But, perhaps people will end up distributing the necessary plugins with their code. And, of course, i’m sure developers would naturally gravitate towards plugins that are well-known, widely used and generally available.

  • Leonid Ilyevsky

    I am in the process of reading the x10 spec, and I have a question about atomic blocks, maybe somebody can explain.

    It says that the atomic block “is executed by an activity as if in a single step during which all other concurrent activities in the same place are blocked”.

    Does it mean that I can never have parallel processing of unrelated pieces of data just because they happen to reside in one place?

    In similar scenario in Java it will be quite different: synchronized blocks can be processed simultaneously if they are using different monitors.

  • Hi Leonid,

    I’m not a expect on X10. However, atomic blocks have been proposed for lots of languages, including Java. The problem with synchronisation is that you have to synchronise on something. Sounds weird, but image you have two array lists and you want to move an item from one to the other, whilst ensuring that no other thread can ever see the intermediate state where the item is in neither. To do this, you have to lock both array lists and the problem is the order in which you do it can lead to deadlock, if other threads are doing something similar.

    Atomic blocks help this situation by ensuring that intermediate state arising during the block is never seen by others. I believe they are a better primitive to use than traditional synchronisation. I would expect that the X10 compiler would allow atomic blocks that cannot interfere with each other to run in parallel. This is probably why the spec says:

    “For the sake of efficient implementation X10 v2.0 requires that the atomic block
    be analyzable, that is, the set of locations that are read and written by the Block-
    Statement are bounded and determined statically.”

    This enables the compiler to figure it all out. The following is a good paper talking about this kind of thing for Java:

    Dave Cunningham, Khilan Gudka, Susan Eisenbach:
    Keep Off the Grass: Locking the Right Path for Atomicity. Proceedings of Compiler Construction, 2008: http://portal.acm.org/citation.cfm?id=1788374.1788399

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>