198
HP Distributed R User's Guide Distributed R Software Version: 1.1.x Document Release Date: 6/16/2015

Hp distributed R User Guide

Embed Size (px)

Citation preview

  • HP Distributed R User's Guide

    Distributed R

    Software Version: 1.1.x

    Document Release Date: 6/16/2015

  • Legal Notices

    WarrantyThe only warranties for HP products and services are set forth in the express warranty statements accompanying such products and services. Nothing herein should beconstrued as constituting an additional warranty. HP shall not be liable for technical or editorial errors or omissions contained herein.

    The information contained herein is subject to change without notice.

    Restricted Rights LegendConfidential computer software. Valid license from HP required for possession, use or copying. Consistent with FAR 12.211 and 12.212, Commercial ComputerSoftware, Computer Software Documentation, and Technical Data for Commercial Items are licensed to the U.S. Government under vendor's standard commerciallicense.

    Copyright Notice Copyright 2006 - 2015 Hewlett-Packard Development Company, L.P.

    Trademark NoticesAdobe is a trademark of Adobe Systems Incorporated.

    Microsoft andWindows are U.S. registered trademarks of Microsoft Corporation.

    UNIX is a registered trademark of TheOpenGroup.

    HP Distributed R Page 2 of 198

  • Contents

    Contents 3

    New Features in HP Distributed R Release 1.1.0 8

    About HP Distributed R 11

    Distributed R Architecture 12

    HP Distributed R PackageOverview 13

    Supported Platforms 13

    Hardware Sizing 14

    Network and Firewall Considerations 14

    Co-location with HP Vertica Server 14

    Installing HP Distributed R 15

    Configuring Passwordless SSH and sudo for the Installation User 16

    To configure passwordless sudo: 16

    To configure passwordless SSH: 16

    Using Distributed R With AmazonWeb Services (AWS) 17

    Choose or Create an AWS Instance 17

    Provide Your Public and Private Keys 18

    Provide Your Public Key to anAWSInstance 18

    Install the Distributed R Packages 19

    Installingor Upgrading HP Distributed R on RedHat/CentOS 20

    Installingor Upgrading HP Distributed R on Ubuntu 24

    Cluster Configuration 28

    Adding or Removing Nodes in an HP Distributed R Cluster 29

    To add a node to a HP Distributed R cluster: 29

    To remove a node from aHP Distributed Rcluster: 30

    Uninstalling HP Distributed R 30

    To completely uninstall HP Distributed R: 30

    Using Distributed R With RStudio 30

    Configuring ODBCINI and VERTICAINI Environment Variables for RStudio 31

    DetermineWhether ODBCINI and VERTICAINI Are Configured 31

    HP Distributed R Page 3 of 198

  • Configure the ODBCINI and VERTICAINI Environment Variables in .bashrc 31

    Configure the ODBCINI and VERTICAINI Environment Variables in RStudio 32

    Single Node and Multi Node Operation 33

    Running Distributed R in Single NodeMode in a Distributed R Cluster 33

    Programming Model 34

    Distributed R Data Structures 34

    Parallel Programming 35

    Programming Examples 36

    Getting Started 36

    Creating a Distributed Array 37

    Parallel ProgrammingWith foreach() 38

    Parallel Array Addition 39

    Creating a Distributed Data Frame 40

    Creating a Distributed List 41

    Load and Save Data from Files 42

    Loading from HP Vertica using foreach 43

    Parallel Execution Using Existing R Packages 44

    Examples of Parallelizing Data in Distributed R 45

    Loading and Synthesizing Data 45

    Sequential Execution 45

    Parallel Task Execution 46

    Parallel Data Execution 48

    Distributed R Command Reference 51

    distributedR_start() 51

    distributedR_status() 52

    distributedR_master_info() 53

    distributedR_shutdown() 53

    darray() 54

    Supported Operations 54

    dframe 56

    Supported Operations 56

    HP Distributed R User's GuideContents

    HP Distributed R (1.1.x) Page 4 of 198

  • dlist 58

    getpartition 59

    npartitions 60

    partitionsize() 60

    is.darray 61

    as.darray() 61

    as.dframe() 62

    factor.dframe() 63

    as.factor.dframe() 64

    unfactor.dframe() 65

    levels.dframe() 66

    clone 67

    foreach() 68

    Multiple Splits Inside a foreach Loop 69

    Syntax 69

    Assign Splits to a dobject 69

    Write a List to Pass to splits() 70

    Treatment of Arguments Assigned to a Split or Multiple Splits 71

    Determining Splits with Functions 72

    Complete Split Determined with Function Example 73

    splits() 73

    update 74

    Distributed R Algorithm Packages 75

    About the HPdregression Package 76

    hpdglm Function 77

    HPdregression Examples 77

    About the HPdclassifier Package 84

    hpdRF_parallelTree 84

    hpdRF_parallelTree Example 85

    hpdRF_parallelForest 86

    hpdRF_parallelForest Examples 87

    HP Distributed R User's GuideContents

    HP Distributed R (1.1.x) Page 5 of 198

  • Example 2 89

    confusionMatrix() 90

    errorRate() 90

    meanSquared() 91

    rSquared() 91

    About the HPdcluster Package 93

    hpdkmeans 94

    hpdkmeans Example 96

    Clustering Example 96

    About the HPdgraph Package 98

    hpdpagerank 99

    hpdwhich.max 102

    About the HPdata Package 104

    db2darray 104

    db2darrays 106

    db2dframe 108

    Example: Load a Set of Samples Stored in a Table to a dframe 108

    db2dgraph 109

    Example: Load an Adjacency Matrix to a darray from an Edgelist Stored in aDatabase 109

    db2matrix 110

    Example: Load a Set of Unlabeled Samples Stored in a Table to aMatrix 110

    splitGraphFile 111

    Example: Split an Edgelist file and Distributing Results Among the Active Nodeson a Cluster 111

    file2dgraph 113

    Example: Load an Adjacency Matrix to a darray from an Edgelist Stored in a FileSet 113

    About the HP Distributed R Extensions for HP Vertica Pack 114

    About Installing the HP Distributed R Extensions for HP Vertica Pack 115

    Installing vRODBC 116

    Configuring ODBC/RODBC/vRODBC to Connect to HP Vertica 116

    HP Distributed R User's GuideContents

    HP Distributed R (1.1.x) Page 6 of 198

  • Test vRODBC 118

    About The HP Distributed R Vertica Connector 119

    localhost and the $HOSTNAME variable 119

    R Value Precision Limitations 119

    About Distributed R In-Database Analytics 121

    R Model Management 123

    deploy.model 123

    R_Models 124

    Deleting R Models 125

    In-database R Analytics with GLM 126

    In-database R Analytics with K-means 130

    In-database R Analytics with Random Forest 134

    Detailed In-database Prediction Example 137

    Open Source Software Acknowledgments 148

    R 148

    Protobuf 152

    Rcpp 153

    Rinside 161

    RUnit 165

    data.table 170

    randomForest 178

    R XML 186

    RODBC 186

    Boost 194

    atomicio.cpp 195

    ZeroMQ 196

    pip 196

    We appreciate your feedback! 198

    HP Distributed R User's GuideContents

    HP Distributed R (1.1.x) Page 7 of 198

  • New Features in HP Distributed R Release1.1.0

    This topic briefly describes new features introduced in HP Distributed R 1.1.0.

    l HP Distributed R is now supported on Ubuntu 12.04 LTS and 14.04 LTS (64-bit).

    l Support has been added for external tables for use with the HP Vertica Connector for HPDistributed R and vRODBC. It is now possible to load external tables into HP Distributed Rusing either the HP Vertica Connector for HP Distributed R or vRODBC.

    l Improved Dependency Installer - The dependency installer has been improved and now providesa supported version of R in the package. Previously the dependency installer downloaded thelatest version of R available from theOS platform repository. Additionally, all pythondependencies and someOS dependencies are now included in the package and do not have tobe downloaded by the dependency installer.

    l A new randomForest implementation called hpdRF_parallelTree() has been introduced withbetter performance for large datasets. The original hpdrandomForest() implementation has beenrenamed to hpdRF_parallelForest(). Additionally the new implementation has been aliased to thehpdrandomForest() function call, so your existing scripts now use the new implementationautomatically. If you prefer to use the old hpdrandomForest() functionality then renamehpdrandomForest() to hpdRF_parallelForest() in your scripts.

    l New functions for handling factors in distributed data frames have been added:n factor.dframe() - factor logical, character, and factor columns in a dframe in place.

    n as.factor.dframe() - return a new dframewith factored logical/character/factor columns.

    n unfactor.dframe() - convert logical/character/factor columns to character in a dframe in place.

    n levels.dframe() - return an array of levels of logical/character/factor columns for a dframe.

    l A new as.dframe() function has been added that creates distributed data frames from regular Rdata.frames.

    l New functionality has been added to the splits() function.

    n foreach statements now support multiple splits.List and vector-based arguments may now bepassed into the splits() function.

    n The determination of which splits to send to each execution task can now be computed via thesplits() function.

    HP Distributed R User's GuideNew Features in HP Distributed R Release 1.1.0

    HP Distributed R (1.1.x) Page 8 of 198

  • l New functions are available to find accuracy metrics for classificationmodels:n confusionMatrix() - generate aconfusionmatrix for a given predictivemodel and a test data.

    n errorRate() - calculate the total error rate and error rates of each class for a given predictivemodel and a test data.

    n meanSquared() - calculate mean squared residuals for a given regressionmodel and a testdata.

    n rSquared() - calculate R-squared (1 - mse / Var(y)) for a given regressionmodel and a testdata.

    l The deploy.model() function has been improved and can accept HP Distributed R modelswhether completedModel = true or completedModel = false.

    HP Distributed R User's GuideNew Features in HP Distributed R Release 1.1.0

    HP Distributed R (1.1.x) Page 9 of 198

  • Page 10 of 198HP Distributed R (1.1.x)

    HP Distributed R User's GuideNew Features in HP Distributed R Release 1.1.0

  • About HP Distributed RHP Distributed R is a high-performance scalable platform for the R language. It enables R toleveragemultiple cores andmultiple servers to perform Big Data Advanced Analytics. It consists ofnew R language constructs to easily parallelize algorithms across multiple R processes.

    HP Distributed R simplifies large-scale analysis by extending R. Because R is a single-threadedenvironment, it has limited utility for Big Data analytics. HP Distributed R allows you to specify thatparts of programs be run inmultiple single-threaded R-processes. This approach results insignificantly reduced execution times for Big Data analysis.

    HP Distributed R follows R language design principles and extends existing R constructs tosupport distributed computing so that R developers can immediately start using HP Distributed Rwith no additional training.

    You should use HP Distributed R when you have performance and scalability issues with R. HPDistributed R allows you to overcome the scalability and performance limitations of R to analyzevery large data sets. HP Distributed R provides the ability to run an analysis on the complete dataset for when you want to use all the data, and not just the sample.

    Many applications need to perform advanced analytics such as machine learning, graphprocessing, and statistical analysis on large amounts of data. While R has many advancedanalytics packages, the single-threaded nature of R limits use of these packages on Big Data. HPDistributed R extends R in two ways:

    l Distributed data. HP Distributed R stores data across servers andmanages distributedcomputation. If you are a data scientist, you can run your programs on very large data sets (suchas terabytes) by simply addingmore servers.

    l Parallel execution. If you are a programmer, you can use HP Distributed R to implement codethat runs in parallel. You can leverage a single multi-coremachine or a cluster of machines toobtain dramatic improvement in application performance.

    HP Distributed R provides distributed data-structures to store in-memory data across multiplemachines including:

    l Distributed arrays (darray)Use distributed arrays whenever data contains only numericvalues.

    l Distributed data frames (dframe)Use distributed data frames for data that contains bothnumeric and non-numeric data or only contains non-numeric data.

    l Distributed lists (dlist)Use distributed lists to store complex objects, such as R models.

    You can partition these data structures by rows, columns, or blocks and also specify the size of theinitial partitions.

    As a programmer, you can express parallel processing in HP Distributed R using foreach loops.Such loops execute a function in parallel onmultiple machines. You pass parts of the distributeddata to these functions. The HP Distributed R runtime intelligently schedules functions on remotemachines to reduce datamovement.

    HP Distributed R User's GuideAbout HP Distributed R

    HP Distributed R (1.1.x) Page 11 of 198

  • In addition to the language constructs already mentioned, HP Distributed R has other helperfunctions. For example, distributedR_start starts the HP Distributed R runtime on a cluster.You can find information about all the functions provided by the HP Distributed R library R by typing?distributedR at the R prompt. You can also access this information using the help() commandin the R console.

    HP Distributed R also comes packaged with several popular algorithms that have been extended towork with the new Distributed R data types and can scale and perform on large datasets. See HPDistributed R PackageOverview.

    Distributed R ArchitectureBefore explaining the Distributed R programmingmodel, it is important to understand the systemarchitecture. Distributed R comprises a single master process andmultiple workers. Logically,each worker resides on one server. Themaster controls each worker and can be co-located with aworker or be on a separate server. Each worker manages multiple local R instances. The figurebelow shows an example cluster setup with two servers. Themaster process runs on Server Awhile the workers run on servers A and B. Each worker has three R instances. You can set up theworkers to usemore or fewer R instances.

    For programmers, themaster is the R instance configure to be themaster node and on whichDistributed R is loaded using the library(distributedR) command. Themaster starts theprogram and is in charge of overall execution. Parts of the program correspond to parallel sections,such as foreach. These parallel processes are executed by the workers. Distributed datastructures, such as darray and dframe, contain data that is stored across workers. The DistributedR API provides commands tomove data between workers as well as betweenmaster and workers.You do not need to know onwhich worker the data resides, as the runtime hides the complexity ofdatamovement.

    HP Distributed R User's GuideAbout HP Distributed R

    HP Distributed R (1.1.x) Page 12 of 198

  • HP Distributed R Package OverviewHP Distributed R provides several algorithm packages that have been created specifically to workin the distributed computing platform of HP Distributed R. HP Distributed R packages are loadedthe same as typical R package libraries using the library() command. HP Distributed Rpackages can be loaded with other R packages. Currently, HP Distributed R provided these Rlibrary packages:

    l HPdata - The Distributed Data Packages, provides functions for loading data into distributeddata objects from databases and files.

    l HPdclassifier - The Distributed algorithms for classifiers package. It contains thehpdandomForest() function, which is a distributed version of randomForest, and an associatedpredict function, predictHPdRF(). Note that while randomForest is popular for classification, itcan also be used for regression and unsupervised learning.

    l HPdcluster - The Distributed clustering for BigData package. It contains the hpdkmeans()function, which is a distributed kmeans algorithm. It also contains hpdapply(), a distributedversion of the apply function.

    l HPdgraph - The Distributed algorithms for graph analytics package. It contains the hpdpagerank() function, which is a distributed pagrerank algorithm. It also contains the hpdwhich.max()function, which acts as a which.max function on darrays.

    l HPdregression - The Distributed Regression for Big Data package. It contains the hpdglm()function, which is a distributed glm function that performs regression analysis on distributed datatypes. It also contains v.hpdglm() and cv.hpdglm() which are functions used to evaluatemodelsusing split-sample and cross-validation respectively.

    More details about these packages can be found in the package help files from within R. Forexample help(HPdata) or ?hpdata after using the library(HPdata) command. Examples foreach of the functions are available in this guide and you can access them by clicking the packagename above.

    Supported PlatformsHP Distributed R Release 1.1.x is supported on the following software platforms:

    l RedHat Enterprise Linux 6.x (x86-64)

    l 64-bit CentOS 6.x (x86- 64)

    l Ubuntu 12.04 LTS and 14.04 LTS (64-bit)

    R VersionHP Distributed R is tested and supported on R version 3.1.3. However, HP Distributed R can runon R version 3.0 or greater. HP Distributed R can not run on R version prior to 3.0.

    HP Distributed R User's GuideAbout HP Distributed R

    HP Distributed R (1.1.x) Page 13 of 198

  • ODBC VersionunixODBC version 2.2.14 or greater is required on all nodes if you want to use RODBC, vRODBC,or the HP Vertica Connector.

    Hardware SizingYou can run HP Distributed R on commodity hardware. In total, you need enough total memory tohold all of the data you want to analyze, along with a buffer for R bookkeeping. The Distributed RAlgorithm Packages section contains details on all of the HP Vertica distributed algorithmpackages as well as memory estimation formulas for each package. In general, ff you havehardware with morememory, you will need fewer total nodes to do the analysis. HP Verticarecommends a stand- alone cluster of HP DL380s.

    You need enough servers so that your largest data set fits into the total memory of your servers,along with a buffer for bookkeeping by R. If you need your answer faster, you need to usemoreCPU cores.

    Details onmemory requirements for algorithms in the Distributed R packages are provided in thisguide in each package's respective section.

    Hardware configuration suggestions are available in the guide: Configuring the HP DL380pGen825-SFF CTOServer as a HP Distributed R Node at http://www.vertica.com/resources-for-configuring-hardware-and-virtual-machines/.

    Network and Firewall ConsiderationsDistributed R performs best when all nodes are on the same subnet and have the same broadcastaddress for one or more interfaces. A cluster that has nodes onmore than one subnet canexperience lower performance due to the network latency associated with amulti-subnet system athigh network utilization levels.

    Distributed R requires SSH communications between the nodes. Distributed R also requires aconfigurable port range be open between the nodes. By default, Distributed R uses ports from50000 to 50100. You can change the port range in the cluster configuration file. See ClusterConfiguration for details.

    Youmust open ports on your firewall for SSH(port 22) and the port range configured formaster/worker communication (50000 - 50100 by default).

    Co-location with HP Vertica ServerDistributed R 1.1.x is not supported for co-location with HP Vertica server. Distributed R nodes andHP Vertica server nodes must be on different servers.

    HP Distributed R User's GuideAbout HP Distributed R

    HP Distributed R (1.1.x) Page 14 of 198

    http://www.vertica.com/resources-for-configuring-hardware-and-virtual-machines/http://www.vertica.com/resources-for-configuring-hardware-and-virtual-machines/

  • Installing HP Distributed RA video tutorial for installing HPDistributed R is available on the HPVertica website.

    The HP Distributed R installer installs HP Distributed R and configures the XML configuration fileson every node in your cluster.

    Before you install, see Configuring Passwordless SSH and sudo for the Installation User. This stepis necessary so that the node on which you are running the installer can access the other nodesover SSH without using a password, and the user installing HP Distributed R has passwordlesssudo privileges on all nodes in the cluster.

    Once you have completed this pre-installation step on each node in the cluster, you can run the HPDistributed R on your platform.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 15 of 198

    https://community.dev.hp.com/t5/Vertica-Blog/HP-Distributed-R-Installation-Tutorial/ba-p/227834

  • Configuring Passwordless SSH and sudo for theInstallation User

    The Distributed R installer calls sudo to install Distributed R packages on each node and uses SSHto communicate between themaster and worker nodes. Passwordless SSH and sudomust beenabled for the installation user during the Distributed R install. After installation is complete youcan disable passwordless sudo for the installation user.

    Important: The installation usernamemust exist on all nodes in the cluster and youmustgive the installation user passwordless ssh and sudo access on all nodes in the HPDistributed R cluster.

    Note: Youmust enable passwordless SSH and sudo even if you are doing a single-nodelocalhost install.

    To configure passwordless sudo:1. Youmust enable passwordless sudo on each node. Edit /etc/sudoers and add the following

    line at the end of the file (replace usernamewith the appropriate username:

    username ALL=(ALL) NOPASSWD:ALL

    Note: You can remove the entry in sudoers after installation completes.

    2. Verify that the installation user can run sudo without a password. For example, as theinstallation user, run: sudo touch example.txt. You should not be prompted for a password.

    If you are deploying on AWS, then see Using Distributed R With AmazonWeb Services (AWS)instead of completing the next procedure.

    To configure passwordless SSH:If you are using Ubuntu, then your install may not includeOpenSSH Server. InstallOpenSSHserver on Ubuntu with the command: sudo apt-get install openssh-server.

    1. Create public and private SSH keys that do not have a pass phrase by using the ssh-keygenutility.

    n If your current ~/.ssh/id_rsa keys do not have a pass phrase and you want to use them forpasswordless SSH on all Distributed R nodes, then skip this step. Otherwise create newSSH keys for the installation user (the same username for which you granted passwordless

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 16 of 198

  • sudo in the previous section).

    n Do not create the keys as root or using sudo. You can optionally provide a file name for thekey files or accept the default id_rsa file name.

    n Do not enter text when prompted for a pass phrase. Simply press ENTER twice. Forexample:

    # ssh-keygenGenerating public/private rsa key pair.Enter file in which to save the key (/home/user/.ssh/id_rsa):Enter passphrase (empty for no passphrase):Enter same passphrase again:Your identification has been saved in /home/user/.ssh/id_rsa.Your public key has been saved in /home/user/.ssh/id_rsa.pub.

    2. Once you have created the SSH keys, use ssh-copy-id to copy the public key to each node inthe Distributed R cluster, including localhost. If you created the SSH keys with the default filename then simply specify the server to which you want to copy the key. Provide yourpassword each time you copy an ID. For example:

    ssh-copy-id localhostuser@localhosts's password:ssh-copy-id [email protected]'s password:ssh-copy-id [email protected]'s password:

    Using Distributed R With Amazon Web Services (AWS)Perform the following steps to install HP Distributed R on AWS:

    1. Choose or Create an AWS Instance.

    2. Provide Your Public and Private Keys.

    3. Install the Distributed R Packages.

    Choose or Create an AWS InstanceYour AWS instancemust meet the following requirements:

    l Your AmazonMachine Image (AMI) must be based on a supported operating system. For a listof supported operating systems, see Supported Platforms.

    l Your Security Groupmust have open ports corresponding to the ports specified in your cluster_conf.xml file and in your Linux kernel firewall (iptables). See Supported Platforms.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 17 of 198

  • For optimal performance onmultiple nodes, Hewlett-Packard recommends that you specify aNetwork type of VPC.

    Provide Your Public and Private KeysYour AWS instances must be able to log in to each other without being prompted for a password. Todo so, youmust provide both your private and public key to each of your instances.

    Provide Your Private Key to an AWSInstance

    When running Distributed R across multiple instances, those instances require the ability to log into each other without user interaction. You can enable this interaction by placing a copy of yourAWS private key on each instance. You can download a copy of this key from AWS. These stepsreplace the sectionPasswordless SSH in the installation steps.

    1. Rename your private key .pem file to id_rsa.

    2. Connect to your AWS instance.

    3. On the AWS instance, copy id_rsa to the directory /.ssh. The instance accepts the private keyand can now connect to other nodes in the cluster without a password.

    Provide Your Public Key to anAWSInstance

    Youmust also generate and copy the public key to each instance in your cluster.

    1. Log in to an instance where your private .pem key is located.

    2. Run the ssh-keygen command:

    $ ssh-keygen -y

    3. You are prompted to enter the location of the .pem file. Enter the file's path.

    Enter file in which the key is (/home/dbadmin/.ssh/id_rsa):

    4. A public key is returned that looks similar to the following:

    ssh-rsaAAAAB3NzaC1yc2EAAAADAQABAAABAQCz6vgtVx7GG00oJSC5zNi+BkT7bjtz9uV6ZH18dxY7iUcOf8esm

    sj32URnqPT1mJuF0F+bZkIW+KDcZnQTBckzLF5mJvSp1mk2jh66fBIbz/MuUzPnh/2KN8YP0Wy/y8abCSiITqhlzw6tOQ4gnYB0pvYal6lrWq0izIPeStSj9snUqKhM/iSttxKmE5s6W7M/2Buou

    +L3uQ13ub+x4GFRocAoythqA2C8GpFg0f4PGZOXIdvWFdO9VW2DImcZpMB2Pf6kXDUwcrqI/c64BmR5DCxxK9wTprwFU/VoQf5UIUuL3ab7D+EcFU1S3zLrbS8pP

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 18 of 198

  • 5. Copy the full public key, create a new file called id_rsa.pub, and then paste the public keyinto id_rsa.pub, using a text editor of your choice. For example:

    $ vim id_rsa.pub

    The new file, id_rsa.pub opens. Paste the full public key into the file.

    6. Copy and paste the contents of id_rsa.pub into the file .ssh/authorized_keys on eachinstance in your cluster.

    Install the Distributed R PackagesOnce you have configured your private and public keys, install the required dependencies, theninstall Distributed R using the installation steps for your OS.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 19 of 198

  • Installingor Upgrading HP Distributed R onRedHat/CentOS

    The HP Distributed R installer is packaged as a gzipped tar file. To install HP Distributed R onRedHat/CentOS youmust use the installer package that is specific to RedHat/CentOS systems.The package is named hp-distributedR-[VERSION].RHEL6.tar.gz, where [VERSION] is theversion number of HP Distributed R. For example: hp-distributedR-1.1.0-0.RHEL6.tar.gz.

    Note: The steps for Installing or Upgrading are the same. Upgrades overwrite the previousversion of HP Distributed R.

    1. Verify that you have given your installation user passwordless ssh and sudo privileges on allnodes in the HP Distributed R cluster. See Configuring Passwordless SSH and sudo for theInstallation User.

    2. On each node, if selinux is enabled then set selinux to be in permissive or disabledmode:

    a. As sudo, edit /etc/selinux/config and change the line: SELINUX=enforcing toSELINUX=permissive or SELINUX=disabled then save and exit the file.

    b. If you set it to permissive, then run: sudo setenforce Permissive

    c. If you set it to disabled, then run: sudo setenforce 0

    3. Download the installation package to themaster node and unzip the package with thecommand:

    tar zxvf hp-distributedR-[VERSION].RHEL6.tar.gz

    4. Change directory into the newly extracted directory:

    cd hp-distributedR-[VERSION]

    5. Run the dependency installer located in the helper directory to install all required dependencies.The dependency installer takes as arguments the hostname or IP Address of each node in theHP Distributed R cluster. This automatically installs the dependencies on each specified node.For example:

    ./helpers/distributedR_install_dependencies NodeA NodeB NodeC

    The installer attempts to detect if you are behind a proxy and use the appropriate proxysettings. However, If you are behind a proxy you can add the arguments --http-proxy and --

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 20 of 198

  • https-proxy. Run ./helpers/distributedR_install_dependencies --help for details onusage.

    6. If any R package dependencies aremissing then you are prompted to install them. AnswerY(or press enter) to install all of the required R packages.

    7. If the dependency installer is successful then skip this step and go to the next numbered stepand run the installer. If the dependency installer fails then complete this step.

    Youmust manually install dependencies using the following sub-steps. Youmust do this oneach node in the cluster if the dependency installer fails.a. Run the following commands to install OS dependencies. If you are behind a proxy then

    youmust configure rpm and yum to use a proxy server.

    sudo rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpmsudo yum install gcc R libxml2 libxml2-devel unixODBC unixODBC-devel libselinux-python \python-devel python-pip

    b. Next, youmust install python dependencies. If you are behind a proxy run the followingcommands to allow PIP to use a proxy server, replace proxy:portwith your proxyinformation:

    export http_proxy=http://proxy:portexport https_proxy=https://proxy:port

    c. Use PIP to install required Python libraries.

    sudo -E pip install jinja2sudo -E pip install PyYamlsudo -E pip install httplib2sudo -E pip install paramikosudo -E pip install setuptools

    d. Start R as sudo to install required R libraries:

    sudo R

    Run the following in R:

    install.packages(c("RInside", "Rcpp", "XML", "RUnit", "data.table","randomForest"))

    Select a CRAN mirror from the list and allow R to install the required libraries.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 21 of 198

    http://www.rpm.org/max-rpm/rpm.8.htmlhttps://www.centos.org/docs/5/html/yum/sn-yum-proxy-server.html

  • Exit R:

    quit()

    8. Run the installer:

    a. The Distributed R installer checks dependencies and installs and configures Distributed Ron all nodes in your cluster. It first copies the required files to /opt/hp/distributedR andthen configures the XML configuration files in /opt/hp/distributedR/conf.

    Note: The installer makes the following changes to each node:

    o Changes the size of /dev/shm to 100% of freememory (obtained by running free().

    o Sets shmall and shmmax to 90% of total memory.

    o Sets shmmi to 500000.

    o Sets max open files (/proc/sys/fs/file-max) to 524288.

    Run the installer by specifying any options and the node(s) on which to install HPDistributed R:

    ./distributedR_install [OPTIONS] [NODES]

    Options:

    o -h or --help: Print help and Exit

    o -cor --check-cluster-connectivity: Check connectivity between the nodes andexit.

    o -y or --yes-to-all: Answer yes to all prompts (useful for non-interactive installs).

    Nodes: The host name or IP address of each node in the cluster. Specify all nodesregardless of which is themaster. You define themaster node in the next step.

    Example:

    ./distributedR_install node1 node2 node3

    b. Follow the installer's guided installation process to configure your system.

    The installer prompts you with these questions:

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 22 of 198

  • i. Which node is the master? - Specify which node is themaster node by specifyingthe number of the node to act as master.

    ii. Which node(s) is/are the workers? - Specify which nodes are workers by selectingthe appropriate number or specifying a comma-separated list of workers.

    iii. Do you want to specify custom port ranges? - You can specify the port rangesover which themaster and worker nodes pass data. By default the range is ports50000 to 50100. If you answer yes then you are prompted for the port ranges to use.

    iv. Do you want to install Vertica ODBC support? - If yes, then the libraries requiredfor HP Vertica ODBC connections are installed to /opt/hp/odbc and the VRODBCR package is installed. However, youmust still manually configure ODBC properties.

    v. Do you want to run a test to make sure the Distributed R installation is OK? -If yes, some basic tests are run to verify the Distributed R install.

    c. Youmust exit the terminal session in which you installed Distributed R and log back in sosystem changes that the installer made can take effect. Distributed R changes limits forthe amount of open file handles and sharedmemory. These changes do not take effect inthe current session or any currently open sessions. Start Distributed R in a new session.

    d. The installation process automatically creates the cluster configuration file for your clusterand places it in /opt/hp/distributedR/conf/cluster_conf.xml on themaster node.See Cluster Configuration for details onmodifying the configuration.

    e. If you are going to connect Distributed R to a database, then configure ODBC. SeeConfiguring ODBC/RODBC/vRODBC to Connect to HP Vertica.

    f. Finally, if you are using the Distributed R Vertica Extensions, then install the extensionspack on your HP Vertica Cluster. See About Installing the HP Distributed R Extensions forHP Vertica Pack.

    HP Distributed R is now installed in /opt/hp/distributedR.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 23 of 198

  • Installingor Upgrading HP Distributed R on UbuntuThe HP Distributed R installer is packaged as a gzipped tar file. To install HP Distributed R on anUbuntu system youmust use the installer package that is specific to Debian/Ubuntu systems. Thepackage is named hp-distributedR-[VERSION].DEBIAN7.tar.gz, where [VERSION] is theversion number of HP Distributed R. For example: hp-distributedR-1.1.0-0.DEBIAN7.tar.gz.

    Note: The steps for Installing or Upgrading are the same. Upgrades overwrite the previousversion of HP Distributed R.

    1. Verify that you have given your installation user passwordless ssh and sudo privileges on allnodes in the HP Distributed R cluster. See Configuring Passwordless SSH and sudo for theInstallation User.

    2. Download the installation package to themaster node and unzip the package with thecommand:

    tar zxvf hp-distributedR-[VERSION].DEBIAN7.tar.gz

    3. Change directory into the newly extracted directory:

    cd hp-distributedR-[VERSION]

    4. Run the dependency installer located in the helper directory to install all required dependencies.The dependency installer takes as arguments the hostname or IP Address of each node in theHP Distributed R cluster. This automatically installs the dependencies on each specified node.For example:

    ./helpers/distributedR_install_dependencies NodeA NodeB NodeC

    The installer attempts to detect if you are behind a proxy and use the appropriate proxysettings. However, If you are behind a proxy you can add the arguments --http-proxy and --https-proxy. Run ./helpers/distributedR_install_dependencies --help for details onusage.

    5. If any R package dependencies aremissing then you are prompted to install them. AnswerY(or press enter) to install all of the required R packages.

    6. If the dependency installer is successful then skip this step and go to the next numbered stepand run the installer. If the dependency installer fails then complete this step.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 24 of 198

  • Youmust manually install dependencies using the following sub-steps. Youmust do this oneach node in the cluster if the dependency installer fails.a. Run the following commands to install OS dependencies. If you are behind a proxy then

    youmust configure apt-get to use a proxy server.

    sudo apt-get install r-base r-base-dev unixODBC-dev libxml2 unixODBC liblzma-devzlib1g-dev libxml2-dev

    b. Next, youmust install python dependencies. If you are behind a proxy run the followingcommands to allow PIP to use a proxy server, replace proxy:portwith your proxyinformation:

    export http_proxy=http://proxy:portexport https_proxy=https://proxy:port

    c. Use PIP to install required Python libraries.

    sudo -E pip install jinja2sudo -E pip install PyYamlsudo -E pip install httplib2sudo -E pip install paramikosudo -E pip install setuptools

    d. Start R as sudo to install required R libraries:

    sudo R

    Run the following in R:

    install.packages(c("RInside", "Rcpp", "XML", "RUnit", "data.table","randomForest"))

    Select a CRAN mirror from the list and allow R to install the required libraries.

    Exit R:

    quit()

    7. Run the installer:

    a. The Distributed R installer checks dependencies and installs and configures Distributed Ron all nodes in your cluster. It first copies the required files to /opt/hp/distributedR andthen configures the XML configuration files in /opt/hp/distributedR/conf.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 25 of 198

    http://manpages.ubuntu.com/manpages/saucy/en/man5/apt.conf.5.html

  • Note: The installer makes the following changes to each node:

    o Changes the size of /dev/shm to 100% of freememory (obtained by running free().

    o Sets shmall and shmmax to 90% of total memory.

    o Sets shmmi to 500000.

    o Sets max open files (/proc/sys/fs/file-max) to 524288.

    Run the installer by specifying any options and the node(s) on which to install HPDistributed R:

    ./distributedR_install [OPTIONS] [NODES]

    Options:

    o -h or --help: Print help and Exit

    o -cor --check-cluster-connectivity: Check connectivity between the nodes andexit.

    o -y or --yes-to-all: Answer yes to all prompts (useful for non-interactive installs).

    Nodes: The host name or IP address of each node in the cluster. Specify all nodesregardless of which is themaster. You define themaster node in the next step.

    Example:

    ./distributedR_install node1 node2 node3

    b. Follow the installer's guided installation process to configure your system.

    The installer prompts you with these questions:

    i. Which node is the master? - Specify which node is themaster node by specifyingthe number of the node to act as master.

    ii. Which node(s) is/are the workers? - Specify which nodes are workers by selectingthe appropriate number or specifying a comma-separated list of workers.

    iii. Do you want to specify custom port ranges? - You can specify the port rangesover which themaster and worker nodes pass data. By default the range is ports50000 to 50100. If you answer yes then you are prompted for the port ranges to use.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 26 of 198

  • iv. Do you want to install Vertica ODBC support? - If yes, then the libraries requiredfor HP Vertica ODBC connections are installed to /opt/hp/odbc and the VRODBCR package is installed. However, youmust still manually configure ODBC properties.

    v. Do you want to run a test to make sure the Distributed R installation is OK? -If yes, some basic tests are run to verify the Distributed R install.

    c. Youmust exit the terminal session in which you installed Distributed R and log back in sosystem changes that the installer made can take effect. Distributed R changes limits forthe amount of open file handles and sharedmemory. These changes do not take effect inthe current session or any currently open sessions. Start Distributed R in a new session.

    d. The installation process automatically creates the cluster configuration file for your clusterand places it in /opt/hp/distributedR/conf/cluster_conf.xml on themaster node.See Cluster Configuration for details onmodifying the configuration.

    e. If you are going to connect Distributed R to a database, then configure ODBC. SeeConfiguring ODBC/RODBC/vRODBC to Connect to HP Vertica.

    f. Finally, if you are using the Distributed R Vertica Extensions, then install the extensionspack on your HP Vertica Cluster. See About Installing the HP Distributed R Extensions forHP Vertica Pack.

    HP Distributed R is now installed in /opt/hp/distributedR.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 27 of 198

  • Cluster ConfigurationThe default cluster configuration file is named cluster_conf.xml and defines themaster andworker nodes in the cluster, the amount of executors (R sessions) for each worker, and the amountof memory to use for Distributed R.

    The installation process creates themaster cluster configuration file and populates it with themaster/worker selections youmade when you installed HP Distributed R. You do not need tochange the configuration after installation unless you want to manually change settings or manuallyadd or remove nodes from your cluster.

    Each node has a cluster_conf.xml file in /opt/hp/distributedR/conf. However, only thecluster_conf.xml file on themaster node defines the settings for the cluster.

    When you run distributedR_start() from themaster node, Distributed R automatically loads thecluster configuration file in /opt/hp/distributedR/conf/cluster_conf.xml. You can optionallyspecify a different configuration file with the cluster_conf argument, for example: distributedR_start(conf='/home/dbadmin/cluster2.xml'). By default the distributedR_start() commandlooks in /opt/hp/distributedR/conf for the configuration file. If the configuration file exists in adifferent directory then youmust specify the full path to the file.

    Example Cluster Configuration File

    node015000050100

    node01500005010000

    node02500005010000

    node03500005010000

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 28 of 198

  • Configuration Optionsl The tag specifies the local (master) node configuration.

    l tag contains the individual workers configuration and each tag definesdetails on the configuration for eachWorker node.

    l specifies the hostname (or IP Address) of the respective server. Enter themaster'shostname under the tag and the worker's node hostname under the tag.

    l Port Range is defined in and tags. These tags define therange of port numbers allowed for use by a particular node (Master orWorker). At run time, arandom port number within the port range defined is opened. If the chosen port is not available,an exception is thrown. Master node port range should have aminimum of two available ports,while eachWorker node port range should have aminimum of 2*(total number of workernodes)+1 available ports at all times of Distributed R task execution.

    l defines the number of R sessions to run on the worker. definesthe amount of memory to use on the worker in MB for Distributed R (total for the server, not persession). If and options in the worker nodes is zero, thenExecutors is set to the number of logical CPUs on the server and SharedMemory is set to thesize of themounted sharedmemory region on the server.

    For addition details type help(distributedR_start) at the R prompt or see the Distributed RPackageManual.

    Adding or Removing Nodes in an HP Distributed RCluster

    You can add to your HP Distributed R cluster by simply re-running the installation script andspecifying additional nodes (in addition to the nodes in the original cluster). You can also removeone or more nodes from a cluster by running the uninstall utility and then re-running the install on theremaining nodes to update the cluster configuration file for themaster node.

    To add a node to a HP Distributed R cluster:1. For any nodes you are adding to the cluster, first configure passwordless SSH from the

    installation node to the new node(s) and configure passwordless sudo on each new node. SeeConfiguring Passwordless SSH and sudo for the Installation User

    2. From themaster node, navigate to the directory containing the HP Distributed R installer. Usethe installation steps for your specific platform. See Installingor Upgrading HP Distributed R

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 29 of 198

    http://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdfhttp://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdf

  • on RedHat/CentOS or Installingor Upgrading HP Distributed R on Ubuntu. When specifyingnodes for the dependency installer and installer, specify all of the existing nodes as well as thenew nodes. The software on the existing nodes is not changed, and the new nodes have HPDistributed R installed. The cluster configuration file is updated with the new nodes.

    To remove a node from a HP Distributed Rcluster:1. From themaster node, navigate to the directory containing the HP Distributed R installer. Run

    distributedR_uninstall and list the nodes to uninstall. For example, if you have a four nodecluster containing Nodes A - D, and you want to remove NodeD then run the command:

    ./distributedR_uninstall NodeD

    2. Run the installer and provide the addresses for the remaining nodes in the cluster to reconfigurethe cluster configuration file. For example:

    ./distributedR_install NodeA NodeB NodeC

    No software is installed, but the cluster configuration file is updated to reflect the new makeupof the cluster.

    Uninstalling HP Distributed RYou can remove all the nodes from your HP Distributed R cluster and uninstall the HP Distributed Rsoftware by using the distributedR_uninstall script located in the HP Distributed R package youdownloaded to install HP Distributed R. If you only want to remove onemore nodes (but not allnodes) from aHP Distributed R cluster see Adding or Removing Nodes in an HP Distributed RCluster.

    To completely uninstall HP Distributed R:From themaster node, navigate to the directory containing the HP Distributed R installer. RundistributedR_uninstall and list all the nodes in your cluster. For example, if your clustercontained Nodes A - D, you run the command:

    ./distributedR_uninstall NodeA NodeB NodeC NodeD

    HP Distributed R is uninstalled and the directory /opt/hp/distributedR is removed from each node inthe cluster.

    Using Distributed R With RStudioYou can use RStudio and RStudio server with HP Distributed R. You can install RStudio orRStudio server on themaster node and use HP Distributed R as you normally would.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 30 of 198

  • You can get more details about RStudio and RStudio Server from the RStudio web site at:http://www.rstudio.com/.

    Important: RStudio and RStudio Server are third-party products. While HP has done initialtesting for HP Distributed R with RStudio and RStudio Server, they are not officially supportedfor use with HP Distributed R.

    Configuring ODBCINI and VERTICAINI EnvironmentVariables for RStudio

    When using vRODBC tomove data from anHP Vertica database to an HPDistributed R cluster,youmust configure the ODBCINI and VERTICAINI environment variables. TheODBCINI variableis configured in a file named odbc.ini. The VERTICAINI variable is configured in a file namedvertica.ini.

    If these variables are not defined or are defined incorrectly, RStudio will return an error messagethat states the following: "Data source name not found."

    Determine Whether ODBCINI and VERTICAINI AreConfigured

    In order to determine whether the ODBCINI and VERTICAINI environment variables are correctlyconfigured in RStudio, enter the following commands in the RStudio terminal:

    > Sys.getenv("ODBCINI")> Sys.getenv("VERTICAINI")

    If no paths to the odbc.ini or vertica.ini files are provided, then the environment variables arenot correctly configured.

    To determine whether VERTICAINI andODBCINI are configured at the system level, use a texteditor of your choice to view the .bashrc file. The .bashrc file is located in your home userdirectory. To view the file, enter the following:

    $ vim ~/.bashrc

    If the following lines are not in the .bashrc file, youmust add them:

    export ODBCINI=export VERTICAINI=

    Configure the ODBCINI and VERTICAINI EnvironmentVariables in .bashrc

    To set the environment variables so that they are recognized by RStudio, youmust first add them tothe .bashrc file.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 31 of 198

    http://www.rstudio.com/

  • To do so, enter the following commands:

    $ echo 'export ODBCINI=' >> ~/.bashrc$ echo 'export VERTICAINI=' >> ~/.bashrc

    Rather than use the echo command, you have the option of opening the .bashrc file and addingthe ODBCINI and VERTICAINI environment variable information within .bashrc itself. To do so,enter the following lines into the .bashrc file, then save the file:

    ODBCINI=VERTICAINI=

    Configure the ODBCINI and VERTICAINI EnvironmentVariables in RStudio

    After setting the odbc.ini and vertica.ini file paths in ~/.bashrc, add the file paths for the files inRStudio. To do so, complete either one of the following steps:

    l Manually assign the environment variables in RStudio to the correct paths of the odbc.ini andvertica.ini files. In RStudio, enter the following commands:

    > Sys.setenv(ODBCINI="")> Sys.setenv(VERTICAINI="")

    l Edit the Renviron file on your system. It is located in the /usr/lib64/R/etc/Renvirondirectory. Add the following two lines to the Renviron file, then save the file:

    ODBCINI=${ODBCINI-''}VERTICAINI=${VERTICAINI-''}

    TheODBCINI and VERTICAINI environment variables are ported to the RStudio session.

    HP Distributed R User's GuideInstalling HP Distributed R

    HP Distributed R (1.1.x) Page 32 of 198

  • Single Node and Multi Node OperationDistributed R can be run in Single Nodemode (localhost mode) andMulti Nodemode. By default,when you use the installer to install 2 or more nodes then Distributed R runs inMulti Nodemode. InMulti Nodemode you leverage the processors andmemory of all nodes in the cluster. However,Single Nodemode is still an effective way to use Distributed R as it leverages all the CPUs on thesingle server and allows for parallel R processing. If you have installed Distributed R on only onenode then the only mode available is single node.

    Running Distributed R in Single Node Mode in aDistributed R Cluster

    If you have installed Distributed R onmultiple servers, then you can still run in single nodemode.When in single nodemode, the server acts as both themaster and a worker. To do this:

    1. On any node in the cluster, start an R session.

    2. If the node is a worker node in the cluster, then you can start it in Single Nodemode simply bycalling:

    > library(distributedR)? distributedR_start()Workers registered - 1/1.All 1 workers are registered.Master address:port - 127.0.0.1:50000

    3. If the node is themaster node, then you can specify the localhost configuration file that iscreated on every node during the installation process to start themaster in single nodemode.This starts Distributed R only on the local node. For example:

    > distributedR_start(cluster_conf='cluster_conf_localhost.xml')Workers registered - 1/1.All 1 workers are registered.Master address:port - 127.0.0.1:50000

    HP Distributed R User's GuideSingle Node andMulti NodeOperation

    HP Distributed R (1.1.x) Page 33 of 198

  • Programming ModelDistributed R Data Structures

    Distributed R provides you with new language extensions and a distributed runtime for R.Distributed R contains the following three groups of commands. For more details about eachcommand, type help(command) from within R or type help(distributedR) to view an overview ofall the commands.

    Command Description

    Session Management Commands

    distributedR_start() Start a new Distributed R session.

    distributedR_shutdown() End session.

    distributedR_status() Obtain master and worker information.

    distributedR_master_info() Obtain details about themaster node.

    Distributed Data Structure Commands

    darray() Create distributed array.

    dframe() Create distributed data frame.

    dlist() Create distributed list.

    as.darray() Create darray object frommatrix object.

    npartitions() Obtain total number of partitions.

    getpartition() Fetch darray, dframe, or dlist object.

    partitionsize() Get the size of a partition.

    clone() Clone or deep copy of a darray.

    Parallel Execution Commands

    foreach() Execute function on cluster.

    splits() Pass partition to foreach loop

    update() Make partition changes inside foreach loopglobally visible

    Distributed R Data StructuresDistributed R provides three new data structures for use within R; distributed arrays, distributeddata frames, and distributed lists.

    HP Distributed R User's GuideProgrammingModel

    HP Distributed R (1.1.x) Page 34 of 198

  • Distributed arrays darray provide a shared, in-memory view of multi-dimensional data storedacross multiple servers. Distributed arrays are Partitioned and Shared.

    Distributed arrays can be partitioned into contiguous ranges of rows, columns, or blocks. Youspecify the size of the initial partitions. Distributed R workers store partitions of the distributed arrayin the compressed sparse column format unless the array is defined as dense.

    l Use partitions to specify coarse-grained parallelism by writing functions that execute in paralleland operate on partitions. For example, partitions of a distributed array can be loaded in parallelfrom data stores such as HP Vertica or from files.

    l Use getpartition to fetch a distributed array andmaterialize it at themaster node. Forexample, getpartition(A) reconstructs the whole array A at themaster by fetching thepartitions from local and remote workers.The ithpartition can be fetched by getpartition(A,i).

    Distributed arrays can be read-shared by multiple concurrent tasks. You simply pass the arraypartitions as arguments tomany concurrent tasks. However, Distributed R supports only a singlewriter per partition.

    A distributed data frame (dframe) is similar to a darray. The primary difference is that, unlikedarray,distributed data frames can store non-numeric data. Even though you can use a dframe tostore numeric only data, it is muchmore efficient to use darray in such cases. The efficiencydifference is because of the underlying representation of these data structures. Numeric data takesless memory than character data. Over large data sets, there is a performance difference.

    A distributed list (dlist) stores elements inside lists that are partitioned across servers. To createa distributed list, you only need to specify the number of partitions. For example,dlist(5) createsa distributed list with five partitions. Initially, each partition is an R list with no elements.

    Parallel ProgrammingIf you are a programmer, you can use foreach loops to execute functions in parallel. You can passdata, including partitions of darray and dframe, to the functions. Array and data frame partitionscan be referred to by the splits function. The splits function automatically fetches remote partitionsand combines them to form a local array. For example, if splits(A)is an argument to a functionexecuting on a worker, then the whole array A would be re-constructed by the runtime, from localand remote partitions, and passed to that worker. The ithpartition can be referenced by splits(A,i).

    Functions inside foreach do not return data. Instead, call update inside the function tomakedistributed array or data frame changes globally visible. The Distributed R runtime starts tasks onworker nodes for parallel execution of the loop body. By default, there is a barrier at the end of theloop to ensure all tasks finish before statements after the loop are executed.

    Note: HP Distributed R is bound by the same limit as R for value sizes (precision). Forexample, HP Distributed R values for the type double is limited to 2^53-1, for example9007199254740991. Effectively, R is limited to 53 bits, and "represents to that precision arange of absolute values from about 2e-308 to 2e+308". See help(double) in the R consolefor additional details.

    HP Distributed R User's GuideProgrammingModel

    HP Distributed R (1.1.x) Page 35 of 198

  • Note: Saving R Sessions - Distributed R shuts downwhen you quit the R session, even ifyou choose to save your workspace. If you shut downDistributed R, or quit R and then saveyour session, youmay encounter an error. Such errors occur when any of your R variablesstore a reference to a distributed object.

    Programming ExamplesThese examples illustrate the Distributed R programmingmodel.

    Getting StartedFollow the steps in to first install Distributed R. Load the Distributed R library, and then start thecluster by calling distributedR_start().

    library(distributedR)Loading required package: RcppLoading required package: RInsideLoading required package: XML

    distributedR_start()Workers registered - 3/3.

    All 3 workers are registered.Master address:port - docb01:50000

    You can view the status of the cluster with the distributedR_status() command. This commandreturns details such as:

    l Number of workers in the cluster

    l Number of R instances managed by each worker

    l Systemmemory available on each worker node

    distributedR_status()Workers Inst SysMem MemUsed DarrayQuota DarrayUsed

    1 docb01:50001 8 11911 3214 10137 02 docb02:50000 8 11911 1920 10137 03 docb03:50000 8 11911 1924 10137 0

    When you are done using Distributed R, you can call distributedR_shutdown() to disconnect themaster from the workers and free resources.

    distributedR_shutdown()Shutdown complete

    HP Distributed R User's GuideProgrammingModel

    HP Distributed R (1.1.x) Page 36 of 198

  • Creating a Distributed ArrayNext, create a distributed array using darray(). Create a 9 9 dense array by specifying its sizeand how it is partitioned. The following example shows how to partition the array into 33 blocksand set all its elements to the value 10. Therefore, nine partitions could reside on remote nodes.

    library(distributedR)distributedR_start()Workers registered - 3/3.

    All 3 workers are registered.Master address:port - docb01:50000

    A

  • [2,] 10 10 10 10 10 10 10 10 10[3,] 10 10 10 10 10 10 10 10 10

    getpartition(A)[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]

    [1,] 10 10 10 10 10 10 10 10 10[2,] 10 10 10 10 10 10 10 10 10[3,] 10 10 10 10 10 10 10 10 10[4,] 10 10 10 10 10 10 10 10 10[5,] 10 10 10 10 10 10 10 10 10[6,] 10 10 10 10 10 10 10 10 10[7,] 10 10 10 10 10 10 10 10 10[8,] 10 10 10 10 10 10 10 10 10[9,] 10 10 10 10 10 10 10 10 10

    Distributed arrays can initially be declared empty. For example, it is typical to create an array andthen load data into the array from a data store. The initial declaration creates a full array which issoon overwritten. By declaring an array empty, you can savememory space.

    Aempty

  • matrix is of the same size as the partition (3 3) but initialized by the value of the iteration variable.Thus the ithpartition has all elements equal to i. Next, you can fetch the whole array usinggetpartition().

    getpartition(B)[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]

    [1,] 1 1 1 2 2 2 3 3 3[2,] 1 1 1 2 2 2 3 3 3[3,] 1 1 1 2 2 2 3 3 3[4,] 4 4 4 5 5 5 6 6 6[5,] 4 4 4 5 5 5 6 6 6[6,] 4 4 4 5 5 5 6 6 6[7,] 7 7 7 8 8 8 9 9 9[8,] 7 7 7 8 8 8 9 9 9[9,] 7 7 7 8 8 8 9 9 9

    By specifying the partition index, you can fetch a particular partition, for example, the fifth partition:

    getpartition(B,5)[,1] [,2] [,3]

    [1,] 5 5 5[2,] 5 5 5[3,] 5 5 5

    When you use foreach, be aware of this function's limitations. First, only variables passed asarguments to the function (init in this case) are available for use within the function. For example,the array A or its partitions cannot be used within the function. Even the iterator variable (i) must bepassed as an argument. Second, loop functions don't return any value.The only way you canmakedatamodifications visible is to call update() on the partition. In addition, you can only use updateon the distributed data structures darray, dframe, dlist arguments. For example, update(index)is incorrect code as index is not a distributed object.

    Parallel Array AdditionWith the two initialized distributed arrays, you can start computations such as adding theirelements. You again use a foreach loop to perform the parallel addition. First, create an outputarray C of the same size and partitioning scheme. In the foreach loop pass the ithpartition of allthree arrays, A, B, and C. Within the loop you can add the corresponding partitions, put the output inc, and call update:

    C

  • [1,] 11 11 11 12 12 12 13 13 13[2,] 11 11 11 12 12 12 13 13 13[3,] 11 11 11 12 12 12 13 13 13[4,] 14 14 14 15 15 15 16 16 16[5,] 14 14 14 15 15 15 16 16 16[6,] 14 14 14 15 15 15 16 16 16[7,] 17 17 17 18 18 18 19 19 19[8,] 17 17 17 18 18 18 19 19 19[9,] 17 17 17 18 18 18 19 19 19

    While you can use foreach to perform any parallel operation, the Distributed R package providesbasic operators with factory presets that work on distributed arrays.These operators include arrayaddition, subtraction,multiplication, and summary statistics such as max, min, mean, and sum(including their column and row versions such as colSums). Internally, all these operators areimplemented using foreach. The following example illustrates the use of some of these operators:

    D

  • 6 0 0 0 0 0 0 0 0 07 0 0 0 0 0 0 0 0 08 0 0 0 0 0 0 0 0 09 0 0 0 0 0 0 0 0 0

    The data frame dF has 9 partitions each of size 3 3.

    You can also create an empty dframe by specifying npartition and not dimensions or blocks:

    dF

  • You can obtain individual partitions or the whole list:

    getpartition(dL,1)[[1]][1] "HP" "1"

    getpartition(dL)[[1]][1] "HP" "1"

    [[2]][1] "HP" "2"

    [[3]][1] "HP" "3"

    Load and Save Data from FilesYou can save or load data in parallel. This example shows how to save data to files. Use theforeach loop to write each partition of an array to a file:

    fname

  • E
  • is assigned to the first partition of array X. HP Vertica has row identifiers to refer to individual rows.To fetch the first partition and display data, use getpartition:

    getpartition(X, 1)[,1] [,2] [,3] [,4]

    [1,] 5 0.903815 0.522466 0.250464[2,] 1 0.994233 0.138644 0.139464[3,] 3 0.117651 0.285975 0.309341[4,] 4 0.280725 0.006694 0.684827[5,] 6 0.331704 0.835160 0.498040

    Parallel Execution Using Existing R PackagesSometimes, you can solve a problem by applying functions from existing R packages in parallel.Consider the example of finding the shortest distance from five source vertices to all other verticesin the graph. Because distance calculation from each source vertex is independent from the others,you can start five tasks to calculate them in parallel. R already has a package called igraph thatcan calculate shortest distances. The following example details how to use igraph in parallel tosolve the preceding problem. For this example, youmust install igraph on all machines in theDistributed R cluster.You canmanually download the software from CRAN or useinstall.packages(igraph).

    First, create a sparse distributed array to store the graph. Because you don't want to partition thegraph, the array has only one partition equal to the total size of the graph.

    G

  • })progress: 100%

    Fetch all shortest distances from the first vertex then print the first ten values:

    getpartition(paths, 1)[,1:10][1] 0 2 2 3 2 2 3 2 1 2

    Examples of Parallelizing Data in Distributed RThese examples demonstrate how you can decrease the execution time of a query by using parallelprogramming in HP Distributed R.

    The number of samples used in these examples is 10million, which results in a data set size of34.5MB. Because this sample size is not very large, youmay not notice a decrease in executiontime when you run the parallel programming examples. However, the decrease in execution timebecomes apparent when you use a larger data set, such as one that is several hundredmegabytesin size. The examples provided only illustrate how to use parallel task execution and parallel dataexecution on large data sets.

    Loading and Synthesizing DataInstall and load the package named "zipcode" as follows:

    > install.packages("zipcode")> library(zipcode)> data(zipcode)

    Synthesize the data, and create a data frame named "exampleData":

    # limit the number of samples to 1 million> nSamples exampleData format(object.size(exampleData), units = "auto")

    Use the data frame created,"exampleData", for all of the following examples.

    Sequential ExecutionIn this example, you use a sequential execution approach to determine the following values:

    HP Distributed R User's GuideProgrammingModel

    HP Distributed R (1.1.x) Page 45 of 198

  • l Most commonName, City, State, and ZIP codes.

    l Number of unique Names, Cities, States, and ZIP codes.

    You can find these values without using HP Distributed R, using only R:

    # set a timer> system.time({# create a list called summarySeq that takes as an output the data we're looking for

    summarySeq summarySeq$popularName[1] "EBR"

    $popularCity[1] "Apo"

    $popularState[1] "TX"

    $popularZip[1] "04852"

    $numberOfUniqueNames[1] 17576

    $numberOfUniqueCities[1] 19108

    $numberOfUniqueStates[1] 62

    $numberOfUniqueZIPs[1] 44336

    Parallel Task ExecutionThe following example demonstrates how you can use the same data to perform the sameexecution shown in the preceding example. The only exception is that, this time, the tasks are

    HP Distributed R User's GuideProgrammingModel

    HP Distributed R (1.1.x) Page 46 of 198

  • performed in parallel execution.

    In parallel execution, individual tasks are executed concurrently on separate executors. This allowsyou to spread the task execution over as many executors as there are tasks. This reduces the workload for an individual executor as well as the execution time.

    # load and start distributed R> library(distributedR)> distributedR_start()# set the timer> system.time({# set the number of tasks to be executed# since we have 8 tasks (popularName, popularCity, popularState, popularZip,numberOfUniqueNames, numberOfUniqueCities, numberOfUniqueStates, numberOfUniqueZips),we'll set it to 8

    nTasks

  • $numberOfUniqueNames[1] 17576

    $numberOfUniqueCities[1] 19108

    $numberOfUniqueStates[1] 62

    $numberOfUniqueZIPs[1] 44336

    You can see from the result of summaryPar1 that the exact same results are obtained with parallelexecution that were achieved with sequential execution.

    Parallel Data ExecutionThe example of parallel task execution gives you results that are superior to sequential execution.However, you need to use a second parallel approach when working with large amounts of data,such as a data set that is several hundredmegabytes large. This second approach, known asparallel data execution, divides the input data into separate partitions which are then sent to theexecutors.

    Parallel data execution is amore scalable approach. HP recommends this approach for loadinglarge amounts of data into HP Vertica, such as a large data frame.

    The parallel data execution approach also takes advantage of HP Vertica load balancingcapabilities. It does so by splitting the data into partitions and sending those partitions to particularworker nodes. By comparison, parallel task execution from the preceding example sends theentirety of exampleData to all of the worker nodes at once.

    # set the timer for executionsystem.time({

    DF

  • localUniqueNames = unique(datai$name),localUniqueCities = unique(datai$city),localUniqueStates = unique(datai$state),localUniqueZips = unique(datai$zip)

    )update(si)

    })

    # intermediate will hold the values of the data from all of the individual partitions

    intermediate summaryPar2$popularName[1] "EBR"

    $popularCity[1] "Apo"

    $popularState[1] "TX"

    $popularZip[1] "04852"

    $numberOfUniqueNames[1] 17576

    HP Distributed R User's GuideProgrammingModel

    HP Distributed R (1.1.x) Page 49 of 198

  • $numberOfUniqueCities[1] 19108

    $numberOfUniqueStates[1] 62

    $numberOfUniqueZips[1] 44336

    The results are the same as the first two approaches.

    HP Distributed R User's GuideProgrammingModel

    HP Distributed R (1.1.x) Page 50 of 198

  • Distributed R Command ReferenceThis section provides an overview and examples for each of the functions available in theDistributed R package,

    Command Description

    Session Management Commands

    distributedR_start() Start a new Distributed R session.

    distributedR_shutdown() End session.

    distributedR_status() Obtain master and worker information.

    distributedR_master_info() Obtain details about themaster node.

    Distributed Data Structure Commands

    darray() Create distributed array.

    dframe() Create distributed data frame.

    dlist() Create distributed list.

    as.darray() Create darray object frommatrix object.

    npartitions() Obtain total number of partitions.

    getpartition() Fetch darray, dframe, or dlist object.

    partitionsize() Get the size of a partition.

    clone() Clone or deep copy of a darray.

    Parallel Execution Commands

    foreach() Execute function on cluster.

    splits() Pass partition to foreach loop

    update() Make partition changes inside foreach loopglobally visible

    distributedR_start()distributedR_start() opens network connections between themaster and the workers and starts theDistributed R runtime on the worker nodes.

    Type help(distributedR_start) in the R console for details on arguments or see the DistributedR PackageManual.

    HP Distributed R User's GuideDistributed R CommandReference

    HP Distributed R (1.1.x) Page 51 of 198

    http://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdfhttp://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdf

  • Example

    > library(distributedR)Loading required package: RcppLoading required package: RInsideLoading required package: XML

    > distributedR_start()Workers registered - 3/3.

    All 3 workers are registered.Master address:port - node01:50000

    distributedR_status()distributedR_status() shows the status of each worker. Use with the argument help=TRUE todisplay descriptions about each column.

    Type help(distributedR_status) in the R console for details on arguments or see theDistributed R PackageManual.

    Example

    > library(distributedR)Loading required package: RcppLoading required package: RInsideLoading required package: XML

    > distributedR_start()Workers registered - 3/3.

    All 3 workers are registered.Master address:port - node01:50000

    > distributedR_status(help=1)

    distributedR_status - helpWorkers: list of workersInst: number of R instances on a workerSysMem: total available system memory (MB)MemUsed: memory currently used in a worker (MB)DarrayQuota: memory for darrays (MB)DarrayUsed: memory currently used by darray (MB)

    Workers Inst SysMem MemUsed DarrayQuota DarrayUsed1 node01:50001 8 11911 3214 10137 02 node02:50000 8 11911 1921 10137 03 node03:50000 8 11911 1928 10137 0

    HP Distributed R User's GuideDistributed R CommandReference

    HP Distributed R (1.1.x) Page 52 of 198

    http://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdf

  • distributedR_master_info()distributedR_master_info() provides details about themaster node, including address, port,and session ID.

    Type help(distributedR_master_info) in the R console for additional details or see theDistributed R PackageManual.

    Example

    > library(distributedR)Loading required package: RcppLoading required package: RInsideLoading required package: XML

    > distributedR_start()Workers registered - 3/3.

    All 3 workers are registered.Master address:port - node01:50000

    > distributedR_master_info()$address[1] "node01"

    $port[1] 50000

    $sessionID[1] 50505

    distributedR_shutdown()distributedR_master_shutdown() stops the Distributed R runtime on the worker nodes, closesconnections to them, and frees resources associated with Distributed R.

    Type help(distributedR_shutdown) in the R console for additional details or see the DistributedR PackageManual.

    Example

    > library(distributedR)Loading required package: RcppLoading required package: RInsideLoading required package: XML

    > distributedR_start()Workers registered - 3/3.

    HP Distributed R User's GuideDistributed R CommandReference

    HP Distributed R (1.1.x) Page 53 of 198

    http://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdfhttp://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdfhttp://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdf

  • > distributedR_shutdown()Shutdown complete

    darray()

    darray (dim, blocks, sparse = FALSE, data = 0, empty=FALSE, distribution_policy='roundrobin')darray (npartitions, sparse = FALSE, distribution_policy='roundrobin')

    The darray() function creates distributed arrays, which store in-memory, multi-dimensional dataacross several machines (worker nodes). Data can be partitioned into chunks of rows, columns, orblocks. Distributed arrays can store only numeric data.

    By default, array partitions are internally stored as densematrices. If an array is specified sparse,partitions are stored in the compressed sparse column format. Last set of partitions may have fewerrows or columns if array size is not an integer multiple of partition size. For example, the distributedarray darray(dim=c(5,5), blocks=c(2,5)) has three partitions. The first two partitions have two rowseach but the last partition has only one row. All three partitions have five columns.

    Distributed arrays can also be defined by specifying just the number of partitions, but not theirsizes. This flexibility is useful when the size of an array is not known. For example, darray(npartitions=c(5,1)) is a dense array with five partitions. Each partition can contain any number ofrows, though the number of columns should be same to conform to a well formed array.

    Distributed arrays can be read-shared by multiple concurrent tasks, but modified by only a singlewriter per partition. Programmers express parallelism by applying functions on array partitions inforeach loops. Loop body is executed at workers. Partitions can be passed as arguments usingsplits. Array modifications can be published globally using update.

    Distributed arrays can be fetched at themaster using getpartition. Number of partitions can beobtained by npartitions. Partitions are numbered from left to right, and then top to bottom (row majororder). Dimension of each partition can be obtained using partitionsize.

    Type help(darray) in the R console for additional details or see the Distributed R PackageManual.

    Note: The mean() function included with darray may return inf (infinite) for extremely largenumbers due to overflow in the R sum() function.

    Supported OperationsThe darray function supports the following basic operators between a distributed array and anumeric as well as between two distributed arrays:

    HP Distributed R User's GuideDistributed R CommandReference

    HP Distributed R (1.1.x) Page 54 of 198

    http://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdfhttp://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdf

  • l Multiplication(*)

    l Addition(+)

    l Subtraction(-)

    Note:Formultiplication between two distributed arrays, matrix multiplication is used.

    The darray function additionally supports the following operators when the input is a singledistributed array:

    l max()

    l min()

    l sum()

    l mean()

    l colSums()

    l rowSums()

    l colMeans()

    l rowMeans()

    l head()

    l tail()

    l ncol()

    l nrow()

    Example

    library(distributedR)distributedR_start()da

  • update(c)})

    getpartition(result)distributedR_shutdown()

    dframe

    dframe (dim, blocks, distribution_policy='roundrobin')dframe (npartitions, distribution_policy='roundrobin')

    The dframe() function creates distributed data frames, which store in-memory, multi-dimensionaldata across several machines. Data can be partitioned into chunks of rows, columns, or blocks.Unlike distributed arrays (darray), dframe can store both numeric and string data. However, dframecan be space-inefficient, and should be replaced by darray wherever possible.

    Distributed data frame partitions are internally stored as data.frame objects. Last set of partitionsmay have fewer rows or columns if data frame size is not an integer multiple of partition size. Forexample, the distributed data frame dframe(dim=c(5,5), blocks=c(2,5)) has three partitions. Thefirst two partitions have two rows each but the last partition has only one row. All three partitionshave five columns.

    Distributed data frames can also be defined by specifying just the number of partitions, but not theirsizes. This flexibility is useful when the size of a data frame is not known ahead of time. Forexample, dframe(npartitions=c(5,1)) is a data framewith five partitions. Each partition can containany number of rows, though the number of columns should be the same to conform to a well-formeddata frame.

    Distributed data frames can be read-shared by multiple concurrent tasks, but modified by only asingle writer per partition. Programmers express parallelism by applying functions on partitions inforeach loops. Loop body is executed at workers. Partitions can be passed as arguments usingsplits. Array modifications can be published globally using update.

    Distributed data frames can be fetched at themaster using getpartition. Number of partitions can beobtained by npartitions. Partitions are numbered from left to right, and then top to bottom (row majororder). Dimension of each partition can be obtained using partitionsize.

    Type help(dframe) in the R console for additional details or see the Distributed R PackageManual.

    Supported OperationsThe dframe function supports the following basic operators between a distributed data frame and anumeric as well as between two distributed data frames:

    l Multiplication(*)

    l Subtraction(-)

    HP Distributed R User's GuideDistributed R CommandReference

    HP Distributed R (1.1.x) Page 56 of 198

    http://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdfhttp://my.vertica.com/docs/DISTR/1.1.x/PDF/Distributed-R-Manual.pdf

  • The dframe function additionally supports the following operators when the input is a singledistributed data frame:

    l max()

    l min()

    l sum()

    l mean()

    l colSums()

    l rowSums()

    l colMeans()

    l rowMeans()

    l head()

    l tail()

    l ncol()

    l nrow()

    Example

    library(distributedR)distributedR_start()df

  • getpartition(dc)

    distributedR_shutdown()

    dlist

    dlist (npartitions)

    The dlist() function creates distributed lists, which stores in-memory lists across severalmachines. Just like R's list, dlist can store other R objects such as character, numeric and logicalvectors, lists, matrices, andmodels. However, dlist can be space-inefficient, and should bereplaced by darray when possible.

    Distributed lists are internally stored as list objects. Each partition of the list can have variablenumber of elements in it. For example, the distributed list dlist(npartitions=5) has five partitions.Each partition is an empty list().

    Distributed lists can be read-shared by multiple concurrent tasks, but modified by only a singlewriter per partition. Programmers express parallelism by applying functions on dlist partitions inforeach loops. Loop body is executed at workers. Partitions can be passed as arguments usingsplits. List modifications can be published globally using update.

    Distributed lists can be fetched at themaster using getpartition. Number of partitions can beobtained by npartitions. Partitions are numbered from left to right.

    Type help(dlist) in the R console for additional details or see the Distributed R PackageManual.

    Example

    library(distributedR)distributedR_start()dl

  • [[4]][1] "HP" "4"

    [[5]][1] "HP" "5"

    distributedR_shutdown()

    getpartition

    getpartition (input_array, partition_index, column_index)

    The is.darray() function fetches partition(s) from a darray, dframe or dlist.

    If both partition_index and column_index aremissing then the full input darray, dframe or dlist isreturned.

    2-D partitioning is valid only for darray and dframe. Since dlist is partitioned lengthwise, onlypartition_index is used to fetch a dlist partition. The column_index argument is undefined for dlist.

    Partitions are numbered from left to right and then top to bottom (row-major order). Partitionnumbers start from 1. For row partitioning (each partition has all the columns) or column partitioning(each partition has all the rows) the column_index argument should not be used. For 2-Dpartitioning, both partition_index and column_index may be used.

    Type help(getpartition) in the R console for additional details or see the Distributed R PackageManual.

    Example

    library(distributedR)distributedR_start()##Input array of size 5X5 with 4 partitionsda

  • getpartition(da,2,2)[,1] [,2]

    [1,] 7 7[2,] 7 7

    npartitions

    npartitions (x)npartitions2D (x)

    The npartitions() and npartitions2D() functions return the number of partitions in a darray,dframe or dlist. npartitions() returns an integer that denotes the number of partitions.npartitions2D() returns a vector that denotes the number of partitions in each direction(rows/columns).

    npartitions returns the total number of partitions in the distributed object. Use npartitions2D toobtain the number of partitions along each direction.

    Type help(npartitions) in the R console for additional details or see the Distributed R PackageManual.

    Example

    library(distributedR)distributedR_start()##Input array of size 5X5 with 4 partitionsda

  • Example

    library(distributedR)distributedR_start()##Input array of size 5X5 with 4 partitionsda

  • The as.darray() function converts an input matrix into a distributed array (darray) with dimensionsequal to that of the input matrix and partitioned according to argument 'blocks'. Datamay reside aspartitions on remote nodes.

    If partition size (blocks) is missing then the input matrix is row partitioned and striped across thecluster, so that the returned distributed array has approximately as many partitions as the number ofR instances in the Distributed R session. The last set of partitions may have fewer rows or columnsif input matrix size is not an integer multiple of partition size. For example, the distributed arrayas.darray(matrix(1,nrow=5,ncol=5), blocks=c(2,5)) has three partitions. The first two partitionshave two rows each but the last partition has only one row. All three partitions have five columns.

    To create a distributed array with just one partition, pass the dimension of the input array. Forexample: as.darray(A, blocks=dim(A)).

    Type help(as.darray) in the R console for additional details or see the Distributed R PackageManual.

    Example

    library(distributedR)distributedR_start()##Create 4x4 matrixmtx

  • To create a distributed framewith just one partition, pass the dimension of the input array. Forexample: as.dframe(A, blocks=dim(A)).

    Type help(as.dframe) in the R console for additional details or see the Distributed R PackageManual.

    Example

    # Single node Distributed R install# Two Executorslibrary(distributedR)distributedR_start()cars = mtcarsdim(cars)[1] 32 11dcars = as.dframe(cars)# Data is split for two executors:partitionsize(dcars)

    [,1] [,2][1,] 16 11[2,] 16 11

    factor.dframe()

    factor.dframe(dframe, colName, colID, trace=FALSE)

    The factor.dframe() function converts categorical columns (character, logical, or factor) of a dframeinto factors. If no columns or column IDs are provided then all supported types (character, logicaland factor) in the dframe are converted. Conversions are done in place; the original dframe ismodified and the function returns nothing.

    This function works the same as as.factor.dframe() except that it modifies the dframe in placeinstead of returning amodified dframe.

    Note: This function does not support numeric because of the potentially huge levels array thatcould be created with large data sets.

    Type help(factor.dframe) in the R console for additional details or see the Distributed RPackageManual.

    Example

    library(distributedR)distributedR_start()DF

  • dfi[,1]
  • dfi[,1]
  • distributedR_start()DF
  • dfi[,1]
  • Example

    library(distributedR)distributedR_start()mtx

  • })getpartition(result)distributedR_shutdown()

    Multiple Splits Inside a foreach LoopYou can pass list and vector-based arguments into the splits() function within a foreach loop. Doingso allows you to assign splits to specific executors (R sessions).

    SyntaxThe syntax for passing list and vector-based arguments into the splits() function is:

    splits(dobject,list)

    splits(dobject,vector)

    The dobject can be a dlist, darray, or dframe.

    Assign Splits to a dobjectThe following example demonstrates how to assign splits to a dobject named A. In this case, A has9 splits and a task parallelism of 3. You can divide the splits as follows:

    l Splits 1, 2, and 3Assign to executor 1

    l Splits 4, 5, and 6Assign to executor 2

    l Splits 7, 8, and 9Assign to executor 3

    A

  • l B[[1]] in the function body has split 2 of A

    l B[[2]] in the function body has split 3 of A

    l B[[3]] in the function body has split 4 of A

    Write a List to Pass to splits()You can also write a list and pass it to the splits() function: