Welcome!

Microsoft Cloud Authors: Janakiram MSV, Yeshim Deniz, David H Deans, Andreas Grabner, Stackify Blog

Related Topics: Microsoft Cloud

Microsoft Cloud: Article

F# on a Virtual Super Computer

Understanding grid computing

With all the hype on the Web about grid computing and scaling out applications, I decided it was time to get my hands dirty.

What's grid computing you ask?

According to Wikipedia, "Grid computing is an emerging model that provides the ability to perform higher throughput computing by taking advantage of many networked computers to model a virtual computer architecture that is able to distribute process execution across a parallel infrastructure."

If you're more confused by that definition, don't worry. It's really just a way of using computing power from a bunch of computers connected to a network.

This, in essence, creates a virtual supercomputer.

At this point, I was searching for a project to work on that could help me understand and use a grid. After attending optionsScalper's presentation on "F# under an Application of Quantitative Finance," I had my answer. F# (say F Sharp) is a .NET meta-programming language developed by the Programming Principles and Tools Group at Microsoft Research in Cambridge, the same group that brought us .NET Generics.

Like OCaml, F# is excellent at writing tools for symbolic programming. Examples of this type of programming include static analysis, compilers, and other sophisticated analyses over structured data terms. Remember using Maple or Matlab? How about Mathematica? That's what writing F# is like. If F# is to be used to analyze various complex problems, then harnessing it to a virtual supercomputer seemed like a logical thing. Slated to learn two new technologies, I was hoping I hadn't bit off more than I could chew.

The Grid
The first thing I wanted to do was find out what was being done with grids in the .NET environment. I was quickly led to the Alchemi open source project at the University of Melbourne. Alchemi was conceived and designed in July 2002 by Akshay Luther while in the penultimate year of his software engineering degree. Now hosted on SourceForge, it looked like a great staring point. After downloading and examining the source (Alchemi-1.0.0-src.zip) I was impressed with how straightforward it was. Alchemi uses two key modules, the manager and the executer. Both can run as a desktop application or a service. The manager takes care of getting the desired process (job) up and running on the grid and ensuring its completion. The executor, on the other hand, is the workhorse of the framework; it runs on the nodes of the grid and does the bulk of the work. (Figure 1)

I started by installing the manager and executor on my development box along with firing up some of the samples that came with Alchemi: the Pi calculator, prime number generator, and fractal generator. All the samples ran perfectly, but only on one machine. Wanting to watch what was happening on the grid, I dug through the documentation and found the Alchemi SDK (Alchemi-1.0.0-sdk.zip), which includes a console application. This application lets you hook into the manager to monitor the grid jobs and their performance. (Figure 2)

I chose the Pi Calculator example to compare performance metrics. First I wanted to see how quickly the job would run with just the one executor on my system. According to the console application I had 3.407GHz available to execute the job, which makes sense on a P4 3.4Ghz system. The result is shown in Figure 3.

The next step was to install the executor on a handful of boxes and see how much faster the samples ran. For starters, I installed the executor on four other machines and watched the available power rise to 11.823GHz...not bad! With all five executors ready to run the Pi Calculator job in parallel, I fired it up and stood back. The time to complete the job fell from 27 seconds to 14 seconds. Impressed with the overall performance and ease of use, I decided to try getting some F# code running on the grid.

The Parallel Problem
One of the problems, or at least concerns, with grid computing is the change in thinking required to develop applications. Typically developers write code using a single thread, only using multithreading when performance is an issue.

For an application to run on a grid, everything has to be written as a thread. Additionally, these threads have to be able to handle pieces of an overall task. For example, say we wanted to create a simple job that counted from 1 to 100 with a one-second delay between each increment. On one machine, using one task this would take 100 seconds. If we broke the job into 10 threads and had each thread count from n to n+10, it would take 10 seconds to complete.

The difficulty is defining the problem in such a way that it can be broken into these parallel tasks.

Historically, problems that can be broken down nicely have been confined to the realm of mathematics and engineering. More recently companies like IBM, HP, Oracle, and Sun are making strides to make grid computing a viable solution in the business environment.

While still not mainstream, awareness, research, and tools like Alchemi can help bring grid computing to the business enterprise environment.

In Alchemi, parallel tasks are defined in the GThread abstract base class. As shown in Listing 1, the developer can, for the most part, design the thread as if it were to run locally.

After examining the Alchemi sample source, it was apparent that I had two roads I could go down: launch the F# as its own job using the classes provided by Alchemi or use C# to write a bootstrapper to load my F# functions. I chose to start with the bootstrapper method because I thought it would be the simplest way to get something working. My approach was to use the Pi calculator sample provided by Alchemi and rewrite the Plouffe-Bellard Pi calculation example in F#.

Fabrice Bellard and Pi
It's important to note that the algorithm I used is an implementation of Fabrice Bellard's 1997 Pi calculation algorithm. Based on the Taylor series, Bellard found Equation 1.

From Equation 1, Bellard used the work of Simon Plouffe and improved the algorithm to produce one whose running time is O(n^2). This work is published in his article "Computation of the n'th digit of pi in any base in O(n^2)." We'll use the algorithm from section 3 of Bellard's paper, Equation 2, as the algorithm for determining n'th digit of p in base B.

Since Bellard's equations are based on the work of Plouffe, I'll refer to them as Plouffe-Bellard for the remainder of this article.

The Plouffe-Bellard Pi calculation example that's provided with Alchemi is in Listing 2.

To get my application running on the Alchemi grid, I needed to:

  1. Build a class that implements a parallel processing algorithm. This is done in the Plouffe-Bellard calculation class.
  2. Create a class that's derived from GThread that uses our algorithm. This is done in the PiCalcGridThread class.
  3. Put the threads on the grid using the Alchemi API. This is done in the PiCalculatorMain class.
In Listing 2, I show what the Plouffe-Bellard calculation class looks like so we can move on to step two. The PiCalcGridThread derives from GThread and is as in Listing 3.

In Listing 3 you can see that the constructor takes the start digit number and the number of digits as arguments. These arguments are the means by which we break the job of calculating Pi into smaller pieces. Putting the PiCalcGridThread class on the grid is done in the PiCalculatorMain class and looks like Listing 4.

In Listing 4, App is an instance of the Alchemi GApplication class. Since the example code provided with Alchemi does a nice job of getting the task up on the grid, we'll use it without modification.

Starting with F#
From this point I wanted to do the Plouffe-Bellard calculation using an F# library. It took me a while to get F# to play nicely in the Alchemi PiCalculator solution, but after I figured it out it boiled down to only a few steps.

  1. Download and install the F# compiler.
  2. Add a new F# project to the PiCalculator example solution.
  3. Set the F# project output to DLL (pb.dll).
  4. Add the files pb.fsi and pb.fs to the F# project.
  5. Include pb.dll, mllib.dll and fslib.dll references in the PiCalculator project.
Next I wanted to get a bit of F# code written that would run on the grid. This was the hardest part of the project since thinking in F# is a bit like speaking in another language. Until you're immersed in it and understand the culture, a lot of things don't make sense.

The pb.fsi file defines the interface to your F# code. This is the mechanism that F# uses to interface to other chunks of code. It's the relatively simple file in Listing 5.


More Stories By Chad Albrecht

Chad Albrecht is president of EnerLinx.com, Inc.

Comments (0)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


@ThingsExpo Stories
In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
@DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
SYS-CON Events announced today that Cedexis will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
SYS-CON Events announced today that Google Cloud has been named “Keynote Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
SYS-CON Events announced today that Opsani will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.
SYS-CON Events announced today that Nirmata will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nirmata provides a comprehensive platform, for deploying, operating, and optimizing containerized applications across clouds, powered by Kubernetes. Nirmata empowers enterprise DevOps teams by fully automating the complex operations and management of application containers and its underlying ...
SYS-CON Events announced today that Opsani to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. Opsani is creating the next generation of automated continuous deployment tools designed specifically for containers. How is continuous deployment different from continuous integration and continuous delivery? CI/CD tools provide build and test. Continuous Deployment is the means by which...