Axum, A Language for Parallel Programming

Axum is Microsoft’s new Language for Safe and Productive Parallel Programming in .NET and is an incubation project developed by Microsoft’s DevLabs. Devlabs defines Axum as follows:

Axum is a language that builds upon the architecture of the Web and principles of isolation, actors, and message-passing to increase application safety, responsiveness, scalability, and developer productivity.

Parallel Programming involves decomposition of a Logic into a number of Parallel tasks, each allowed to run independently. In a Real world Parallel Programming, each Parallel task runs in different independent components and it involves a lot of coordination between the isolated components to accomplish a common goal. Interfacing the components,  their interdependencies often result in Concurrency issues, when each component communicates with each other. To solve these Practical problems, Microsoft has come the new Axum Language, which helps in coordination of different components of a Solution. Axum allows us to model different components, enables interaction with each other and solves the concurrency issues. The delay in terms of processing the inputs in the parallel processing components is greatly reduced which increases the speed of Parallel Programming.

Axum compiler, Axum Language Specification and Axum Programming Guide can be download here. It works in Visual Studio 2008 or Visual Studio 2008 Shell, which is freely downloadable. In this post, let us see how to do a basic Axum Program.

When installed in VS or VS shell, Axum will be available when we create a new Project. Let us create an Axum Console Application.

By default, when a project is created, the Solution explorer will show an Axum file (of extension .ax). Notice the Axum Runtime libraries in the References.

The Program.ax file looks as follows. The Axum Language looks like a C# code. “Agent” is  an actor which communicates with other Actors through messages in Axum world. We can define our own actors and specify how actors should interact with each other.

In Object oriented world, each Object has a state in terms of Properties which can be used by other objects and each object has a behavior in terms of Methods which can be invoked by other objects. Axum does not have either of these qualities. In Axom, similar to an Asynchronous programming model, Agents send messages to other Agents and enable callback for the Response.  Axum can use other .NET libraries from VB.NET, C# or F#.

An Agent accepts the messages sent from other Agents and hence works on input Data, processes Data and Sends output data. Data is received and sent through conduits called Channels. Each Channel has gates called Ports which allows different types of Data. A Channel has two ends similar to two directions of a conduit – One is the Implementing End which a Sender Agent implements and the other is an Using end which a Receiver Agent uses. The Sender Agent sends the messages through the Implementing End of a Channel and the messages are picked up by the Receiving agent through the Using End of the Channel.

When an Agent implements a channel, it is denoted by the “Channel” keyword near the Agent declaration.  This is similar to how classes implement Interfaces in C#. “MainAgent” is the Agent that executes when the Application starts running. By default, the “MainAgent” implements the application channel.

“Primarychannel” is the keyword that denotes the Implementing Channel and “::” is the symbol that indicates the port.

The following code instructs the agent to receive the data through the “CommandLine” port of the Implementing Channel.

The following code indicates the completion of data transfer by sending the data to the Channel’s “Done” port. The Symbol “<—“ is used to send the data to a port.

In this example, “receive” operation is a synchronous operation which makes the Channel to wait for the data in the port, until it arrives. “Send” operation is another operation which is asynchronous as the sender does not wait for the data to be sent to the destination port.

We can implement our own channel to indicate the format of data transfer. The following channel accepts an integer and gives out an integer.

We can implement our own Agent, which inherits the channel. All the operation in an Agent’s constructor take place synchronously. The following agent finds the square of a number.

In this example, we have received the input data from an input channel performed a square operation and returned it to the output Channel.

We can instantiate an Agent by calling “CreateInNewDomain” function.

The following example sends a number to an input port and receives the data from the output port.

Operations in different Agents run in different threads. You can split the logic between multiple agents allowing them to run in Parallel. We have a responsive UI when coordinating the data from different Agents which run in different threads. There is no asynchronous delay or latency time. Agents communicate with each other only through messages. Agents do not share their state with other agent. Agents protect the state within themselves. Thus Concurrency issues are nullified in the Parallel Programming.

In this post, we have seen,

  • What “Axum” is?
  • What is the need for a new Programming language like Axum?
  • How to create a simple Axum program?
  • How to define the Logic in Parallel?
  • How Axum solves Real world Parallel Programming issues?

Resources

  1. Videos
    1. Channel 9 – Building your first Axum Application
    2. MAESTRO – Managed DSL for Concurrent Programming
  2. Blog
    1. Axum Team Blog
  3. Site
    1. Axum in Devlabs