Pi (π) Calculator

Task 1 – Inspecting the PiCalculator Solution

In this task, you will inspect the PiCalculator solution to see the how the code of the MPI application.

  1. Open Microsoft Visual Studio 2010 from Start | AllPrograms | MicrosoftVisualStudio2010 | Microsoft Visual Studio 2010.
  2. Open the PiCalculator.sln solution file located in the MPI\Source\PiCalculator folder.
  3. Examine the project in the Solution Explorer window. The file that contains the MPI application is named PiCalculator.cpp, as shown in Figure 2:

    Figure 2

    The PiCalculator project tree

  4. Open the PiCalculator.cpp file and examine its contents. The application calculates the value of pi by using the integral formula of 4/(1+x^2), which is broken down using Riemann sums, and calculated in multiple processes using MPI.
  5. Continue examining the application code, you will notice that there are several stages for the MPI application:
    1. Get the number of processes (size) and the id of the current process (rank).
    2. Broadcast the value of the interval to all the processes.
    3. Collect the partial sum from all the processes.
    4. Print the result and terminate the process execution.
    Note:
    For more information on building MPI applications for Windows HPC Server 2008 R2, refer to the Windows HPC Server 2008 - Using MS-MPI white paper.
  6. Change the solution configuration to Release, as shown in Figure 3, and build the solution.

    Figure 3

    Changing solution configuration

Task 2 – Deploy the PiCalculator Application to Windows Azure Worker Nodes

In this task, you will deploy the PiCalculator MPI application to your Windows Azure worker nodes.

  1. Open the command prompt window from Start | All Programs | Accessories | Command Prompt.
  2. Navigate to the MPI labs folder, and run the following command to create a deployment package (this step is illustrated in step 1 of Figure 1):

    CMD

    hpcpack create source\piCalculator.zip source\piCalculator\release\
  3. Run the following command to upload the deployment package to the Windows Azure package storage (this step is illustrated in step 2 of Figure 1):

    CMD

    hpcpack upload source\piCalculator.zip /nodetemplate:"Azure node template" /relativePath:piCalculator
    Note:
     Change the value of the nodetemplate parameter to the name of your Windows Azure node template.
  4. Use the following command to create a c:\app directory on the participating Windows Azure nodes:

    CMD

    clusrun /nodegroup:azurenodes md c:\app\
    Note:
     Change the value of the nodegroup parameter to the name of the group containing your Windows Azure nodes.
  5. Run the following command to deploy the contents of the deployment package to the Windows Azure nodes (this step is illustrated in step 3 of Figure 1):

    CMD

    clusrun /nodegroup:azurenodes hpcsync c:\app
    Note:
     Change the value of the nodegroup parameter to the name of the group containing your Windows Azure nodes.
  6. Run the following command to configure the Windows Azure Firewall to allow MPI communication between the Windows Azure nodes (this step is illustrated in step 4 of Figure 1):

    CMD

    clusrun /nodegroup:azurenodes hpcfwutil register piCalculator c:\app\piCalculator\piCalculator.exe
    Note:
     Change the value of the nodegroup parameter to the name of the group containing your Windows Azure nodes.

Task 3 - Execute the PiCalculator Application and View its Result

In this task, you will use the HPC 2008 R2 Cluster Manager to start a job that executes the PiCalculator MPI application. Once the job is completed, you will be able to see the result in the job information window.

  1. Open the HPC 2008 R2 Cluster Manager application from Start | All Programs | Microsoft HPC Pack 2008 R2 | HPC Cluster Manager.
  2. In the Cluster Manager application, enter the Node Management section and verify that the Windows Azure nodes in the cluster are online, as shown in Figure 4:

    Figure 4

    Verifying the state of the Windows Azure nodes

  3. In the Cluster Manager application, enter the Job Management section and click New Job… in the Actions pane as shown in Figure 5:

    Figure 5

    Create a new job

  4. In the New Job dialog, set the Job name to pi calculator, as shown in Figure 6:

    Figure 6

    Setting the name of the job

  5. Still in the New Job dialog, click the Edit Tasks option, click the arrow next to the Add button, and then click Basic Task …, as shown in Figure 7:

    Figure 7

    New basic task

  6. In the Task Details and I/O Redirection window, set the Task name field to piCalculator, enter mpiexec c:\app\piCalculator\piCalculator 10000000 in the Command Line field, and set the maximum number of resources to be used to 9999, as shown in Figure 8:

    Figure 8

    Creating the MPI task in the job

  7. Click the ResourceSelection option, check the Run this job only on nodes that are members of all the following groups checkbox, and then add a group containing Windows Azure nodes, as shown in Figure 9:

    Figure 9

    Selecting node groups for the job

    Note:
    In your HPC cluster, the name of the Windows Azure node group may differ.
  8. Click the Environment Variables option, click the Add button, and then add an environment variable named CCP_MPI_NETMASK with the value of 0.0.0.0/0.0.0.0, as shown in Figure 10:

    Figure 10

    Adding an environment variable

  9. Click the Submit button to start the job.
  10. Once the job is complete, locate it in the finished jobs list, and view its information.
  11. In the View Job window, click the View Tasks section, and observe the value of pi calculated by the MPI application, as shown in Figure 11:

    Figure 11

    Observing the output of the MPI application

    Note:
    To get a more accurate value of pi, run the job with more iterations. You can change the command line parameter in the basic task from its current value of 10 million to 50 million, 100 million, or even 1 billion iterations.