Before starting you will need the following:
An Azure account and subscription are required to create cluster virtual machines and Azure Storage accounts.
Azure PowerShell is a set of modules that provide cmdlets to manage Azure with Windows PowerShell. The Azure PowerShell cmdlets are required to run the script used to create and manage the clusters. See " How to install and configure Azure PowerShell " for installation instructions.
MATLAB, Parallel Computing Toolbox, and MATLAB Distributed Computing Server hosted licenses; the cluster configuration assumes that the MathWorks Hosted License Manager is used for all licenses. See http://www.mathworks.com/products/parallel-computing/mathworks-hosted-license-manager/ .
Access to the MATLAB Distributed Computing Server software that will need to be downloaded and then installed on a virtual machine that will be used as a “base” VM image for the clusters.
Copy the mdcs.ps1 file from the scripts folder to a folder on your local computer. If you do not have a GitHub account select the mdscs.ps1 file, then select the "Raw" button, then copy the text and paste it into a local file.
A VM that will be used as the basis for all cluster VMs needs to be created with MATLAB Distributed Computing Server installed.
This process normally only has to be done once; the only reason for it to be repeated would be to cater for new versions of the MATLAB Distributed Computing Server software. In the future we plan to remove or drastically reduce this preparation work.
Create a VM:
Navigate to https://portal.azure.com
On the left hand navigation bar select "New" | “Virtual Machines” | "Windows Server 2012 R2 Datacenter".
Ensure "Resource Manager" is selected in the drop down box and select "Create".
Configure the basic settings:
Set the Name field; the recommendation is to include the MATLAB Distributed Computing Server version; e.g. “mdcsimage2016a”
Pick and note down the user name and password; these will be required to connect to the VM later to install the MATLAB Distributed Computing Server software.
If you do not have an existing resource group you’d like to use, then simply use the same value as the name field; e.g. “mdcsimage2016a”.
Pick a location; this is normally the location that is closest to you and should be the same location where you will want the clusters created.
Select "OK".
Configure VM size:
Settings:
Storage:
Set ‘Disk type’ to “Premium (SSD)”
Select ‘Storage account’, then ‘Create new’
For ‘Name’ enter a unique string; e.g. one that contains your organization name, such as “contosomdcs”
The ‘Type’ is fixed at “Premium-LRS”.
Monitoring:
Leave all other fields at default values; select “OK”.
Summary:
Install MATLAB Distributed Computing Server on the VM:
Login to the VM just created using Remote Desktop; the easiest way to do this is to use the Azure portal:
Navigate to https://portal.azure.com
On the left hand navigation bar select "Virtual machines”
A list of virtual machines will be displayed; select the “. . .” in the last column for the VM (e.g. “mdcsimage2016a”); select “Connect”.
Open the file and enter the username and password you chose when creating the VM to login to the VM.
Download the MATLAB Distributed Computing Server software:
The first time you connect to VM, a Server Manager window will show. Click “Local Server” on the left, and then "IE Enhanced Security Configuration" section, switch the configuration to "Off" for the administrators.
Use Internet Explorer to navigate to the MathWorks web site; download the MATLAB Distributed Computing Server software and install in the default directory on the C drive. Windows 64-bit.
Prepare the VM so it can be used as a base image:
On the VM, open a Windows PowerShell command line window in administrator mode. This can be done by open "Start Menu", type "PowerShell", and right click the item "Run as administrator"
In the command window, type:
& "\$Env:SystemRoot\\system32\\sysprep\\sysprep.exe"
/generalize /oobe /shutdown
When the command has finished, the VM will be shut down and the RDP connection will be closed automatically.
Save the VM image:
Using your local computer, open a Windows PowerShell window in Admin mode run the following commands; the result will be a VHD file saved in the storage account created previously.
# Login - provide your Azure account credentials when prompted
Login-AzureRmAccount
# List all your subscription ids
Get-AzureRmSubscription | ft SubscriptionId
# Pick the subscription you want to use
Set-AzureRmContext -SubscriptionId <subscription id>
# Stop and deallocate the VM, it might take a while
Stop-AzureRmVM
-ResourceGroupName <resource group name>
-name <vm name>
# Set it to generalized format
Set-AzureRmVM
-ResourceGroupName <resource group name>
-name <VM name>
-Generalized
# Save the VM disk as the image for all VMs.
Save-AzureRmVMImage
-ResourceGroupName <resource group name>
-VMName <VM name>
-DestinationContainerName <use the VM name>
-VHDNamePrefix <use the VM name>
Before any of the scripts are used Windows PowerShell must be invoked, you must login, and you must set the subscription you want to use.
# Login - provide your Azure account credentials when prompted
Login-AzureRmAccount
# List all your subscription ids
Get-AzureRmSubscription | ft SubscriptionId
# Pick the subscription you want to use
Set-AzureRmContext -SubscriptionId <subscription id>
# Change to the folder containing mdcs.ps1
cd <folder>
The following PowerShell script enables the creation and management of MATLAB Distributed Computing Server clusters:
.\mdcs.ps1 <command> <command parameters>
The following commands and arguments are provided:
.\mdcs create [<INI configuration filename>]
Creates a cluster using a set of parameters to specify the cluster configuration.
The optional INI file contains cluster configuration parameters to avoid typing in the configuration and to enable easy creation of different configurations by copying the INI file and only modifying what needs to be changed. See below for the format of the INI file.
Note: it is recommended that up to 30 VMs can use one storage account for their disks; if more than 30 VMs are required then additional storage accounts should be created, the “base” VHD copied, and the INI file updated appropriately. It is therefore better to use fewer VM’s with more cores (1 worker per core) than more VM’s with fewer cores.
.\mdcs list
.\mdcs pause <cluster name>
.\mdcs resume <cluster name>
.\mdcs delete <cluster name>
Deletes the specified cluster, shutting down the VMs and deleting the VM disks
NOTE: This includes any data stored in the shared folder on the client node
One way to create a cluster is from Azure portal. Click the following button will bring you to Azure portal UI to deploy MATLAB Distributed Computing Server cluster. Refer to the following section for parameter values.
The easiest way to specify the parameters for cluster creation is by using an INI file; this way the configuration can be reused and different cluster configurations created by simply copying the file and changing only the necessary parameter values.
Multiple clusters can be created; the cluster name has to be different for each one.
Example INI File:
[config]
BaseVmVhd=https://contosomdcs.blob.core.windows.net/system/Microsoft.Compute/Images/mdcsimage2016a/mdcsimage20...
ClusterVmVhdContainer=https://contosomdcs.blob.core.windows.net/mdcs1/
Region=eastus2
ClusterName=mdcs1
ClientVmSize=Standard_DS2
MjsVmSize=Standard_DS2
NumWorkersOnMjsVm=0
WorkerVmSize=Standard_DS4
NumWorkerVms=5
NumWorkersOnWorkerVms=-1
VmUsername=azureuser
SubscriptionId=11111111-2222-3333-4444-555555555555
INI file parameters:
To create the cluster:
Use Azure PowerShell
cd <folder containing the downloaded scripts>
.\\mdcs create <INI file>
Confirm parameters values read from INI file
You will be prompted and need to enter the admin password
The script will block while provisioning the cluster and return when the cluster has been provisioned and is ready for use.
A “client” VM that is used to run the MATLAB client is created for each cluster .
Login to the “client” VM:
On the “Client” VM:
File share:
Copying data to and from the cluster:
A Cluster Profile needs to be created using the MATLAB client:
Invoke the Cluster Profile Manager
Create a Cluster Profile:
Select the “Edit” button to enter the required configuration:
Optionally enter a description
Enter the hostname; this will always be “MASTER”
The name of the MATLAB job scheduler will always be “mymjs”
You must enter the license number for the MATLAB Distributed Computing Server license (configured to use the Mathworks Hosted License Manager)
Select “Done”
Optionally rename the profile
Validate the profile:
Select the “Validate” button on the toolbar and ensure all tests pass
As part of the validation you will likely need to enter your Mathworks account email address and password; select the “Keep me logged on” checkbox.
The script lists the cluster name, number of workers, and the state of the VMs. Running VMs, which are billed, can be distinguished from suspended VMs).
Pausing and Resuming a ClusterPausing a cluster stops the VM’s so they no longer incur compute charges, but the disks are preserved so they will start up in the same state and with their data preserved. For example, any data in the shared folder on the “client” will be preserved. Charges will still be incurred for Azure Storage.
Resuming a cluster starts the VM’s using their previously saved state.
Deleting a ClusterDeleting actually deletes the VM’s and their associated disks; this includes the disk containing the share on the “client” VM.
Resources and Scriptshttps://github.com/Azure/azure-quickstart-templates/tree/master/matlab-cluster
https://docs.microsoft.com/en-us/azure/virtual-machines/windows/matlab-mdcs-cluster
FeedbackWe welcome any feedback on these scripts - bugs, feature requests, etc. Please submit feedback using one of the following mechanisms:
Create an issue on this GitHub repository https://github.com/Azure/azure-quickstart-templates/tree/master/matlab-cluster
Create a post in the Azure Batch MSDN forum .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.