This post walks through the steps required to use the “Cloud Numerics” distributed numerical and data analytics library from F#. While the “Cloud Numerics” lab focuses on C#, a few additional setup steps enable you to:
Write F# applications that use the “Cloud Numerics” lab libraries.
Use the deployment utility to scale-out your F# application to the Windows Azure cloud.
Because most numerical functions in “Cloud Numerics” are static, calling these methods from F# methods feels natural. For example, consider the following F# source code example:
Before You Begin
Before you begin to write “Cloud Numerics” F# code, complete the instructions in the “Cloud Numerics” Getting Started wiki post to:
- Create an Azure account (if do not have one already)
- Install “Cloud Numerics” on your local computer where you develop your F# applications
- Configure and deploy a cluster in Azure
- Submit the sample C# “Cloud Numerics” program to Azure.
Once you are able to build and run the sample C# application provided with the “Cloud Numerics” project template, you are ready to follow the steps in this post to create an F# “Cloud Numerics” application.
Distributed Numerics with F# on Windows Azure
Step 1: Start Visual Studio and create a new C# Microsoft Cloud Numerics Application project
Step 2: In Visual Studio, in the same solution that you created in the previous Step containing the C# “Cloud Numerics” sample application, create a new F# project.
a. In Solution Explorer, right-click the solution, and choose Add/New Project.
b. In the Add New Project window, choose Visual F# on the left, then choose F# Application in the main panel, ensure “.NET Framework 4” is selected at the top of the window, type a name for the F# project or use the default name, and click OK.
Step 3: Change the target framework to .NET Framework 4. In Solution Explorer, right-click on the new project and choose Properties. On the Application tab, change the Target Framework to .NET Framework 4, and click OK to the warning that appears.
Step 4: Change the project platform to x64. You need to do this because “Cloud Numerics” is an x64 bit only application and F# is x86 by default.
a. In Solution Explorer, right click the solution and choose Properties. Select Configuration Properties in the left-hand panel and click Configuration Manager. Then select x64 from the Active solution platform dropdown.
b. Click the Platform column in the row for your new F# project, and select <New>. Select x64 from the “New Platform” dropdown and click OK. Ensure that the “Create new solution platforms” checkbox is unchecked.
c. Click the Platform column again for your new F# project, and select Edit. Select x86 from the platform list and click the Remove button, then Yes, and then Close.
d. In the Solution Properties window, select the Build checkbox in the row for your new project, and click OK.
Step 5: Now you’ll need to add references to the Cloud Numerics assemblies to your F# project.
a. Right-click your F# project, select References choose Add Reference.
The Add Reference window displays.
b. Click the Browse tab.
In the “Look In” field, choose the bin directory where Cloud Numerics was installed. By default this is C:\Program Files\Microsoft Numerics\v0.1\Bin. If you aren’t sure where it’s installed, you can right-click one of the Microsoft.Numerics assembly references under the sample C# project, choose Properties, and look at the path in the Properties window. Select all of the DLLs that start with “Microsoft.Numerics”, as well as Microsoft.Solver.Foundation.dll, and then click OK.
Step 6: Right-click the FSharp.Core assembly under References in your F# project and choose Properties. In the properties window choose True in the Copy Local field.
Step 7: That’s it. You can now write F# code that uses the “Cloud Numerics” numerical libraries.
a. Copy the F# sample program below and copy it into the Program.fs file in your “Cloud Numerics” project.
b. Build the project
Step 8: Try building and running the F# program locally to verify that it works. Ensure the F# project is set to be the startup project (right-click on the F# project and select Set as Startup Project) and press CRTL+F5 to build and run.
Step 9: To run the F# program on Windows Azure, build and run (CTRL+F5) the AppConfigure project to start the “Cloud Numerics Deployment Utility” you used previously to deploy your C# sample application.
a. In the Application Code tab, click Browse and select the executable for your F# program.
b. Click Submit Job to run it on a Windows Azure cluster. Use the procedures described in the Getting Started wiki post to view the status and standard output of your program on Azure.
You can now run distributed F# applications on Azure!