In this blog post we’ll introduce Cloud Numerics F# Extensions, a companion post to Microsoft Codename “Cloud Numerics” Lab refresh. Its purpose is to make it easier for you as an F# user to write “Cloud Numerics” applications, and it does so by wrapping “Cloud Numerics” .NET APIs to provide an F# idiomatic user experience that includes array building and manipulation and operator overloads. We’ll go through the steps of setting up the extension as well as a few examples.
The Visual Studio Solution for the extensions is available at the Microsoft Codename “Cloud Numerics” download site.
First, install “Cloud Numerics” on your local computer. If you only intend to work with compiled applications, that completes the setup. For using F# Interactive, a few additional steps are needed to enable fsi.exe for 64-bit use:
In the Programs menu, under Visual Studio Tools, right click Visual Studio x64 Win64 command prompt. Run it as administrator. In the Visual Studio tools command window, specify the following commands:
Open Visual Studio
With Visual Studio 2012 preview, it is possible to use “Cloud Numerics” assemblies locally. However, because the Visual Studio project template is not available for VS 2012 preview, you’ll have to use following procedure to bypass the installation of the template:
Note that this procedure gives the local development experience only; you can work with 64-bit F# Interactive, and build and run your application on your PC. If you have a workstation with multiple CPU cores, you can run a compiled “Cloud Numerics” application in parallel, but deployment to Windows Azure cluster is not available.
To configure your F# project to use “Cloud Numerics” F# extensions:
A simple way to use “Cloud Numerics” libraries from F# Interactive is to copy and send the previous piece of code to F# Interactive. Then, you will be able to use create arrays, call functions, and so forth, for example:
Note that when using F# Interactive, the code executes in serial fashion. However, parallel execution is straightforward as we’ll see next.
To execute your application in parallel on your workstation, build your application, open Visual Studio x64 Win64 Command Prompt, and go to the folder where your application executable is. Then, launch a parallel MPI computation using mpiexec –n <number of processes> <application executable>.
Let’s try the above example in parallel. The application code will look like
You can use the same serial code in parallel case. We then run it using mpiexec to get the result:
Finally, to deploy the application to Azure we’ll re-purpose the “Cloud Numerics” C# Solution template to get to the Deployment Utility:
F# has an elegant syntax for operating on slices of arrays. With “Cloud Numerics” F# Extensions we can apply this syntax to distributed arrays, for example:
We supply operator overloads for matrix multiply as x *@ y and linear solve of a*x=b as let x = a /@ b . Also, operator overloads are available for element-wise operations on arrays:
To enable a more concise syntax, we have added shortened definitions for the array classes as follows:
Finally, we provide several functions for building arrays, for example from F# sequences or by random sampling. They wrap the “Cloud Numerics” .NET APIs to for functional programming experience. The functions are within 4 modules:
These modules include functions for building arrays of specific type, for example:
The “Cloud Numerics” F# Extensions has a folder named “Examples” that holds three example .fs files, including:
The examples are part of a self-contained solution. To run them:
You can also run the examples in the F# interactive, by selecting code (except the module declaration on the first line) and sending it to F# interactive.
This concludes the introduction to “Cloud Numerics” F# Extensions. We welcome your feedback at cnumerics-feedback@microsoft.com.