MATLAB PARALLEL COMPUTING TOOLBOX - S Uživatelská příručka Strana 1

Procházejte online nebo si stáhněte Uživatelská příručka pro Software MATLAB PARALLEL COMPUTING TOOLBOX - S. MATLAB PARALLEL COMPUTING TOOLBOX - S User`s guide Uživatelská příručka

  • Stažení
  • Přidat do mých příruček
  • Tisk
  • Strana
    / 656
  • Tabulka s obsahem
  • ŘEŠENÍ PROBLÉMŮ
  • KNIHY
  • Hodnocené. / 5. Na základě hodnocení zákazníků
Zobrazit stránku 0
Parallel Computing Toolbox™
User's Guide
R2015a
Zobrazit stránku 0
1 2 3 4 5 6 ... 655 656

Shrnutí obsahu

Strany 1 - User's Guide

Parallel Computing Toolbox™User's GuideR2015a

Strany 2 - How to Contact MathWorks

x ContentsJob Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-29Job Monitor GUI . . . . . . . . . . . . . . .

Strany 3 - Revision History

4 Interactive Parallel Computation with pmode4-68Until this point in the example, the variant arrays are independent, other thanhaving the same name.

Strany 4

Run Communicating Jobs Interactively Using pmode4-7P>> combined = gather(whole)Notice, however, that this gathers the entire array into the wor

Strany 5 - Contents

4 Interactive Parallel Computation with pmode4-814If you require distribution along a different dimension, you can use theredistribute function. In th

Strany 6

Run Communicating Jobs Interactively Using pmode4-915Exit pmode and return to the regular MATLAB desktop.P>> pmode exit

Strany 7

4 Interactive Parallel Computation with pmode4-10Parallel Command WindowWhen you start pmode on your local client machine with the commandpmode start

Strany 8

Parallel Command Window4-11You have several options for how to arrange the tiles showing your worker outputs.Usually, you will choose an arrangement

Strany 9

4 Interactive Parallel Computation with pmode4-12P>> distobj = codistributor('1d',1);P>> I = redistribute(I, distobj)When you re

Strany 10

Parallel Command Window4-13You can choose to view the worker outputs by tabs.1. Select tabbeddisplay2. Select tab3. Select labsshown inthis tabYou ca

Strany 11 - Program Independent Jobs

4 Interactive Parallel Computation with pmode4-14Multiple labsin same tab

Strany 12 - GPU Computing

Running pmode Interactive Jobs on a Cluster4-15Running pmode Interactive Jobs on a ClusterWhen you run pmode on a cluster of workers, you are running

Strany 13

xiRun mapreduce on a Hadoop Cluster . . . . . . . . . . . . . . . . . . 6-61Cluster Preparation . . . . . . . . . . . . . . . . . . . . . . . . . . .

Strany 14 - Glossary

4 Interactive Parallel Computation with pmode4-16Plotting Distributed Data Using pmodeBecause the workers running a job in pmode are MATLAB sessions w

Strany 15 - Getting Started

Plotting Distributed Data Using pmode4-17This is not the only way to plot codistributed data. One alternative method, especiallyuseful when running n

Strany 16 - 1 Getting Started

4 Interactive Parallel Computation with pmode4-18pmode Limitations and Unexpected ResultsUsing Graphics in pmodeDisplaying a GUIThe workers that run t

Strany 17

pmode Troubleshooting4-19pmode TroubleshootingIn this section...“Connectivity Testing” on page 4-19“Hostname Resolution” on page 4-19“Socket Connecti

Strany 19 - Partition Large Data Sets

5Math with Codistributed ArraysThis chapter describes the distribution or partition of data across several workers,and the functionality provided for

Strany 20

5 Math with Codistributed Arrays5-2Nondistributed Versus Distributed ArraysIn this section...“Introduction” on page 5-2“Nondistributed Arrays” on page

Strany 21

Nondistributed Versus Distributed Arrays5-3 WORKER 1 WORKER 2 WORKER 3 WORKER 4 | | |8 1 6 | 8

Strany 22 - Run a Batch Job

5 Math with Codistributed Arrays5-4Codistributed ArraysWith replicated and variant arrays, the full content of the array is stored in theworkspace of

Strany 23 - Run a Batch Parallel Loop

Working with Codistributed Arrays5-5Working with Codistributed ArraysIn this section...“How MATLAB Software Distributes Arrays” on page 5-5“Creating

Strany 24

xii ContentsProgram Communicating Jobs8Program Communicating Jobs . . . . . . . . . . . . . . . . . . . . . . . . 8-2Program Communicating Jobs for a

Strany 25

5 Math with Codistributed Arrays5-6end Lab 1: This lab stores D(:,1:250). Lab 2: This lab stores D(:,251:500). Lab 3: This lab stores D(:,501

Strany 26

Working with Codistributed Arrays5-7number is not evenly divisible by the number of workers, MATLAB partitions the arrayas evenly as possible.MATLAB

Strany 27

5 Math with Codistributed Arrays5-8spmd, A = [11:18; 21:28; 31:38; 41:48], endA = 11 12 13 14 15 16 17 18 21 22 23

Strany 28

Working with Codistributed Arrays5-9(local part) on each worker first, and then combine them into a single array that isdistributed across the worker

Strany 29 - Parallel for-Loops (parfor)

5 Math with Codistributed Arrays5-10Constructor FunctionsThe codistributed constructor functions are listed here. Use the codist argument(created by t

Strany 30 - Introduction to parfor

Working with Codistributed Arrays5-11 size(D) L = getLocalPart(D); size(L)endreturns on each worker:3 803 20Each worker recognizes

Strany 31

5 Math with Codistributed Arrays5-12where D is any MATLAB array.Determining the Dimension of DistributionThe codistributor object determines how an ar

Strany 32 - Create a parfor-Loop

Working with Codistributed Arrays5-13Construct an 8-by-16 codistributed array D of random values distributed by columns onfour workers:spmd D = ra

Strany 33 - Create a parfor-Loop

5 Math with Codistributed Arrays5-14 11 12 13 | 14 15 16 | 17 18 | 19 20 21 22 23 | 24 25 26 | 27 28 | 29 30

Strany 34 - 2 Parallel for-Loops (parfor)

Working with Codistributed Arrays5-15to the end of the entire array; that is, the last subscript of the final segment. The lengthof each segment is a

Strany 35

xiiiExample: Run Your MATLAB Code . . . . . . . . . . . . . . . . . . 9-14Supported MATLAB Code . . . . . . . . . . . . . . . . . . . . . . . . . . 9-

Strany 36

5 Math with Codistributed Arrays5-16 Element is in position 25000 on worker 2.Notice if you use a pool of a different size, the element ends up in a

Strany 37

Working with Codistributed Arrays5-17Now you can use this codistributor object to distribute the original matrix:P>> AA = codistributed(A, DIST

Strany 38

5 Math with Codistributed Arrays5-181 9 17 25 33 41 49 572 10 18 26 34 42 50 583 11 19 27 35

Strany 39 - parfor Limitations

Working with Codistributed Arrays5-19The following points are worth noting:• '2dbc' distribution might not offer any performance enhancemen

Strany 40

5 Math with Codistributed Arrays5-20Looping Over a Distributed Range (for-drange)In this section...“Parallelizing a for-Loop” on page 5-20“Codistribut

Strany 41 - Handle Classes

Looping Over a Distributed Range (for-drange)5-21 plot(1:numDataSets, res); print -dtiff -r300 fig.tiff; save \\central\myResults\today.mat

Strany 42

5 Math with Codistributed Arrays5-22D = eye(8, 8, codistributor())E = zeros(8, 8, codistributor())By default, these arrays are distributed by columns;

Strany 43 - Nested Loops

Looping Over a Distributed Range (for-drange)5-23To loop over all elements in the array, you can use for-drange on the dimension ofdistribution, and

Strany 44

5 Math with Codistributed Arrays5-24MATLAB Functions on Distributed and Codistributed ArraysMany functions in MATLAB software are enhanced or overload

Strany 45 - P-Code Scripts

MATLAB Functions on Distributed and Codistributed Arrays5-25atandatanhbesselhbesselibesseljbesselkbesselybetabetaincbetaincinvbetalnbitandbitorbitxor

Strany 46

xiv ContentsObjects — Alphabetical List10Functions — Alphabetical List11Glossary

Strany 48

6Programming OverviewThis chapter provides information you need for programming with Parallel ComputingToolbox software. Further details of evaluating

Strany 49

6 Programming Overview6-2How Parallel Computing Products Run a JobIn this section...“Overview” on page 6-2“Toolbox and Server Components” on page 6-3“

Strany 50

How Parallel Computing Products Run a Job6-3MATLAB WorkerSchedulerMATLAB ClientParallelComputingToolboxMATLAB DistributedComputing ServerMATLAB Worke

Strany 51

6 Programming Overview6-4A MATLAB Distributed Computing Server software setup usually includes manyworkers that can all execute tasks simultaneously,

Strany 52

How Parallel Computing Products Run a Job6-5ClientWorkerWorkerWorkerClientScheduler 2WorkerWorkerWorkerClientClientScheduler 1Cluster with Multiple C

Strany 53 - Loop Variable

6 Programming Overview6-6• Is the handling of parallel computing jobs the only cluster scheduling managementyou need?The MJS is designed specifically

Strany 54

How Parallel Computing Products Run a Job6-7same platform. The cluster can also be comprised of both 32-bit and 64-bit machines,so long as your data

Strany 55 - Sliced Variables

6 Programming Overview6-8ClusterClientWorkerWorkerWorkerJobJobJobJobJobJobJobJobJobJobJobJobJobJobcreateJobsubmitPendingQueued RunningFinishedfetchOut

Strany 56

How Parallel Computing Products Run a Job6-9Job Stage DescriptionFailed When using a third-party scheduler, a job might fail if thescheduler encounte

Strany 57

1Getting Started• “Parallel Computing Toolbox Product Description” on page 1-2• “Parallel Computing with MathWorks Products” on page 1-3• “Key Problem

Strany 58

6 Programming Overview6-10Create Simple Independent JobsProgram a Job on a Local ClusterIn some situations, you might need to define the individual ta

Strany 59 - Broadcast Variables

Create Simple Independent Jobs6-11results = [2] [4] [6]6Delete the job. When you have the results, you can permanently remove the job fromt

Strany 60 - Reduction Variables

6 Programming Overview6-12Parallel PreferencesYou can access parallel preferences in the general preferences for MATLAB. To open thePreferences dialog

Strany 61

Parallel Preferences6-13• Automatically create a parallel pool — This setting causes a pool to automaticallystart if one is not already running at th

Strany 62

6 Programming Overview6-14Clusters and Cluster ProfilesIn this section...“Cluster Profile Manager” on page 6-14“Discover Clusters” on page 6-14“Import

Strany 63

Clusters and Cluster Profiles6-15This opens the Discover Clusters dialog box, where you select the location of yourclusters. As clusters are discover

Strany 64

6 Programming Overview6-16discovery of MJS clusters by identifying specific hosts rather than broadcastingacross your network.A DNS service (SRV) reco

Strany 65 - Reduction Variables

Clusters and Cluster Profiles6-17The imported profile appears in your Cluster Profile Manager list. Note that the listcontains the profile name, whic

Strany 66

6 Programming Overview6-18The following example provides instructions on how to create and modify profiles usingthe Cluster Profile Manager.Suppose yo

Strany 67 - Temporary Variables

Clusters and Cluster Profiles6-19This creates and displays a new profile, called MJSProfile1.2Double-click the new profile name in the listing, and m

Strany 68

1 Getting Started1-2Parallel Computing Toolbox Product DescriptionPerform parallel computations on multicore computers, GPUs, and computer clustersPar

Strany 69 - Temporary Variables

6 Programming Overview6-20You might want to edit other properties depending on your particular network andcluster situation.5Click Done to save the pr

Strany 70 - Improving parfor Performance

Clusters and Cluster Profiles6-215Scroll down to the Workers section, and for the Range of number of workers, clearthe [4 4] and leave the field blan

Strany 71 - Improving parfor Performance

6 Programming Overview6-22You can see examples of profiles for different kinds of supported schedulers in theMATLAB Distributed Computing Server insta

Strany 72 - Parallel Pools

Clusters and Cluster Profiles6-23Note Validation will fail if you already have a parallel pool open.When the tests are complete, you can click Show D

Strany 73 - Start a Parallel Pool

6 Programming Overview6-24• The Cluster Profile Manager indicates which is the default profile. You can select anyprofile in the list, then click Set

Strany 74

Apply Callbacks to MJS Jobs and Tasks6-25Apply Callbacks to MJS Jobs and TasksThe MATLAB job scheduler (MJS) has the ability to trigger callbacks in

Strany 75

6 Programming Overview6-26 disp(['Finished task: ' num2str(task.ID)])Create a job and set its QueuedFcn, RunningFcn, and FinishedFcn prope

Strany 76

Apply Callbacks to MJS Jobs and Tasks6-27Create and save a callback function clientTaskCompleted.m on the path of theMATLAB client, with the followin

Strany 77

6 Programming Overview6-28guarantee to the order in which the tasks finish, so the plots might overwrite eachother. Likewise, the FinishFcn callback f

Strany 78

Job Monitor6-29Job MonitorIn this section...“Job Monitor GUI” on page 6-29“Manage Jobs Using the Job Monitor” on page 6-30“Identify Task Errors Using

Strany 79

Parallel Computing with MathWorks Products1-3Parallel Computing with MathWorks ProductsIn addition to Parallel Computing Toolbox providing a local cl

Strany 80 - When to Use spmd

6 Programming Overview6-30Typical Use CasesThe Job Monitor lets you accomplish many different goals pertaining to job tracking andqueue management. Us

Strany 81 - Define an spmd Statement

Job Monitor6-31If you save this script in a file named invert_me.m, you can try to run the script as abatch job on the default cluster:batch('in

Strany 82

6 Programming Overview6-32Programming TipsIn this section...“Program Development Guidelines” on page 6-32“Current Working Directory of a MATLAB Worker

Strany 83 - Display Output

Programming Tips6-333Modify your code for division. Decide how you want your code divided. Foran independent job, determine how best to divide it int

Strany 84 - Introduction to Composites

6 Programming Overview6-34C:\TEMP\MDCE\Checkpoint\nodeA52_worker22_mlworker_log\workWriting to Files from WorkersWhen multiple workers attempt to writ

Strany 85

Programming Tips6-35clears all Parallel Computing Toolbox objects from the current MATLAB session. Theystill remain in the MJS. For information on re

Strany 86

6 Programming Overview6-36initialize a task is far greater than the actual time it takes for the worker to evaluate thetask function.

Strany 87

Control Random Number Streams6-37Control Random Number StreamsIn this section...“Different Workers” on page 6-37“Client and Workers” on page 6-38“Cli

Strany 88 - Distribute Arrays

6 Programming Overview6-38delete(p)Note Because rng('shuffle') seeds the random number generator based on thecurrent time, you should not us

Strany 89 - Create Codistributed Arrays

Control Random Number Streams6-39For identical results, you can set the client and worker to use the same generator andseed. Here the file randScript

Strany 90

1 Getting Started1-4Key Problems Addressed by Parallel ComputingIn this section...“Run Parallel for-Loops (parfor)” on page 1-4“Execute Batch Jobs in

Strany 91

6 Programming Overview6-40Keyword Generator Multiple Stream andSubstream SupportApproximate Period In FullPrecision'CombRecursive' or'm

Strany 92

Control Random Number Streams6-41Rg = -0.0108 -0.7577 -0.8159 0.4742Worker CPU and Worker GPUCode running on a worker’s CPU uses the same ge

Strany 93

6 Programming Overview6-42Profiling Parallel CodeIn this section...“Introduction” on page 6-42“Collecting Parallel Profile Data” on page 6-42“Viewing

Strany 94

Profiling Parallel Code6-43• Amount of data transferred between each worker• Amount of time each worker spends waiting for communicationsWith the par

Strany 95

6 Programming Overview6-44The function summary report displays the data for each function executed on a worker insortable columns with the following h

Strany 96

Profiling Parallel Code6-45Column Header DescriptionTotal Time Plot Bar graph showing relative size of Self Time, Self Comm WaitingTime, and Total Ti

Strany 97 - P>> x = pi

6 Programming Overview6-46communication. Manual Comparison Selection allows you to compare data fromspecific workers or workers that meet certain crit

Strany 98 - P>> all = numlabs

Profiling Parallel Code6-47The next figure shows a summary report for the workers that spend the most versusleast time for each function. A Manual Co

Strany 99

6 Programming Overview6-48Click on a function name in the summary listing of a comparison to get a detailedcomparison. The detailed comparison for cod

Strany 100

Profiling Parallel Code6-49To see plots of communication data, select Plot All PerLab Communication in theShow Figures menu. The top portion of the p

Strany 101

Key Problems Addressed by Parallel Computing1-5the same machine as the client, you might see significant performance improvement on amulticore/multip

Strany 102 - P>> getLocalPart(I)

6 Programming Overview6-50Plots like those in the previous two figures can help you determine the best way tobalance work among your workers, perhaps

Strany 103 - P>> pmode exit

Benchmarking Performance6-51Benchmarking PerformanceHPC Challenge BenchmarksSeveral MATLAB files are available to illustrate HPC Challenge benchmarkp

Strany 104 - Parallel Command Window

6 Programming Overview6-52Troubleshooting and DebuggingIn this section...“Object Data Size Limitations” on page 6-52“File Access and Permissions” on p

Strany 105 - Select layout

Troubleshooting and Debugging6-53Error using ==> feval Undefined command/function 'function_name'.The worker that ran the task did

Strany 106 - Drag to adjust

6 Programming Overview6-54• MATLAB could not read/write the job input/output files in the scheduler’s job storagelocation. The storage location might

Strany 107 - Select only two tabs

Troubleshooting and Debugging6-55how to start it and how to test connectivity, see “Start Admin Center” and “TestConnectivity” in the MATLAB Distribu

Strany 108 - Multiple labs

6 Programming Overview6-56 Could not send Job3.common.mat for job 3: One of your shell's init files contains a command that is writing t

Strany 109

Run mapreduce on a Parallel Pool6-57Run mapreduce on a Parallel PoolIn this section...“Start Parallel Pool” on page 6-57“Compare Parallel mapreduce”

Strany 110

6 Programming Overview6-58Create two MapReducer objects for specifying the different execution environments formapreduce.inMatlab = mapreducer(0);inPo

Strany 111

Run mapreduce on a Parallel Pool6-59readall(meanDelay) Key Value __________________ ________ 'MeanArrivalDelay&

Strany 112 - Using Graphics in pmode

How to Contact MathWorksLatest news:www.mathworks.comSales and services:www.mathworks.com/sales_and_servicesUser community:www.mathworks.com/matlabcen

Strany 113 - Socket Connections

1 Getting Started1-6Introduction to Parallel SolutionsIn this section...“Interactively Run a Loop in Parallel” on page 1-6“Run a Batch Job” on page 1-

Strany 114

6 Programming Overview6-60Related Examples• “Getting Started with MapReduce”• “Run mapreduce on a Hadoop Cluster”More About• “MapReduce”• “Datastore”

Strany 115

Run mapreduce on a Hadoop Cluster6-61Run mapreduce on a Hadoop ClusterIn this section...“Cluster Preparation” on page 6-61“Output Format and Order” o

Strany 116 - Nondistributed Arrays

6 Programming Overview6-62outputFolder = '/home/user/logs/hadooplog';Note The specified outputFolder must not already exist. The mapreduce o

Strany 117

Run mapreduce on a Hadoop Cluster6-63meanDelay = KeyValueDatastore with properties: Files: { ' .../tmp/alafleur/tpc00621b1_4

Strany 118 - Codistributed Arrays

6 Programming Overview6-64Partition a Datastore in ParallelPartitioning a datastore in parallel, with a portion of the datastore on each worker in apa

Strany 119 - D = codistributed(A)

Partition a Datastore in Parallel6-65 [total,count] = sumAndCountArrivalDelay(ds)sumtime = tocmean = total/counttotal = 17211680count = 24173

Strany 120

6 Programming Overview6-66total = 0;count = 0;parfor ii = 1:N % Get partition ii of the datastore. subds = partition(ds,N,ii); [localTota

Strany 121

Partition a Datastore in Parallel6-67Rather than let the software calculate the number of partitions, you can explicitly setthis value, so that the d

Strany 122

6 Programming Overview6-68mean = 7.1201delete(p);Parallel pool using the 'local' profile is shutting down.You might get some idea of mode

Strany 123

7Program Independent Jobs• “Program Independent Jobs” on page 7-2• “Program Independent Jobs on a Local Cluster” on page 7-3• “Program Independent Job

Strany 124 - Local Arrays

Introduction to Parallel Solutions1-7parforMATLAB®workersMATLAB®clientBecause the iterations run in parallel in other MATLAB sessions, each iteration

Strany 125

7 Program Independent Jobs7-2Program Independent JobsAn Independent job is one whose tasks do not directly communicate with each other, thatis, the ta

Strany 126

Program Independent Jobs on a Local Cluster7-3Program Independent Jobs on a Local ClusterIn this section...“Create and Run Jobs with a Local Cluster”

Strany 127 - Restoring the Full Array

7 Program Independent Jobs7-4Create a Cluster ObjectYou use the parcluster function to create an object in your local MATLAB sessionrepresenting the l

Strany 128

Program Independent Jobs on a Local Cluster7-5c Local Cluster Associated Jobs Number Pending: 1 Number Queued:

Strany 129

7 Program Independent Jobs7-6Fetch the Job’s ResultsThe results of each task’s evaluation are stored in the task object’s OutputArgumentsproperty as a

Strany 130 - 2-Dimensional Distribution

Program Independent Jobs on a Local Cluster7-7evaluation to the local cluster, the scheduler starts a MATLAB worker for each task inthe job, but only

Strany 131

7 Program Independent Jobs7-8Program Independent Jobs for a Supported SchedulerIn this section...“Create and Run Jobs” on page 7-8“Manage Objects in t

Strany 132

Program Independent Jobs for a Supported Scheduler7-9where MATLAB is accessed and many other cluster properties. The exact properties aredetermined b

Strany 133

7 Program Independent Jobs7-10 Modified: false Host: node345 Username: mylogi

Strany 134 - Parallelizing a for-Loop

Program Independent Jobs for a Supported Scheduler7-11 Number Running: 0 Number Finished: 0 Task ID of Errors: []Note that the job’s St

Strany 135 - plot(1:numDataSets, res);

1 Getting Started1-8Run a Batch JobTo offload work from your MATLAB session to run in the background in another session,you can use the batch command.

Strany 136

7 Program Independent Jobs7-12Alternatively, you can create the five tasks with one call to createTask by providing acell array of five cell arrays de

Strany 137

Program Independent Jobs for a Supported Scheduler7-13wait(job1)results = fetchOutputs(job1);Display the results from each task.results{1:5} 0.950

Strany 138

7 Program Independent Jobs7-14Computing Server software or other cluster resources remain in place. When the clientsession ends, only the local refere

Strany 139

Program Independent Jobs for a Supported Scheduler7-15Remove Objects PermanentlyJobs in the cluster continue to exist even after they are finished, a

Strany 140

7 Program Independent Jobs7-16Share Code with the WorkersBecause the tasks of a job are evaluated on different machines, each machine must haveaccess

Strany 141 - Programming Overview

Share Code with the Workers7-17c = parcluster(); % Use defaultjob1 = createJob(c);ap = {'/central/funcs','/dept1/funcs', ...

Strany 142 - 6 Programming Overview

7 Program Independent Jobs7-18more than one task for the job. (Note: Do not confuse this property with the UserDataproperty on any objects in the MATL

Strany 143 - Toolbox and Server Components

Share Code with the Workers7-19manually attached files to determine which code files are necessary for the workers,and to automatically send those fi

Strany 144

7 Program Independent Jobs7-20• taskStartup.m automatically executes on a worker each time the worker beginsevaluation of a task.• poolStartup.m autom

Strany 145

Program Independent Jobs for a Generic Scheduler7-21Program Independent Jobs for a Generic SchedulerIn this section...“Overview” on page 7-21“MATLAB

Strany 146

Introduction to Parallel Solutions1-9batch runs your code on a local worker or a cluster worker, but does not require aparallel pool.You can use batc

Strany 147 - Life Cycle of a Job

7 Program Independent Jobs7-22Client nodeMATLAB clientEnvironmentvariablesSubmitfunctionWorker nodeMATLAB workerEnvironmentvariablesDecodefunctionSche

Strany 148

Program Independent Jobs for a Generic Scheduler7-23testlocation = 'Plant30'c.IndependentSubmitFcn = {@mysubmitfunc, time_limit, testlocati

Strany 149

7 Program Independent Jobs7-24exist before the worker starts. For more information on the decode function, see“MATLAB Worker Decode Function” on page

Strany 150

Program Independent Jobs for a Generic Scheduler7-25Define Scheduler Command to Run MATLAB WorkersThe submit function must define the command necessa

Strany 151

7 Program Independent Jobs7-26This example function uses only the three default arguments. You can haveadditional arguments passed into your submit fu

Strany 152 - Parallel Preferences

Program Independent Jobs for a Generic Scheduler7-27derived from the values of your object properties. This command is inside the for-loop so that yo

Strany 153 - Parallel Preferences

7 Program Independent Jobs7-28'parallel.cluster.generic.independentDecodeFcn'. The remainder of thissection is useful only if you use names

Strany 154 - Clusters and Cluster Profiles

Program Independent Jobs for a Generic Scheduler7-29With those values from the environment variables, the decode function must set theappropriate pro

Strany 155

7 Program Independent Jobs7-30c = parcluster('MyGenericProfile')If your cluster uses a shared file system for workers to access job and task

Strany 156

Program Independent Jobs for a Generic Scheduler7-312. Create a JobYou create a job with the createJob function, which creates a job object in thecli

Strany 157

1 Getting Started1-10parforbatchMATLAB®workersMATLAB®client5To view the results:wait(job)load(job,'A')plot(A)The results look the same as be

Strany 158

7 Program Independent Jobs7-32T = createTask(job1, @rand, 1, {{3,3} {3,3} {3,3} {3,3} {3,3}});In this case, T is a 5-by-1 matrix of task objects.4. Su

Strany 159

Program Independent Jobs for a Generic Scheduler7-33 0.6038 0.0153 0.9318 0.2722 0.7468 0.4660 0.1988 0.4451 0.4186 0.8

Strany 160

7 Program Independent Jobs7-34Filename DescriptiondeleteJobFcn.m Script to delete a job from the schedulerextractJobId.m Script to get the job’s ID fr

Strany 161

Program Independent Jobs for a Generic Scheduler7-35for ii = 1:props.NumberOfTasks define scheduler command per task end submit job to scheduler

Strany 162

7 Program Independent Jobs7-36 command to scheduler canceling job job_idIn a similar way, you can define what do to for deleting a job, and what to

Strany 163

Program Independent Jobs for a Generic Scheduler7-37delete(j1)Get State Information About a Job or TaskWhen using a third-party scheduler, it is poss

Strany 164

7 Program Independent Jobs7-38The following step occurs in your network:1For each task, the scheduler starts a MATLAB worker session on a cluster node

Strany 165

8Program Communicating Jobs• “Program Communicating Jobs” on page 8-2• “Program Communicating Jobs for a Supported Scheduler” on page 8-4• “Program Co

Strany 166

8 Program Communicating Jobs8-2Program Communicating JobsCommunicating jobs are those in which the workers can communicate with each otherduring the e

Strany 167

Program Communicating Jobs8-3Some of the details of a communicating job and its tasks might depend on the type ofscheduler you are using. The followi

Strany 168

Introduction to Parallel Solutions1-11Run Script as Batch Job from the Current Folder BrowserFrom the Current Folder browser, you can run a MATLAB sc

Strany 169 - Job Monitor

8 Program Communicating Jobs8-4Program Communicating Jobs for a Supported SchedulerIn this section...“Schedulers and Conditions” on page 8-4“Code the

Strany 170

Program Communicating Jobs for a Supported Scheduler8-5The function for this example is shown below.function total_sum = colsumif labindex == 1 %

Strany 171 - Job Monitor

8 Program Communicating Jobs8-6When your cluster object is defined, you create the job object with thecreateCommunicatingJob function. The job Type pr

Strany 172 - Programming Tips

Program Communicating Jobs for a Generic Scheduler8-7Program Communicating Jobs for a Generic SchedulerIn this section...“Introduction” on page 8-7“C

Strany 173 - Programming Tips

8 Program Communicating Jobs8-83Use createCommunicatingJob to create a communicating job object for yourcluster.4Create a task, run the job, and retri

Strany 174

Program Communicating Jobs for a Generic Scheduler8-9Filename DescriptiongetSubmitString.m Script to get the submission string for the schedulerThese

Strany 175 - Speeding Up a Job

8 Program Communicating Jobs8-10Further Notes on Communicating JobsIn this section...“Number of Tasks in a Communicating Job” on page 8-10“Avoid Deadl

Strany 176

Further Notes on Communicating Jobs8-11In another example, suppose you want to transfer data from every worker to the nextworker on the right (define

Strany 178

9GPU Computing• “GPU Capabilities and Performance” on page 9-2• “Establish Arrays on a GPU” on page 9-3• “Run Built-In Functions on a GPU” on page 9-8

Strany 179 - Client and GPU

1 Getting Started1-12Distribute Arrays and Run SPMDDistributed ArraysThe workers in a parallel pool communicate with each other, so you can distribute

Strany 180

9 GPU Computing9-2GPU Capabilities and PerformanceIn this section...“Capabilities” on page 9-2“Performance Benchmarking” on page 9-2CapabilitiesParall

Strany 181 - Worker CPU and Worker GPU

Establish Arrays on a GPU9-3Establish Arrays on a GPUIn this section...“Transfer Arrays Between Workspace and GPU” on page 9-3“Create GPU Arrays Dire

Strany 182 - Profiling Parallel Code

9 GPU Computing9-4Transfer Array of a Specified PrecisionCreate a matrix of double-precision random values in MATLAB, and then transfer thematrix as s

Strany 183 - Viewing Parallel Profile Data

Establish Arrays on a GPU9-5For example, to see the help on the colon constructor, typehelp gpuArray/colonExample: Construct an Identity Matrix on th

Strany 184

9 GPU Computing9-6parallel.gpu.RandStreamThese functions perform in the same way as rng and RandStream in MATLAB, butwith certain limitations on the G

Strany 185 - Profiling Parallel Code

Establish Arrays on a GPU9-7For more information about generating random numbers on a GPU, and a comparisonbetween GPU and CPU generation, see “Contr

Strany 186

9 GPU Computing9-8Run Built-In Functions on a GPUIn this section...“MATLAB Functions with gpuArray Arguments” on page 9-8“Example: Functions with gpuA

Strany 187

Run Built-In Functions on a GPU9-9atan2datandatanhbesseljbesselybetabetaincbetaincinvbetalnbitandbitcmpbitgetbitorbitsetbitshiftbitxorblkdiagbsxfunca

Strany 188

9 GPU Computing9-10Ga = rand(1000,'single','gpuArray');Gfft = fft(Ga); Gb = (real(Gfft) + Ga) * 6;G = gather(Gb);The whos command

Strany 189

Run Built-In Functions on a GPU9-11 (1,2) 1 (2,5) 1g = gpuArray(s); % g is a sparse gpuArraygt = transpose(g); % gt is a sparse g

Strany 190

Introduction to Parallel Solutions1-13The line above retrieves the data from worker 3 to assign the value of X. The followingcode sends data to worke

Strany 191 - Benchmarking Performance

9 GPU Computing9-12Function Input Range for Real Outputlog(x) x >= 0log1p(x) x >= -1log10(x) x >= 0log2(x) x >= 0power(x,y) x >= 0reall

Strany 192 - Troubleshooting and Debugging

Run Element-wise MATLAB Code on GPU9-13Run Element-wise MATLAB Code on GPUIn this section...“MATLAB Code vs. gpuArray Objects” on page 9-13“Run Your

Strany 193

9 GPU Computing9-14Example: Run Your MATLAB CodeIn this example, a small function applies correction data to an array of measurementdata. The function

Strany 194

Run Element-wise MATLAB Code on GPU9-15Supported MATLAB CodeThe function you pass into arrayfun or bsxfun can contain the following built-inMATLAB fu

Strany 195 - Caused by:

9 GPU Computing9-16Generate Random Numbers on a GPUThe function you pass to arrayfun or bsxfun for execution on a GPU can contain therandom number gen

Strany 196

Run Element-wise MATLAB Code on GPU9-17for gpuArray” on page 9-5. For more information about generating random numberson a GPU, and a comparison betw

Strany 197 - Compare Parallel mapreduce

9 GPU Computing9-18Identify and Select a GPU DeviceIf you have only one GPU in your computer, that GPU is the default. If you have morethan one GPU de

Strany 198

Identify and Select a GPU Device9-19 AvailableMemory: 4.9190e+09 MultiprocessorCount: 13 ClockRateKHz: 614500

Strany 199 - See Also

9 GPU Computing9-20Run CUDA or PTX Code on GPUIn this section...“Overview” on page 9-20“Create a CUDAKernel Object” on page 9-21“Run a CUDAKernel” on

Strany 200

Run CUDA or PTX Code on GPU9-21The following sections provide details of these commands and workflow steps.Create a CUDAKernel Object• “Compile a PTX

Strany 201 - Calculate Mean Delay

1 Getting Started1-14Determine Product Installation and VersionsTo determine if Parallel Computing Toolbox software is installed on your system, typet

Strany 202

9 GPU Computing9-22k = parallel.gpu.CUDAKernel('myfun.ptx','float *, const float *, float');Another use for C prototype input is w

Strany 203 - More About

Run CUDA or PTX Code on GPU9-23Integer Typesint8_T, int16_T, int32_T, int64_Tuint8_T, uint16_T, uint32_T, uint64_TThe header file is shipped as matla

Strany 204

9 GPU Computing9-24These rules have some implications. The most notable is that every output from a kernelmust necessarily also be an input to the ker

Strany 205

Run CUDA or PTX Code on GPU9-25__global__ void simplestKernelEver( float * x, float val )then the PTX code contains an entry that might be called_Z18

Strany 206

9 GPU Computing9-26• GridSize — A vector of three elements, the product of which determines the numberof blocks.• ThreadBlockSize — A vector of three

Strany 207

Run CUDA or PTX Code on GPU9-27Use gpuArray VariablesIt might be more efficient to use gpuArray objects as input when running a kernel:k = parallel.g

Strany 208

9 GPU Computing9-28The input values x1 and x2 correspond to pInOut and c in the C function prototype. Theoutput argument y corresponds to the value of

Strany 209

Run CUDA or PTX Code on GPU9-292Compile the CU code at the shell command line to generate a PTX file calledtest.ptx.nvcc -ptx test.cu3Create the kern

Strany 210

9 GPU Computing9-304Before you run the kernel, set the number of threads correctly for the vectors youwant to add.N = 128;k.ThreadBlockSize = N;in1 =

Strany 211

Run MEX-Functions Containing CUDA Code9-31Run MEX-Functions Containing CUDA CodeIn this section...“Write a MEX-File Containing CUDA Code” on page 9-3

Strany 212 - 7 Program Independent Jobs

2Parallel for-Loops (parfor)• “Introduction to parfor” on page 2-2• “Create a parfor-Loop” on page 2-4• “Comparing for-Loops and parfor-Loops” on page

Strany 213

9 GPU Computing9-32{ int i = blockDim.x * blockIdx.x + threadIdx.x; if (i < N) B[i] = 2.0 * A[i];}It contains the following lines to d

Strany 214

Run MEX-Functions Containing CUDA Code9-33Compile a GPU MEX-FileWhen you have set up the options file, use the mex command in MATLAB to compilea MEX-

Strany 215

9 GPU Computing9-34• MEX-files can analyze the size of the input and allocate memory of a different size,or launch grids of a different size, from C o

Strany 216

Measure and Improve GPU Performance9-35Measure and Improve GPU PerformanceIn this section...“Basic Workflow for Improving Performance” on page 9-35“A

Strany 217 - Properties

9 GPU Computing9-36you might need to vectorize your code, replacing looped scalar operations with MATLABmatrix and vector operations. While vectorizin

Strany 218

Measure and Improve GPU Performance9-37on the GPU, rewrites the code to use arrayfun for element-wise operations, and finallyshows how to integrate a

Strany 219

9 GPU Computing9-38if you make that the first dimension. Similarly, if you frequently operate along aparticular dimension, it is usually best to have

Strany 220

Measure and Improve GPU Performance9-39repeating the timed operation to get better resolution, executing the function beforemeasurement to avoid init

Strany 221

9 GPU Computing9-40transform of a filter vector, transforms back to the time domain, and stores the result inan output matrix.function y = fastConvolu

Strany 222

Measure and Improve GPU Performance9-41On the same machine, this code displays the output:Execution time on CPU = 0.019335Execution time on GPU = 0.0

Strany 223

Revision HistoryNovember 2004 Online only New for Version 1.0 (Release 14SP1+)March 2005 Online only Revised for Version 1.0.1 (Release 14SP2)Septembe

Strany 224 - Share Code with the Workers

2 Parallel for-Loops (parfor)2-2Introduction to parforIn this section...“parfor-Loops in MATLAB” on page 2-2“Deciding When to Use parfor” on page 2-2p

Strany 225

9 GPU Computing9-42Execution time on GPU = 0.0020537Maximum absolute error = 1.1374e-14In conclusion, vectorizing the code helps both the CPU and GPU

Strany 226

10Objects — Alphabetical List

Strany 227 - Share Code with the Workers

10 Objects — Alphabetical List10-2codistributedAccess elements of arrays distributed among workers in parallel poolConstructorcodistributed, codistrib

Strany 228

codistributed10-3Also among the methods there are several for examining the characteristics of the arrayitself. Most behave like the MATLAB functions

Strany 229 - Overview

10 Objects — Alphabetical List10-4codistributor1d1-D distribution scheme for codistributed arrayConstructorcodistributor1dDescriptionA codistributor1d

Strany 230

codistributor2dbc10-5codistributor2dbc2-D block-cyclic distribution scheme for codistributed arrayConstructorcodistributor2dbcDescriptionA codistribu

Strany 231 - Scheduler

10 Objects — Alphabetical List10-6CompositeAccess nondistributed variables on multiple workers from clientConstructorCompositeDescriptionVariables tha

Strany 232

CUDAKernel10-7CUDAKernelKernel executable on GPUConstructorparallel.gpu.CUDAKernelDescriptionA CUDAKernel object represents a CUDA kernel, that can e

Strany 233

10 Objects — Alphabetical List10-8Property Name Descriptioncorresponding element in the vector of the MaxGridSize propertyof the GPUDevice object.Shar

Strany 234

CUDAKernel10-9See AlsogpuArray, GPUDevice

Strany 235 - MATLAB Worker Decode Function

Introduction to parfor2-3one when you have only a small number of simple calculations. The examples of thissection are only to illustrate the behavio

Strany 236

10 Objects — Alphabetical List10-10distributedAccess elements of distributed arrays from clientConstructordistributedYou can also create a distributed

Strany 237

distributed10-11MethodsThe overloaded methods for distributed arrays are too numerous to list here. Mostresemble and behave the same as built-in MATL

Strany 238

10 Objects — Alphabetical List10-12gpuArrayArray stored on GPUConstructorgpuArray converts an array in the MATLAB workspace into a gpuArray with eleme

Strany 239

gpuArray10-13DescriptionA gpuArray object represents an array stored on the GPU. You can use the array fordirect calculations, or in CUDA kernels tha

Strany 240

10 Objects — Alphabetical List10-14GPUDeviceGraphics processing unit (GPU)ConstructorgpuDeviceDescriptionA GPUDevice object represents a graphic proce

Strany 241

GPUDevice10-15where methodname is the name of the method. For example, to get help onisAvailable, typehelp parallel.gpu.GPUDevice.isAvailableProperti

Strany 242

10 Objects — Alphabetical List10-16Property Name DescriptionClockRateKHz Peak clock rate of the GPU in kHz.ComputeMode The compute mode of the device,

Strany 243

mxGPUArray10-17mxGPUArrayType for MATLAB gpuArrayDescriptionmxGPUArray is an opaque C language type that allows a MEX function access to theelements

Strany 244

10 Objects — Alphabetical List10-18See AlsogpuArray, mxArray

Strany 245

parallel.Cluster10-19parallel.ClusterAccess cluster properties and behaviorsConstructorsparclustergetCurrentCluster (in the workspace of the MATLAB w

Strany 246

2 Parallel for-Loops (parfor)2-4Create a parfor-LoopThe safest approach when creating a parfor-loop is to assume that iterations areperformed on diffe

Strany 247

10 Objects — Alphabetical List10-20Cluster Type Descriptionparallel.cluster.HPCServer Interact with CJS cluster running WindowsMicrosoft HPC Serverpar

Strany 248

parallel.Cluster10-21Property DescriptionHost Host name of the cluster head nodeJobStorageLocation Location where cluster stores job and taskinformat

Strany 249 - Program Communicating Jobs

10 Objects — Alphabetical List10-22Property DescriptionSecurityLevel Degree of security applied to cluster and itsjobs. For descriptions of security l

Strany 250 - 8 Program Communicating Jobs

parallel.Cluster10-23Property DescriptionRcpCommand Command to copy files to and from clientResourceTemplate Define resources to request forcommunica

Strany 251 - Code in the Client

10 Objects — Alphabetical List10-24Property DescriptionDeleteTaskFcn Function to run when deleting taskGetJobStateFcn Function to run when querying jo

Strany 252

parallel.cluster.Hadoop10-25parallel.cluster.HadoopHadoop cluster for mapreducerConstructorsparallel.cluster.HadoopDescriptionA parallel.cluster.Hado

Strany 253

10 Objects — Alphabetical List10-26Property DescriptionRequiresMathWorksHostedLicensing Specify whether cluster uses MathWorkshosted licensingHelpFor

Strany 254

parallel.Future10-27parallel.FutureRequest function execution on parallel pool workersConstructorsparfeval, parfevalOnAllContainer HierarchyParent pa

Strany 255

10 Objects — Alphabetical List10-28Method Descriptioncancel Cancel queued or running futurefetchNext Retrieve next available unread futureoutputs (Fev

Strany 256

parallel.Future10-29help parallel.FevalFuturehelp parallel.FevalOnAllFutureSee Alsoparallel.Pool

Strany 257

Create a parfor-Loop2-5• “Comparing for-Loops and parfor-Loops” on page 2-6• “Reductions: Cumulative Values Updated by Each Iteration” on page 2-8• “

Strany 258

10 Objects — Alphabetical List10-30parallel.JobAccess job properties and behaviorsConstructorscreateCommunicatingJob, createJob, findJob, recreategetC

Strany 259

parallel.Job10-31MethodsAll job type objects have the same methods, described in the following table.PropertiesCommon to All Job TypesThe following p

Strany 260 - 9 GPU Computing

10 Objects — Alphabetical List10-32Property DescriptionUserData Information associated with job objectUsername Name of user who owns jobMJS JobsMJS in

Strany 261 - Establish Arrays on a GPU

parallel.Job10-33HelpTo get further help on a particular type of parallel.Job object, including a list of links tohelp for its properties, type help

Strany 262

10 Objects — Alphabetical List10-34parallel.PoolAccess parallel poolConstructorsparpool, gcpDescriptionA parallel.Pool object provides access to a par

Strany 263

parallel.Pool10-35HelpTo get further help on parallel.Pool objects, including a list of links to help for specificproperties, type:help parallel.Pool

Strany 264

10 Objects — Alphabetical List10-36parallel.TaskAccess task properties and behaviorsConstructorscreateTask, findTaskgetCurrentTask (in the workspace o

Strany 265 - 100 100

parallel.Task10-37PropertiesCommon to All Task TypesThe following properties are common to all task object types.Property DescriptionCaptureDiary Spe

Strany 266

10 Objects — Alphabetical List10-38MJS TasksMJS task objects have the following properties in addition to the common properties:Property DescriptionFa

Strany 267

parallel.Worker10-39parallel.WorkerAccess worker that ran taskConstructorsgetCurrentWorker in the workspace of the MATLAB worker.In the client worksp

Strany 268

2 Parallel for-Loops (parfor)2-6Comparing for-Loops and parfor-LoopsBecause parfor-loops are not quite the same as for-loops, there are specific behav

Strany 269

10 Objects — Alphabetical List10-40PropertiesMJS WorkerThe following table describes the properties of an MJS worker.Property DescriptionAllHostAddres

Strany 270

RemoteClusterAccess10-41RemoteClusterAccessConnect to schedulers when client utilities are not available locallyConstructorr = parallel.cluster.Remot

Strany 271

10 Objects — Alphabetical List10-42MethodsMethod Name Descriptionconnect connect(r,clusterHost) establishes a connection to thespecified host using th

Strany 272

RemoteClusterAccess10-43Method Name DescriptionrunCommand [status,result] = runCommand(r,command) runsthe supplied command on the remote host and ret

Strany 273 - Supported MATLAB Code

10 Objects — Alphabetical List10-44Property Name DescriptionJobStorageLocation Location on the remote host for files that are being mirrored.UseIdenti

Strany 274

11Functions — Alphabetical List

Strany 275

11 Functions — Alphabetical List11-2addAttachedFilesAttach files or folders to parallel poolSyntaxaddAttachedFiles(poolobj,files)DescriptionaddAttache

Strany 276

addAttachedFiles11-3Files or folders to attach, specified as a string or cell array of strings. Each string canspecify either an absolute or relative

Strany 277

11 Functions — Alphabetical List11-4arrayfunApply function to each element of array on GPUSyntaxA = arrayfun(FUN, B)A = arrayfun(FUN,B,C,...)[A,B,...]

Strany 278 - Run CUDA or PTX Code on GPU

arrayfun11-5all have the same size or be scalar. Any scalar inputs are scalar expanded before beinginput to the function FUN.One or more of the input

Strany 279 - Create a CUDAKernel Object

Comparing for-Loops and parfor-Loops2-7parfor-loop requires that each iteration be independent of the other iterations, and thatall code that follows

Strany 280

11 Functions — Alphabetical List11-6R2 = rand(2,1,4,3,'gpuArray');R3 = rand(1,5,4,3,'gpuArray');R = arrayfun(@(x,y,z)(x+y.*z),R1,R

Strany 281 - Run CUDA or PTX Code on GPU

arrayfun11-7 o2 400x400 108 gpuArray s1 400x400 108 gpuArray s2 400x400 108 gpuArray s3

Strany 282

11 Functions — Alphabetical List11-8batchRun MATLAB script or function on workerSyntaxj = batch('aScript')j = batch(myCluster,'aScript&

Strany 283

batch11-9j = batch(fcn,N,{x1, ..., xn}) runs the function specified by a function handleor function name, fcn, on a worker in the cluster identified

Strany 284

11 Functions — Alphabetical List11-10is the cwd of MATLAB when the batch command is executed. If the string for thisargument is '.', there i

Strany 285

batch11-11Clean up a batch job’s data after you are finished with it:delete(j)Run a batch function on a cluster that generates a 10-by-10 random matr

Strany 286

11 Functions — Alphabetical List11-12bsxfunBinary singleton expansion function for gpuArraySyntaxC = bsxfun(FUN,A,B)Descriptionbsxfun with gpuArray in

Strany 287

bsxfun11-13size(R) 2 5 4 3R1 = rand(2,2,0,4,'gpuArray');R2 = rand(2,1,1,4,'gpuArray');R = bsxfun(@plus,R1,R2);size(R

Strany 288

11 Functions — Alphabetical List11-14cancelCancel job or taskSyntaxcancel(t)cancel(j)Argumentst Pending or running task to cancel.j Pending, running,

Strany 289

cancel11-15c = parcluster();job1 = createJob(c);t = createTask(job1, @rand, 1, {3,3});cancel(t)t Task with properties: ID: 1

Strany 290

2 Parallel for-Loops (parfor)2-8Reductions: Cumulative Values Updated by Each IterationThese two examples show parfor-loops using reduction assignment

Strany 291 - Comparison to a CUDA Kernel

11 Functions — Alphabetical List11-16cancel (FevalFuture)Cancel queued or running futureSyntaxcancel(F)Descriptioncancel(F) stops the queued and runni

Strany 292

cancel (FevalFuture)11-17See AlsofetchOutputs | isequal | parfeval | parfevalOnAll | fetchNext

Strany 293

11 Functions — Alphabetical List11-18changePasswordPrompt user to change MJS passwordSyntaxchangePassword(mjs)changePassword(mjs,username)Argumentsmjs

Strany 294

changePassword11-19Change your password for the MJS cluster on which the parallel pool is running.p = gcp;mjs = p.Cluster;changePassword(mjs)See Also

Strany 295

11 Functions — Alphabetical List11-20classUnderlyingClass of elements within gpuArray or distributed arraySyntaxC = classUnderlying(D)DescriptionC = c

Strany 296

classUnderlying11-21c1 = classUnderlying(D1)c8 =uint8c1 =singleSee Alsodistributed | codistributed | gpuArray

Strany 297

11 Functions — Alphabetical List11-22clearRemove objects from MATLAB workspaceSyntaxclear objArgumentsobj An object or an array of objects.Description

Strany 298

clear11-23 1isequal (job1copy, j2)ans = 0More AboutTipsIf obj references an object in the cluster, it is cleared from the workspace, but it r

Strany 299

11 Functions — Alphabetical List11-24codistributedCreate codistributed array from replicated local dataSyntaxC = codistributed(X)C = codistributed(X,c

Strany 300

codistributed11-25ExamplesCreate a 1000-by-1000 codistributed array C1 using the default distribution scheme.spmd N = 1000; X = magic(N);

Strany 301

Reductions: Cumulative Values Updated by Each Iteration2-9More About• “Introduction to parfor” on page 2-2• “Comparing for-Loops and parfor-Loops” on

Strany 302 - Description

11 Functions — Alphabetical List11-26codistributed.buildCreate codistributed array from distributed dataSyntaxD = codistributed.build(L, codist)D = co

Strany 303 - codistributed

codistributed.build11-27 % Distribute the matrix over the second dimension (columns), % and let the codistributor derive the partition from the

Strany 304 - Properties

11 Functions — Alphabetical List11-28codistributed.cellCreate codistributed cell arraySyntaxC = codistributed.cell(n)C = codistributed.cell(m, n, p, .

Strany 305

codistributed.cell11-29 C = cell(8, codistributor1d());endC = cell(m, n, p, ..., codist) and C = cell([m, n, p, ...],codist) are the same as C = c

Strany 306 - Composite

11 Functions — Alphabetical List11-30codistributed.colonDistributed colon operationSyntaxcodistributed.colon(a,d,b)codistributed.colon(a,b)codistribut

Strany 307 - CUDAKernel

codistributed.colon11-31spmd(4); C = codistributed.colon(1,10), endLab 1: This worker stores C(1:3). LocalPart: [1 2 3] Codistributor

Strany 308

11 Functions — Alphabetical List11-32codistributed.spallocAllocate space for sparse codistributed matrixSyntaxSD = codistributed.spalloc(M, N, nzmax)S

Strany 309

codistributed.spalloc11-33 SD = codistributed.spalloc(N, N, 2*N); for ii=1:N-1 SD(ii,ii:ii+1) = [ii ii]; endendSee Alsospalloc | sparse

Strany 310

11 Functions — Alphabetical List11-34codistributed.speyeCreate codistributed sparse identity matrixSyntaxCS = codistributed.speye(n)CS = codistributed

Strany 311 - distributed

codistributed.speye11-35CS = speye(m, n, codist) and CS = speye([m, n], codist) are the same asCS = codistributed.speye(m, n) and CS = codistributed.

Strany 312

2 Parallel for-Loops (parfor)2-10parfor Programming ConsiderationsIn this section...“MATLAB Path” on page 2-10“Error Handling” on page 2-10MATLAB Path

Strany 313

11 Functions — Alphabetical List11-36codistributed.sprandCreate codistributed sparse array of uniformly distributed pseudo-random valuesSyntaxCS = cod

Strany 314 - GPUDevice

codistributed.sprand11-37spmd(4) CS = codistributed.sprand(1000, 1000, .001);endcreates a 1000-by-1000 sparse codistributed double array CS with a

Strany 315

11 Functions — Alphabetical List11-38codistributed.sprandnCreate codistributed sparse array of uniformly distributed pseudo-random valuesSyntaxCS = co

Strany 316

codistributed.sprandn11-39spmd(4) CS = codistributed.sprandn(1000, 1000, .001);endcreates a 1000-by-1000 sparse codistributed double array CS with

Strany 317

11 Functions — Alphabetical List11-40codistributorCreate codistributor object for codistributed arraysSyntaxcodist = codistributor()codist = codistrib

Strany 318

codistributor11-41codist = codistributor('2dbc') forms a 2-D block-cyclic codistributor object. Formore information about '2dbc'

Strany 319 - Container Hierarchy

11 Functions — Alphabetical List11-42ASee Alsocodistributed | codistributor1d | codistributor2dbc | getCodistributor |getLocalPart | redistribute

Strany 320

codistributor1d11-43codistributor1dCreate 1-D codistributor object for codistributed arraysSyntaxcodist = codistributor1d()codist = codistributor1d(d

Strany 321 - parallel.Cluster

11 Functions — Alphabetical List11-44To use a default dimension, specify codistributor1d.unsetDimension forthat argument; the distribution dimension i

Strany 322 - PBS Pro and TORQUE

codistributor1d.defaultPartition11-45codistributor1d.defaultPartitionDefault partition for codistributed arraySyntaxP = codistributor1d.defaultPartit

Strany 323

parfor Limitations2-11parfor LimitationsMost of these restrictions result from the need for loop iterations to be completelyindependent of each other

Strany 324

11 Functions — Alphabetical List11-46codistributor2dbcCreate 2-D block-cyclic codistributor object for codistributed arraysSyntaxcodist = codistributo

Strany 325

codistributor2dbc11-47codist = codistributor2dbc(lbgrid,blksize,orient,gsize) formsa codistributor object that distributes arrays with the global siz

Strany 326

11 Functions — Alphabetical List11-48codistributor2dbc.defaultLabGridDefault computational grid for 2-D block-cyclic distributed arraysSyntaxgrid = co

Strany 327

Composite11-49CompositeCreate Composite objectSyntaxC = Composite()C = Composite(nlabs)DescriptionC = Composite() creates a Composite object on the c

Strany 328

11 Functions — Alphabetical List11-50ExamplesThe following examples all use a local parallel pool of four workers, opened with thestatement:p = parpoo

Strany 329

Composite11-51d = distributed([3 1 4 2]); % One integer per workerspmd c = getLocalPart(d); % Unique value on each workerendc{:} 3 1

Strany 330

11 Functions — Alphabetical List11-52createCommunicatingJobCreate communicating job on clusterSyntaxjob = createCommunicatingJob(cluster)job = createC

Strany 331

createCommunicatingJob11-53simultaneously on all workers, and lab* functions can be used for communicationbetween workers.job = createCommunicatingJo

Strany 332 - CJS Jobs

11 Functions — Alphabetical List11-54Delete the job from the cluster.delete(j);See AlsocreateJob | createTask | findJob | parcluster | recreate | subm

Strany 333

createJob11-55createJobCreate independent job on clusterSyntaxobj = createJob(cluster)obj = createJob(...,'p1',v1,'p2',v2,...)job

Strany 335

2 Parallel for-Loops (parfor)2-12Inputs and Outputs in parfor-LoopsIn this section...“Functions with Interactive Inputs” on page 2-12“Displaying Outpu

Strany 336

11 Functions — Alphabetical List11-56is not specified and the cluster has a value specified in its 'Profile' property, thecluster’s profile

Strany 337

createJob11-57 {'myapp/folderA','myapp/folderB','myapp/file1.m'});See AlsocreateCommunicatingJob | createTask |

Strany 338

11 Functions — Alphabetical List11-58createTaskCreate new task in jobSyntaxt = createTask(j, F, N, {inputargs})t = createTask(j, F, N, {C1,...,Cm})t =

Strany 339

createTask11-59by a function handle or function name F, with the given input arguments {inputargs},returning N output arguments.t = createTask(j, F,

Strany 340

11 Functions — Alphabetical List11-60Run the job.submit(j);Wait for the job to finish running, and get the output from the task evaluation.wait(j);tas

Strany 341 - RemoteClusterAccess

delete11-61deleteRemove job or task object from cluster and memorySyntaxdelete(obj)Descriptiondelete(obj) removes the job or task object, obj, from t

Strany 342

11 Functions — Alphabetical List11-62Delete all jobs on the cluster identified by the profile myProfile:myCluster = parcluster('myProfile');

Strany 343

delete (Pool)11-63delete (Pool)Shut down parallel poolSyntaxdelete(poolobj)Descriptiondelete(poolobj) shuts down the parallel pool associated with th

Strany 344 - Examples

11 Functions — Alphabetical List11-64demoteDemote job in cluster queueSyntaxdemote(c,job)Argumentsc Cluster object that contains the job.job Job objec

Strany 345

demote11-65Examine the new queue sequence:[pjobs,qjobs,rjobs,fjobs] = findJob(c);get(qjobs,'Name') 'Job A' 'Job C&apos

Strany 346 - Input Arguments

Objects and Handles in parfor-Loops2-13Objects and Handles in parfor-LoopsIn this section...“Using Objects in parfor-Loops” on page 2-13“Handle Class

Strany 347

11 Functions — Alphabetical List11-66diaryDisplay or save Command Window text of batch jobSyntaxdiary(job)diary(job, 'filename')Argumentsjob

Strany 348

distributed11-67distributedCreate distributed array from data in client workspaceSyntaxD = distributed(X)DescriptionD = distributed(X) creates a dist

Strany 349 - arrayfun

11 Functions — Alphabetical List11-68D1 = distributed(magic(Nsmall));Create a large distributed array directly, using a build method:Nlarge = 1000;D2

Strany 350

distributed.cell11-69distributed.cellCreate distributed cell arraySyntaxD = distributed.cell(n)D = distributed.cell(m, n, p, ...)D = distributed.cell

Strany 351

11 Functions — Alphabetical List11-70distributed.spallocAllocate space for sparse distributed matrixSyntaxSD = distributed.spalloc(M, N, nzmax)Descrip

Strany 352 - Arguments

distributed.speye11-71distributed.speyeCreate distributed sparse identity matrixSyntaxDS = distributed.speye(n)DS = distributed.speye(m, n)DS = distr

Strany 353

11 Functions — Alphabetical List11-72distributed.sprandCreate distributed sparse array of uniformly distributed pseudo-random valuesSyntaxDS = distrib

Strany 354

distributed.sprandn11-73distributed.sprandnCreate distributed sparse array of normally distributed pseudo-random valuesSyntaxDS = distributed.sprandn

Strany 355

11 Functions — Alphabetical List11-74dloadLoad distributed arrays and Composite objects from diskSyntaxdloaddload filenamedload filename Xdload filena

Strany 356

dload11-75When loading Composite objects, the data is sent to the available parallel pool workers. Ifthe Composite is too large to fit on the current

Strany 357

2 Parallel for-Loops (parfor)2-14B = @sin;for ii = 1:100 A(ii) = B(ii);endA corresponding parfor-loop does not allow B to reference a function hand

Strany 358

11 Functions — Alphabetical List11-76dsaveSave workspace distributed arrays and Composite objects to diskSyntaxdsavedsave filenamedsave filename Xdsav

Strany 359

dsave11-77See Alsosave | distributed | Composite | dload | parpool

Strany 360

11 Functions — Alphabetical List11-78existCheck whether Composite is defined on workersSyntaxh = exist(C,labidx)h = exist(C)Descriptionh = exist(C,lab

Strany 361

existsOnGPU11-79existsOnGPUDetermine if gpuArray or CUDAKernel is available on GPUSyntaxTF = existsOnGPU(DATA)DescriptionTF = existsOnGPU(DATA) retur

Strany 362

11 Functions — Alphabetical List11-80 4 14 15 1reset(g);M_exists = existsOnGPU(M) 0M % Try to display gpuArrayData no longer exists

Strany 363

eye11-81eyeIdentity matrixSyntaxE = eye(sz,arraytype)E = eye(sz,datatype,arraytype)E = eye(sz,'like',P)E = eye(sz,datatype,'like'

Strany 364

11 Functions — Alphabetical List11-82Argument Values Descriptions'uint8', 'int16','uint16','int32','uint3

Strany 365

eye11-83D = eye(1000,'distributed');Create Codistributed Identity MatrixCreate a 1000-by-1000 codistributed double identity matrix, distrib

Strany 366

11 Functions — Alphabetical List11-84falseArray of logical 0 (false)SyntaxF = false(sz,arraytype)F = false(sz,'like',P)C = false(sz,codist)C

Strany 367

false11-85see the reference pages for codistributor1d and codistributor2dbc. To usethe default distribution scheme, you can specify a codistributor c

Strany 368

Nesting and Flow in parfor-Loops2-15Nesting and Flow in parfor-LoopsIn this section...“Nested Functions” on page 2-15“Nested Loops” on page 2-15“Nest

Strany 369

11 Functions — Alphabetical List11-86Each worker contains a 100-by-labindex local piece of C.Create gpuArray False MatrixCreate a 1000-by-1000 gpuArra

Strany 370

fetchNext11-87fetchNextRetrieve next available unread FevalFuture outputsSyntax[idx,B1,B2,...,Bn] = fetchNext(F)[idx,B1,B2,...,Bn] = fetchNext(F,TIME

Strany 371

11 Functions — Alphabetical List11-88end% Build a waitbar to track progressh = waitbar(0,'Waiting for FevalFutures to complete...');results

Strany 372

fetchOutputs (job)11-89fetchOutputs (job)Retrieve output arguments from all tasks in jobSyntaxdata = fetchOutputs(job)Descriptiondata = fetchOutputs(

Strany 373

11 Functions — Alphabetical List11-90Wait for the job to finish and retrieve the random matrix:wait(j)data = fetchOutputs(j);data{1}

Strany 374

fetchOutputs (FevalFuture)11-91fetchOutputs (FevalFuture)Retrieve all output arguments from FutureSyntax[B1,B2,...,Bn] = fetchOutputs(F)[B1,B2,...,Bn

Strany 375

11 Functions — Alphabetical List11-920.0048 0.9658 0.8488Create an FevalFuture vector, and fetch all its outputs.for idx = 1:10 F(idx) = parf

Strany 376

feval11-93fevalEvaluate kernel on GPUSyntaxfeval(KERN, x1, ..., xn)[y1, ..., ym] = feval(KERN, x1, ..., xn)Descriptionfeval(KERN, x1, ..., xn) evalua

Strany 377

11 Functions — Alphabetical List11-94[y1, y2] = feval(KERN, x1, x2, x3) The three input arguments, x1, x2, and x3, correspond to the three argument

Strany 378

findJob11-95findJobFind job objects stored in clusterSyntaxout = findJob(c)[pending queued running completed] = findJob(c)out = findJob(c,'p1&ap

Strany 379

2 Parallel for-Loops (parfor)2-16Limitations of Nested for-LoopsFor proper variable classification, the range of a for-loop nested in a parfor must be

Strany 380

11 Functions — Alphabetical List11-96completed jobs include those that failed. Jobs that are deleted or whose status isunavailable are not returned by

Strany 381

findTask11-97findTaskTask objects belonging to job objectSyntaxtasks = findTask(j)[pending running completed] = findTask(j)tasks = findTask(j,'p

Strany 382

11 Functions — Alphabetical List11-98specified property-value pairs, p1, v1, p2, v2, etc. The property name must be in theform of a string, with the v

Strany 383

for11-99forfor-loop over distributed rangeSyntaxfor variable = drange(colonop) statement ... statementendDescriptionThe general format isfor

Strany 384

11 Functions — Alphabetical List11-100ExamplesFind the rank of magic squares. Access only the local portion of a codistributed array.r = zeros(1, 40,

Strany 385

gather11-101gatherTransfer distributed array or gpuArray to local workspaceSyntaxX = gather(A)X = gather(C,lab)DescriptionX = gather(A) can operate i

Strany 386

11 Functions — Alphabetical List11-102n = 10;spmd C = codistributed(magic(n)); M = gather(C) % Gather all elements to all workersendS = gather(C)

Strany 387

gather11-103W 1024x1 8192 doubleMore AboutTipsNote that gather assembles the codistributed or distributed array in the workspaces of

Strany 388

11 Functions — Alphabetical List11-104gcatGlobal concatenationSyntaxXs = gcat(X)Xs = gcat(X, dim)Xs = gcat(X, dim, targetlab)DescriptionXs = gcat(X) c

Strany 389

gcp11-105gcpGet current parallel poolSyntaxp = gcpp = gcp('nocreate')Descriptionp = gcp returns a parallel.Pool object representing the cur

Strany 390

Nesting and Flow in parfor-Loops2-17Invalid Valid disp(A(i, 1))end end disp(v(1)) A(i, :) = v;endInside a parfor, if you use multiple for

Strany 391

11 Functions — Alphabetical List11-106delete(gcp('nocreate'))See AlsoComposite | delete | distributed | parfeval | parfevalOnAll | parfor |p

Strany 392

getAttachedFilesFolder11-107getAttachedFilesFolderFolder into which AttachedFiles are writtenSyntaxfolder = getAttachedFilesFolderArgumentsfolder Str

Strany 393

11 Functions — Alphabetical List11-108getCodistributorCodistributor object for existing codistributed arraySyntaxcodist = getCodistributor(D)Descripti

Strany 394

getCodistributor11-109 ornt = codist2.OrientationendDemonstrate that these codistributor objects are complete:spmd (4) isComplete(codist1)

Strany 395

11 Functions — Alphabetical List11-110getCurrentClusterCluster object that submitted current taskSyntaxc = getCurrentClusterArgumentsc The cluster obj

Strany 396

getCurrentCluster11-111See AlsogetAttachedFilesFolder | getCurrentJob | getCurrentTask |getCurrentWorker

Strany 397

11 Functions — Alphabetical List11-112getCurrentJobJob object whose task is currently being evaluatedSyntaxjob = getCurrentJobArgumentsjob The job obj

Strany 398

getCurrentTask11-113getCurrentTaskTask object currently being evaluated in this worker sessionSyntaxtask = getCurrentTaskArgumentstask The task objec

Strany 399

11 Functions — Alphabetical List11-114getCurrentWorkerWorker object currently running this sessionSyntaxworker = getCurrentWorkerArgumentsworker The w

Strany 400

getCurrentWorker11-115j = createJob(c);j.AttachedFiles = {'identifyWorkerHost.m'};t = createTask(j,@identifyWorkerHost,1,{});submit(j)wait(

Strany 401

2 Parallel for-Loops (parfor)2-18More About• “parfor Limitations” on page 2-11• “Convert Nested for-Loops to parfor” on page 2-48

Strany 402

11 Functions — Alphabetical List11-116getDebugLogRead output messages from job run in CJS clusterSyntaxstr = getDebugLog(cluster, job_or_task)Argument

Strany 403

getDebugLog11-117getDebugLog(c,j);See AlsocreateCommunicatingJob | createJob | createTask | parcluster

Strany 404

11 Functions — Alphabetical List11-118getJobClusterDataGet specific user data for job on generic clusterSyntaxuserdata = getJobClusterData(cluster,job

Strany 405

getJobFolder11-119getJobFolderFolder on client where jobs are storedSyntaxjoblocation = getJobFolder(cluster,job)Descriptionjoblocation = getJobFolde

Strany 406

11 Functions — Alphabetical List11-120getJobFolderOnClusterFolder on cluster where jobs are storedSyntaxjoblocation = getJobFolderOnCluster(cluster,jo

Strany 407

getLocalPart11-121getLocalPartLocal portion of codistributed arraySyntaxL = getLocalPart(A)DescriptionL = getLocalPart(A) returns the local portion o

Strany 408

11 Functions — Alphabetical List11-122getLogLocationLog location for job or taskSyntaxlogfile = getLogLocation(cluster,cj)logfile = getLogLocation(clu

Strany 409

globalIndices11-123globalIndicesGlobal indices for local part of codistributed arraySyntaxK = globalIndices(C,dim)K = globalIndices(C,dim,lab)[E,F] =

Strany 410

11 Functions — Alphabetical List11-124ExamplesCreate a 2-by-22 codistributed array among four workers, and view the global indices oneach lab:spmd

Strany 411

gop11-125gopGlobal operation across all workersSyntaxres = gop(FUN,x)res = gop(FUN,x,targetlab)ArgumentsFUN Function to operate across workers.x Argu

Strany 412

Variables and Transparency in parfor-Loops2-19Variables and Transparency in parfor-LoopsIn this section...“Unambiguous Variable Names” on page 2-19“T

Strany 413

11 Functions — Alphabetical List11-126ExamplesThis example shows how to calculate the sum and maximum values for x among allworkers.p = parpool('

Strany 414

gop11-127spmd res = gop(afun,num2str(labindex));endres{1}1 2 3 4See AlsolabBarrier | labindex | numlabs

Strany 415

11 Functions — Alphabetical List11-128gplusGlobal additionSyntaxS = gplus(X)S = gplus(X, targetlab)DescriptionS = gplus(X) returns the addition of the

Strany 416

gpuArray11-129gpuArrayCreate array on GPUSyntaxG = gpuArray(X)DescriptionG = gpuArray(X) copies the numeric array X to the GPU, and returns a gpuArra

Strany 417

11 Functions — Alphabetical List11-130 G2 10x10 108 gpuArrayCopy the array back to the MATLAB workspace.G1 = gather(G2);whos G1 Name

Strany 418

gpuDevice11-131gpuDeviceQuery or select GPU deviceSyntaxD = gpuDeviceD = gpuDevice()D = gpuDevice(IDX)gpuDevice([ ])DescriptionD = gpuDevice or D = g

Strany 419

11 Functions — Alphabetical List11-132for ii = 1:gpuDeviceCount g = gpuDevice(ii); fprintf(1,'Device %i has ComputeCapability %s \n',

Strany 420

gpuDeviceCount11-133gpuDeviceCountNumber of GPU devices presentSyntaxn = gpuDeviceCountDescriptionn = gpuDeviceCount returns the number of GPU device

Strany 421

11 Functions — Alphabetical List11-134gputimeitTime required to run function on GPUSyntaxt = gputimeit(F)t = gputimeit(F,N)Descriptiont = gputimeit(F)

Strany 422

gputimeit11-135t1 = gputimeit(f,1)0.2933More AboutTipsgputimeit is preferable to timeit for functions that use the GPU, because it ensuresthat all op

Strany 423

2 Parallel for-Loops (parfor)2-20Similarly, you cannot clear variables from a worker's workspace by executing clearinside a parfor statement:parf

Strany 424

11 Functions — Alphabetical List11-136helpHelp for toolbox functions in Command WindowSyntaxhelp class/functionArgumentsclass A Parallel Computing Too

Strany 425

help11-137parallel.job.CJSIndependentJobhelp parallel.job/createTaskhelp parallel.job/AdditionalPathsSee Alsomethods

Strany 426

11 Functions — Alphabetical List11-138InfArray of infinitySyntaxA = Inf(sz,arraytype)A = Inf(sz,datatype,arraytype)A = Inf(sz,'like',P)A = I

Strany 427

Inf11-139Argument Values Descriptions'gpuArray'Specifies gpuArray.datatype'double' (default),'single'Specifies underlyi

Strany 428

11 Functions — Alphabetical List11-140Create Codistributed Inf MatrixCreate a 1000-by-1000 codistributed double matrix of Infs, distributed by its sec

Strany 429

isaUnderlying11-141isaUnderlyingTrue if distributed array's underlying elements are of specified classSyntaxTF = isaUnderlying(D, 'classnam

Strany 430 - Create gpuArray False Matrix

11 Functions — Alphabetical List11-142iscodistributedTrue for codistributed arraySyntaxtf = iscodistributed(X)Descriptiontf = iscodistributed(X) retur

Strany 431

isComplete11-143isCompleteTrue if codistributor object is completeSyntaxtf = isComplete(codist)Descriptiontf = isComplete(codist) returns true if cod

Strany 432

11 Functions — Alphabetical List11-144isdistributedTrue for distributed arraySyntaxtf = isdistributed(X)Descriptiontf = isdistributed(X) returns true

Strany 433

isequal11-145isequalTrue if clusters have same property valuesSyntaxisequal(C1,C2)isequal(C1,C2,C3,...)Descriptionisequal(C1,C2) returns logical 1 (t

Strany 434

Variables and Transparency in parfor-Loops2-21 temp = struct(); temp.myfield1 = rand(); temp.myfield2 = i;end parfor i = 1:4 temp = struc

Strany 435

11 Functions — Alphabetical List11-146isequal (FevalFuture)True if futures have same IDSyntaxeq = isequal(F1,F2)Descriptioneq = isequal(F1,F2) returns

Strany 436

isreplicated11-147isreplicatedTrue for replicated arraySyntaxtf = isreplicated(X)Descriptiontf = isreplicated(X) returns true for a replicated array,

Strany 437

11 Functions — Alphabetical List11-148jobStartupFile for user-defined options to run when job startsSyntaxjobStartup(job)Argumentsjob The job for whic

Strany 438

labBarrier11-149labBarrierBlock execution until all workers reach this callSyntaxlabBarrierDescriptionlabBarrier blocks execution of a parallel algor

Strany 439

11 Functions — Alphabetical List11-150labBroadcastSend data to all workers or receive data sent to all workersSyntaxshared_data = labBroadcast(srcWkrI

Strany 440

labBroadcast11-151ExamplesIn this case, the broadcaster is the worker whose labindex is 1.srcWkrIdx = 1;if labindex == srcWkrIdx data = randn(10);

Strany 441

11 Functions — Alphabetical List11-152labindexIndex of this workerSyntaxid = labindexDescriptionid = labindex returns the index of the worker currentl

Strany 442

labProbe11-153labProbeTest to see if messages are ready to be received from other workerSyntaxisDataAvail = labProbeisDataAvail = labProbe(srcWkrIdx)

Strany 443

11 Functions — Alphabetical List11-154[isDataAvail,srcWkrIdx,tag] = labProbe returns labindex of the workers andtags of ready messages. If no data is

Strany 444

labReceive11-155labReceiveReceive data from another workerSyntaxdata = labReceivedata = labReceive(srcWkrIdx)data = labReceive('any',tag)da

Strany 445

vContentsGetting Started1Parallel Computing Toolbox Product Description . . . . . . . . 1-2Key Features . . . . . . . . . . . . . . . . . . . . . . .

Strany 446

2 Parallel for-Loops (parfor)2-22x = zeros(10,12);parfor idx = 1:12 x(:,idx) = idx;endThe following code offers a suggested workaround for this limit

Strany 447

11 Functions — Alphabetical List11-156More AboutTipsThis function blocks execution in the worker until the corresponding call to labSendoccurs in the

Strany 448

labSend11-157labSendSend data to another workerSyntaxlabSend(data,rcvWkrIdx)labSend(data,rcvWkrIdx,tag)Argumentsdata Data sent to the other workers;

Strany 449

11 Functions — Alphabetical List11-158labSendReceiveSimultaneously send data to and receive data from another workerSyntaxdataReceived = labSendReceiv

Strany 450

labSendReceive11-159dataReceived = labSendReceive(rcvWkrIdx,srcWkrIdx,dataSent,tag) usesthe specified tag for the communication. tag can be any integ

Strany 451

11 Functions — Alphabetical List11-160Lab 2: otherdata = 1Lab 3: otherdata = 1 3 4 2Transfer data to the next worker with

Strany 452

length11-161lengthLength of object arraySyntaxlength(obj)Argumentsobj An object or an array of objects.Descriptionlength(obj) returns the length of o

Strany 453

11 Functions — Alphabetical List11-162listAutoAttachedFilesList of files automatically attached to job, task, or parallel poolSyntaxlistAutoAttachedFi

Strany 454

listAutoAttachedFiles11-163listAutoAttachedFiles(obj)Automatically Attach Files ProgrammaticallyProgrammatically set a job to automatically attach co

Strany 455

11 Functions — Alphabetical List11-164loadLoad workspace variables from batch jobSyntaxload(job)load(job, 'X')load(job, 'X', &apos

Strany 456

load11-165S = load(job ...) returns the contents of job into variable S, which is a structcontaining fields matching the variables retrieved.Examples

Strany 457

Classification of Variables in parfor-Loops2-23Classification of Variables in parfor-LoopsWhen a name in a parfor-loop is recognized as referring to

Strany 458

11 Functions — Alphabetical List11-166logoutLog out of MJS clusterSyntaxlogout(c)Descriptionlogout(c) logs you out of the MJS cluster specified by clu

Strany 459

mapreducer11-167mapreducerDefine parallel execution environment for mapreducemapreducer is the execution configuration function for mapreduce. This f

Strany 460

11 Functions — Alphabetical List11-168mapreducer(hcluster) specifies a Hadoop cluster for parallel execution ofmapreduce. hcluster is a parallel.clust

Strany 461

mapreducer11-169Output Argumentsmr — Execution environment for mapreduceMapReducer objectExecution environment for mapreduce, returned as a MapReduce

Strany 462

11 Functions — Alphabetical List11-170methodsList functions of object classSyntaxmethods(obj)out = methods(obj)Argumentsobj An object or an array of o

Strany 463

methods11-171See Alsohelp

Strany 464

11 Functions — Alphabetical List11-172mpiLibConfLocation of MPI implementationSyntax[primaryLib, extras] = mpiLibConfArgumentsprimaryLib MPI implement

Strany 465

mpiLibConf11-173More AboutTipsUnder all circumstances, the MPI library must support all MPI-1 functions. Additionally,the MPI library must support nu

Strany 466

11 Functions — Alphabetical List11-174mpiprofileProfile parallel communication and execution timesSyntaxmpiprofilempiprofile on <options>mpiprof

Strany 467

mpiprofile11-175Option Descriptionadditionally records information about built-infunctions such as eig or labReceive.-messagedetail default-messagede

Strany 468

2 Parallel for-Loops (parfor)2-24loop variablesliced output variablebroadcast variabletemporary variablereduction variablesliced input variableNotes a

Strany 469

11 Functions — Alphabetical List11-176mpiprofile info returns a profiling data structure with additional fields to the oneprovided by the standard pro

Strany 470

mpiprofile11-177ExamplesIn pmode, turn on the parallel profiler, run your function in parallel, and call the viewer:mpiprofile on;% call your functio

Strany 471

11 Functions — Alphabetical List11-178mpiSettingsConfigure options for MPI communicationSyntaxmpiSettings('DeadlockDetection','on'

Strany 472

mpiSettings11-179ExamplesSet deadlock detection for a communicating job inside the jobStartup.m file for thatjob: % Inside jobStartup.m for the co

Strany 473

11 Functions — Alphabetical List11-180mxGPUCopyFromMxArray (C)Copy mxArray to mxGPUArrayC Syntax#include "gpu/mxGPUArray.h"mxGPUArray* mxGPU

Strany 474

mxGPUCopyGPUArray (C)11-181mxGPUCopyGPUArray (C)Duplicate (deep copy) mxGPUArray objectC Syntax#include "gpu/mxGPUArray.h"mxGPUArray* mxGPU

Strany 475

11 Functions — Alphabetical List11-182mxGPUCopyImag (C)Copy imaginary part of mxGPUArrayC Syntax#include "gpu/mxGPUArray.h"mxGPUArray* mxGPU

Strany 476

mxGPUCopyReal (C)11-183mxGPUCopyReal (C)Copy real part of mxGPUArrayC Syntax#include "gpu/mxGPUArray.h"mxGPUArray* mxGPUCopyReal(mxGPUArray

Strany 477

11 Functions — Alphabetical List11-184mxGPUCreateComplexGPUArray (C)Create complex GPU array from two real gpuArraysC Syntax#include "gpu/mxGPUAr

Strany 478

mxGPUCreateFromMxArray (C)11-185mxGPUCreateFromMxArray (C)Create read-only mxGPUArray object from input mxArrayC Syntax#include "gpu/mxGPUArray.

Strany 479

Loop Variable2-25Loop VariableThe loop variable defines the loop index value for each iteration. It is set with thebeginning line of a parfor stateme

Strany 480

11 Functions — Alphabetical List11-186mxGPUCreateGPUArray (C)Create mxGPUArray object, allocating memory on GPUC Syntax#include "gpu/mxGPUArray.h

Strany 481

mxGPUCreateGPUArray (C)11-187ReturnsPointer to an mxGPUArray.DescriptionmxGPUCreateGPUArray creates a new mxGPUArray object with the specified size,

Strany 482

11 Functions — Alphabetical List11-188mxGPUCreateMxArrayOnCPU (C)Create mxArray for returning CPU data to MATLAB with data from GPUC Syntax#include &q

Strany 483

mxGPUCreateMxArrayOnGPU (C)11-189mxGPUCreateMxArrayOnGPU (C)Create mxArray for returning GPU data to MATLABC Syntax#include "gpu/mxGPUArray.h&qu

Strany 484 - Create gpuArray Inf Matrix

11 Functions — Alphabetical List11-190mxGPUDestroyGPUArray (C)Delete mxGPUArray objectC Syntax#include "gpu/mxGPUArray.h"mxGPUDestroyGPUArra

Strany 485

mxGPUGetClassID (C)11-191mxGPUGetClassID (C)mxClassID associated with data on GPUC Syntax#include "gpu/mxGPUArray.h"mxClassID mxGPUGetClass

Strany 486

11 Functions — Alphabetical List11-192mxGPUGetComplexity (C)Complexity of data on GPUC Syntax#include "gpu/mxGPUArray.h"mxComplexity mxGPUGe

Strany 487

mxGPUGetData (C)11-193mxGPUGetData (C)Raw pointer to underlying dataC Syntax#include "gpu/mxGPUArray.h"void* mxGPUGetData(mxGPUArray const

Strany 488

11 Functions — Alphabetical List11-194mxGPUGetDataReadOnly (C)Read-only raw pointer to underlying dataC Syntax#include "gpu/mxGPUArray.h"voi

Strany 489

mxGPUGetDimensions (C)11-195mxGPUGetDimensions (C)mxGPUArray dimensionsC Syntax#include "gpu/mxGPUArray.h"mwSize const * mxGPUGetDimensions

Strany 490

2 Parallel for-Loops (parfor)2-26More About• “Classification of Variables in parfor-Loops” on page 2-23

Strany 491

11 Functions — Alphabetical List11-196mxGPUGetNumberOfDimensions (C)Size of dimension array for mxGPUArrayC Syntax#include "gpu/mxGPUArray.h"

Strany 492

mxGPUGetNumberOfElements (C)11-197mxGPUGetNumberOfElements (C)Number of elements on GPU for arrayC Syntax#include "gpu/mxGPUArray.h"mwSize

Strany 493

11 Functions — Alphabetical List11-198mxGPUIsSame (C)Determine if two mxGPUArrays refer to same GPU dataC Syntax#include "gpu/mxGPUArray.h"i

Strany 494

mxGPUIsSparse (C)11-199mxGPUIsSparse (C)Determine if mxGPUArray contains sparse GPU dataC Syntax#include "gpu/mxGPUArray.h"int mxGPUIsSpars

Strany 495

11 Functions — Alphabetical List11-200mxGPUIsValidGPUData (C)Determine if mxArray is pointer to valid GPU dataC Syntax#include "gpu/mxGPUArray.h&

Strany 496

mxInitGPU (C)11-201mxInitGPU (C)Initialize MATLAB GPU library on currently selected deviceC Syntax#include "gpu/mxGPUArray.h" int mxInitGPU

Strany 497

11 Functions — Alphabetical List11-202mxIsGPUArray (C)Determine if mxArray contains GPU dataC Syntax#include "gpu/mxGPUArray.h"int mxIsGPUAr

Strany 498

NaN11-203NaNArray of Not-a-NumbersSyntaxA = NaN(sz,arraytype)A = NaN(sz,datatype,arraytype)A = NaN(sz,'like',P)A = NaN(sz,datatype,'li

Strany 499

11 Functions — Alphabetical List11-204Argument Values Descriptions'gpuArray'Specifies gpuArray.datatype'double' (default),'si

Strany 500

NaN11-205Create Codistributed NaN MatrixCreate a 1000-by-1000 codistributed double matrix of NaNs, distributed by its seconddimension (columns).spmd(

Strany 501

Sliced Variables2-27Sliced VariablesA sliced variable is one whose value can be broken up into segments, or slices, whichare then operated on separat

Strany 502

11 Functions — Alphabetical List11-206numlabsTotal number of workers operating in parallel on current jobSyntaxn = numlabsDescriptionn = numlabs retur

Strany 503

ones11-207onesArray of onesSyntaxN = ones(sz,arraytype)N = ones(sz,datatype,arraytype)N = ones(sz,'like',P)N = ones(sz,datatype,'like&

Strany 504

11 Functions — Alphabetical List11-208Argument Values Descriptions'gpuArray'Specifies gpuArray.datatype'double' (default),'si

Strany 505

ones11-209ExamplesCreate Distributed Ones MatrixCreate a 1000-by-1000 distributed array of ones with underlying class double:D = ones(1000,'dist

Strany 506

11 Functions — Alphabetical List11-210pagefunApply function to each page of array on GPUSyntaxA = pagefun(FUN,B)A = pagefun(FUN,B,C,...)[A,B,...] = pa

Strany 507

pagefun11-211FUN must be a handle to a function that is written in the MATLAB language (i.e., not abuilt-in function or a MEX-function).Currently the

Strany 508

11 Functions — Alphabetical List11-212B = rand(K,N,P,'gpuArray');C = pagefun(@mtimes,A,B);s = size(C) % returns M-by-N-by-P s = 300

Strany 509

parallel.cluster.Hadoop11-213parallel.cluster.HadoopCreate Hadoop cluster objectSyntaxhcluster = parallel.cluster.Hadoophcluster = parallel.cluster.H

Strany 510

11 Functions — Alphabetical List11-214Input ArgumentsName-Value Pair ArgumentsSpecify optional comma-separated pairs of Name,Value arguments. Name is

Strany 511

parallel.cluster.Hadoop11-215See Alsomapreduce | mapreducer

Strany 512

2 Parallel for-Loops (parfor)2-28After the first level, you can use any type of valid MATLAB indexing in the second andfurther levels.The variable A s

Strany 513 - Output Arguments

11 Functions — Alphabetical List11-216parallel.clusterProfilesNames of all available cluster profilesSyntaxALLPROFILES = parallel.clusterProfiles[ALLP

Strany 514

parallel.clusterProfiles11-217allNames = parallel.clusterProfiles()myCluster = parcluster(allNames{end});See Alsoparallel.defaultClusterProfile | par

Strany 515

11 Functions — Alphabetical List11-218parallel.defaultClusterProfileExamine or set default cluster profileSyntaxp = parallel.defaultClusterProfileoldp

Strany 516

parallel.defaultClusterProfile11-219oldDefault = parallel.defaultClusterProfile('Profile2');strcmp(oldDefault,'MyProfile') % retu

Strany 517

11 Functions — Alphabetical List11-220parallel.exportProfileExport one or more profiles to fileSyntaxparallel.exportProfile(profileName, filename)para

Strany 518

parallel.exportProfile11-221notLocal = ~strcmp(allProfiles,'local');profilesToExport = allProfiles(notLocal);if ~isempty(profilesToExport)

Strany 519 - mpiprofile

11 Functions — Alphabetical List11-222parallel.gpu.CUDAKernelCreate GPU CUDA kernel object from PTX and CU codeSyntaxKERN = parallel.gpu.CUDAKernel(PT

Strany 520

parallel.gpu.CUDAKernel11-223 int idx = blockIdx.x * blockDim.x + threadIdx.x; if (idx < vecLen) { pi[idx] += c;}and simpleEx.ptx contai

Strany 521

11 Functions — Alphabetical List11-224parallel.importProfileImport cluster profiles from fileSyntaxprof = parallel.importProfile(filename)Descriptionp

Strany 522

parallel.importProfile11-225Import all the profiles from the file ManyProfiles.settings, and use the first one toopen a parallel pool.profs = paralle

Strany 523

Sliced Variables2-29a simple (nonindexed) broadcast variable; and every other index is a scalar constant, asimple broadcast variable, a nested for-lo

Strany 524 - C Syntax

11 Functions — Alphabetical List11-226parclusterCreate cluster objectSyntaxc = parclusterc = parcluster(profile)Descriptionc = parcluster returns a cl

Strany 525

parcluster11-227parpool(myCluster);Find a particular cluster using the profile named 'MyProfile', and create anindependent job on the clust

Strany 526

11 Functions — Alphabetical List11-228parfevalExecute function asynchronously on parallel pool workerSyntaxF = parfeval(p,fcn,numout,in1,in2,...)F = p

Strany 527

parfeval11-229for idx = 1:10 f(idx) = parfeval(p,@magic,1,idx); % Square size determined by idxend% Collect the results as they become available.mag

Strany 528

11 Functions — Alphabetical List11-230parfevalOnAllExecute function asynchronously on all workers in parallel poolSyntaxF = parfevalOnAll(p,fcn,numout

Strany 529

parfor11-231parforExecute loop iterations in parallelSyntaxparfor loopvar = initval:endval, statements, endparfor (loopvar = initval:endval, M), stat

Strany 530

11 Functions — Alphabetical List11-232than that number, even if additional workers are available. If you request more resourcesthan are available, MAT

Strany 531

parfor11-233Notably, the assignments to the variables i, t, and u do not affect variables with thesame name in the context of the parfor statement. T

Strany 532

11 Functions — Alphabetical List11-234are necessary for its execution, then automatically attaches those files to the parallelpool so that the code is

Strany 533

parpool11-235parpoolCreate parallel pool on clusterSyntaxparpoolparpool(poolsize)parpool(profilename)parpool(profilename,poolsize)parpool(cluster)par

Strany 534

2 Parallel for-Loops (parfor)2-30However, if it is clear that in every iteration, every reference to an array element isset before it is used, the var

Strany 535

11 Functions — Alphabetical List11-236parpool( ___ ,Name,Value) applies the specified values for certain properties whenstarting the pool.poolobj = pa

Strany 536

parpool11-237Return Pool Object and Delete PoolCreate a parallel pool with the default profile, and later delete the pool.poolobj = parpool;delete(po

Strany 537

11 Functions — Alphabetical List11-238Example: c = parcluster();Name-Value Pair ArgumentsSpecify optional comma-separated pairs of Name,Value argument

Strany 538

parpool11-239More AboutTips• The pool status indicator in the lower-left corner of the desktop shows the clientsession connection to the pool and the

Strany 539

11 Functions — Alphabetical List11-240This slight difference in behavior might be an issue in a mixed-platform environmentwhere the client is not the

Strany 540

parpool11-241P7P8• “Parallel Preferences”• “Clusters and Cluster Profiles”• “Pass Data to and from Worker Sessions”See AlsoComposite | delete | distr

Strany 541

11 Functions — Alphabetical List11-242pausePause MATLAB job scheduler queueSyntaxpause(mjs)Argumentsmjs MATLAB job scheduler object whose queue is pau

Strany 542

pctconfig11-243pctconfigConfigure settings for Parallel Computing Toolbox client sessionSyntaxpctconfig('p1', v1, ...)config = pctconfig(&a

Strany 543

11 Functions — Alphabetical List11-244If the property is 'hostname', the specified value is used to set the hostname forthe client session o

Strany 544

pctRunDeployedCleanup11-245pctRunDeployedCleanupClean up after deployed parallel applicationsSyntaxpctRunDeployedCleanupDescriptionpctRunDeployedClea

Strany 545

Broadcast Variables2-31Broadcast VariablesA broadcast variable is any variable other than the loop variable or a sliced variablethat is not affected

Strany 546

11 Functions — Alphabetical List11-246pctRunOnAllRun command on client and all workers in parallel poolSyntaxpctRunOnAll commandDescriptionpctRunOnAll

Strany 547

pctRunOnAll11-247See Alsoparpool

Strany 548

11 Functions — Alphabetical List11-248ploadLoad file into parallel sessionSyntaxpload(fileroot)Argumentsfileroot Part of filename common to all saved

Strany 549 - Create gpuArray NaN Matrix

pload11-249This creates three files (threeThings1.mat, threeThings2.mat,threeThings3.mat) in the current working directory.Clear the workspace on all

Strany 550

11 Functions — Alphabetical List11-250pmodeInteractive Parallel Command WindowSyntaxpmode startpmode start numworkerspmode start prof numworkerspmode

Strany 551

pmode11-251pmode quit or pmode exit stops the pmode job, deletes it, and closes the ParallelCommand Window. You can enter this command at the MATLAB

Strany 552

11 Functions — Alphabetical List11-252pmode start local 4Start pmode using the profile myProfile and eight workers on the cluster.pmode start myProfil

Strany 553

poolStartup11-253poolStartupFile for user-defined options to run on each worker when parallel pool startsSyntaxpoolStartupDescriptionpoolStartup runs

Strany 554

11 Functions — Alphabetical List11-254See AlsojobStartup | taskFinish | taskStartup

Strany 555

promote11-255promotePromote job in MJS cluster queueSyntaxpromote(c,job)Argumentsc The MJS cluster object that contains the job.job Job object promot

Strany 556

vi ContentsReductions: Cumulative Values Updated by Each Iteration . 2-8parfor Programming Considerations . . . . . . . . . . . . . . . . . . 2-10MATL

Strany 557

2 Parallel for-Loops (parfor)2-32Reduction VariablesMATLAB supports an important exception, called reductions, to the rule that loopiterations must be

Strany 558

11 Functions — Alphabetical List11-256Examine the new queue sequence:[pjobs, qjobs, rjobs, fjobs] = findJob(c);get(qjobs,'Name') 'Jo

Strany 559

psave11-257psaveSave data from communicating job sessionSyntaxpsave(fileroot)Argumentsfileroot Part of filename common to all saved files.Description

Strany 560

11 Functions — Alphabetical List11-258Clear the workspace on all the workers and confirm there are no variables.clear allwhosLoad the previously saved

Strany 561

rand11-259randArray of rand valuesSyntaxR = rand(sz,arraytype)R = rand(sz,datatype,arraytype)R = rand(sz,'like',P)R = rand(sz,datatype,&apo

Strany 562

11 Functions — Alphabetical List11-260Argument Values Descriptions'gpuArray'Specifies gpuArray.datatype'double' (default),'si

Strany 563

rand11-261Create Codistributed Rand MatrixCreate a 1000-by-1000 codistributed double matrix of rands, distributed by its seconddimension (columns).sp

Strany 564

11 Functions — Alphabetical List11-262randiArray of random integersSyntaxR = randi(valrange,sz,arraytype)R = randi(valrange,sz,datatype,arraytype)R =

Strany 565

randi11-263Argument Values Descriptions'codistributed'Specifies codistributed array, using the defaultdistribution scheme.'gpuArray&ap

Strany 566

11 Functions — Alphabetical List11-264ExamplesCreate Distributed Randi MatrixCreate a 1000-by-1000 distributed array of randi values from 1 to 100, wi

Strany 567

randn11-265randnArray of randn valuesSyntaxR = randn(sz,arraytype)R = randn(sz,datatype,arraytype)R = randn(sz,'like',P)R = randn(sz,dataty

Strany 568

Reduction Variables2-33parfor i = 1:n X = X + d(i);endThis loop is equivalent to the following, where each d(i) is calculated by a differentiterat

Strany 569

11 Functions — Alphabetical List11-266Argument Values Descriptions'gpuArray'Specifies gpuArray.datatype'double' (default),'si

Strany 570

randn11-267Create Codistributed Randn MatrixCreate a 1000-by-1000 codistributed double matrix of randn values, distributed by itssecond dimension (co

Strany 571

11 Functions — Alphabetical List11-268recreateCreate new job from existing jobSyntaxnewjob = recreate(oldjob)newjob = recreate(oldjob,'TaskID&apo

Strany 572

recreate11-269Recreate a Job with Specified TasksThis example shows how to recreate an independent job, which has only the tasks withIDs 21 to 32 fro

Strany 573

11 Functions — Alphabetical List11-270redistributeRedistribute codistributed array with another distribution schemeSyntaxD2 = redistribute(D1, codist)

Strany 574

reset11-271resetReset GPU device and clear its memorySyntaxreset(gpudev)Descriptionreset(gpudev) resets the GPU device and clears its memory of gpuAr

Strany 575

11 Functions — Alphabetical List11-272M % Display gpuArray 16 2 3 13 5 11 10 8 9 7 6 12 4 14 15

Strany 576

reset11-273clear MSee AlsogpuDevice | gpuArray | parallel.gpu.CUDAKernel

Strany 577

11 Functions — Alphabetical List11-274resumeResume processing queue in MATLAB job schedulerSyntaxresume(mjs)Argumentsmjs MATLAB job scheduler object w

Strany 578

saveAsProfile11-275saveAsProfileSave cluster properties to specified profileDescriptionsaveAsProfile(cluster,profileName) saves the properties of the

Strany 579

2 Parallel for-Loops (parfor)2-34Required (static): If the reduction assignment uses * or [,], then in every reductionassignment for X, X must be cons

Strany 580

11 Functions — Alphabetical List11-276saveProfileSave modified cluster properties to its current profileDescriptionsaveProfile(cluster) saves the modi

Strany 581

saveProfile11-277 Properties: Profile: local Modified: false Host: H

Strany 582

11 Functions — Alphabetical List11-278setConstantMemorySet some constant memory on GPUSyntaxsetConstantMemory(kern,sym,val)setConstantMemory(kern,sym1

Strany 583

setConstantMemory11-279setConstantMemory(KERN,'N1',int32(10));setConstantMemory(KERN,'N2',int32(10));setConstantMemory(KERN,&apos

Strany 584

11 Functions — Alphabetical List11-280setJobClusterDataSet specific user data for job on generic clusterSyntaxsetJobClusterData(cluster,job,userdata)A

Strany 585

size11-281sizeSize of object arraySyntaxd = size(obj)[m,n] = size(obj)[m1,m2,m3,...,mn] = size(obj)m = size(obj,dim)Argumentsobj An object or an arra

Strany 586

11 Functions — Alphabetical List11-282See Alsolength

Strany 587

sparse11-283sparseCreate sparse distributed or codistributed matrixSyntaxSD = sparse(FD)SC = sparse(m,n,codist)SC = sparse(m,n,codist,'noCommuni

Strany 588

11 Functions — Alphabetical List11-284To simplify this six-argument call, you can pass scalars for the argument v and one of thearguments i or j, in w

Strany 589

sparse11-285Create a sparse codistributed array from vectors of indices and a distributed array ofelement values:r = [ 1 1 4 4 8];c = [ 1 4 1 4

Strany 590

Reduction Variables2-35beginning of each iteration. The parfor on the right is correct, because it does not assignf inside the loop:Invalid Validf =

Strany 591

11 Functions — Alphabetical List11-286spmdExecute code in parallel on workers of parallel poolSyntaxspmd, statements, endspmd(n), statements, endspmd(

Strany 592

spmd11-287By default, MATLAB uses as many workers as it finds available in the pool. When thereare no MATLAB workers available, MATLAB executes the b

Strany 593

11 Functions — Alphabetical List11-288• If the AutoAttachFiles property in the cluster profile for the parallel pool is set totrue, MATLAB performs an

Strany 594

submit11-289submitQueue job in schedulerSyntaxsubmit(j)Argumentsj Job object to be queued.Descriptionsubmit(j) queues the job object j in its cluster

Strany 595

11 Functions — Alphabetical List11-290More AboutTipsWhen a job is submitted to a cluster queue, the job’s State property is set to queued,and the job

Strany 596

subsasgn11-291subsasgnSubscripted assignment for CompositeSyntaxC(i) = {B}C(1:end) = {B}C([i1, i2]) = {B1, B2}C{i} = BDescriptionsubsasgn assigns rem

Strany 597

11 Functions — Alphabetical List11-292subsrefSubscripted reference for CompositeSyntaxB = C(i)B = C([i1, i2, ...])B = C{i}[B1, B2, ...] = C{[i1, i2, .

Strany 598

taskFinish11-293taskFinishUser-defined options to run on worker when task finishesSyntaxtaskFinish(task)Argumentstask The task being evaluated by the

Strany 599

11 Functions — Alphabetical List11-294taskStartupUser-defined options to run on worker when task startsSyntaxtaskStartup(task)Argumentstask The task b

Strany 600

true11-295trueArray of logical 1 (true)SyntaxT = true(sz,arraytype)T = true(sz,'like',P)C = true(sz,codist)C = true(sz, ___ ,codist,'n

Strany 601

2 Parallel for-Loops (parfor)2-36parfor statement might produce values of X with different round-off errors. This is anunavoidable cost of parallelism

Strany 602

11 Functions — Alphabetical List11-296reference pages for codistributor1d and codistributor2dbc. To use the defaultdistribution scheme, you can specif

Strany 603

true11-297Each worker contains a 100-by-labindex local piece of C.Create gpuArray True MatrixCreate a 1000-by-1000 gpuArray of trues:G = true(1000,&a

Strany 604

11 Functions — Alphabetical List11-298updateAttachedFilesUpdate attached files or folders on parallel poolSyntaxupdateAttachedFiles(poolobj)Descriptio

Strany 605 - Create gpuArray Rand Matrix

updateAttachedFiles11-299See AlsoaddAttachedFiles | gcp | listAutoAttachedFiles | parpool

Strany 606

11 Functions — Alphabetical List11-300waitWait for job to change stateSyntaxwait(j)wait(j,'state')wait(j,'state',timeout)Arguments

Strany 607

wait11-301Note Simulink models cannot run while a MATLAB session is blocked by wait. If youmust run Simulink from the MATLAB client while also runnin

Strany 608

11 Functions — Alphabetical List11-302wait (FevalFuture)Wait for futures to completeSyntaxOK = wait(F)OK = wait(F,STATE)OK = wait(F,STATE,TIMEOUT)Desc

Strany 609

wait (GPUDevice)11-303wait (GPUDevice)Wait for GPU calculation to completeSyntaxwait(gpudev)Descriptionwait(gpudev) blocks execution in MATLAB until

Strany 610

11 Functions — Alphabetical List11-304zerosArray of zerosSyntaxZ = zeros(sz,arraytype)Z = zeros(sz,datatype,arraytype)Z = zeros(sz,'like',P)

Strany 611

zeros11-305Argument Values Descriptions'gpuArray'Specifies gpuArray.datatype'double' (default),'single', 'int8&apo

Strany 612

Reduction Variables2-37f(e,a) = a = f(a,e)Examples of identity elements for some functions are listed in this table.Function Identity Element+ 0* and

Strany 613

11 Functions — Alphabetical List11-306ExamplesCreate Distributed Zeros MatrixCreate a 1000-by-1000 distributed array of zeros with underlying class do

Strany 614

Glossary-1GlossaryCHECKPOINTBASEThe name of the parameter in the mdce_def file thatdefines the location of the checkpoint directories for theMATLAB jo

Strany 615

GlossaryGlossary-2distributed applicationThe same application that runs independently on severalnodes, possibly with different input parameters. There

Strany 616

GlossaryGlossary-3homogeneous clusterA cluster of identical machines, in terms of both hardwareand software.independent jobA job composed of independ

Strany 617

GlossaryGlossary-4nodeA computer that is part of a cluster.parallel applicationThe same application that runs on several workerssimultaneously, with c

Strany 618

GlossaryGlossary-5worker checkpointinformationFiles required by the worker during the execution oftasks.

Strany 620

2 Parallel for-Loops (parfor)2-38First consider the reduction function itself. To compare an iteration's result againstanother's, the functi

Strany 621

Temporary Variables2-39Temporary VariablesA temporary variable is any variable that is the target of a direct, nonindexedassignment, but is not a red

Strany 622

2 Parallel for-Loops (parfor)2-40 b = false; end ... endThis loop is acceptable as an ordinary for-loop, but as a parfor-loop, b is a

Strany 623

Temporary Variables2-41• “Reduction Variables” on page 2-32

Strany 624

viiReduction Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-32Basic Rules for Reduction Variables . . . . . . . . . . . .

Strany 625

2 Parallel for-Loops (parfor)2-42Improving parfor PerformanceWhere to Create ArraysWith a parfor-loop, it might be faster to have each MATLAB worker c

Strany 626

Improving parfor Performance2-43before the loop (as shown on the left below), rather than have each worker create its ownarrays inside the loop (as s

Strany 627

2 Parallel for-Loops (parfor)2-44Parallel PoolsIn this section...“What Is a Parallel Pool?” on page 2-44“Automatically Start and Stop a Parallel Pool

Strany 628

Parallel Pools2-45Automatically Start and Stop a Parallel PoolBy default, a parallel pool starts automatically when needed by certain parallel langua

Strany 629

2 Parallel for-Loops (parfor)2-46To open a parallel pool based on your preference settings:parpoolTo open a pool of a specific size:parpool(4)To use a

Strany 630

Parallel Pools2-47If you specify a pool size at the command line, this overrides the setting of yourpreferences. But this value must fall within the

Strany 631

2 Parallel for-Loops (parfor)2-48Convert Nested for-Loops to parforA typical use case for nested loops is to step through an array using one loop vari

Strany 632

Convert Nested for-Loops to parfor2-49M1 = magic(5);for a = 1:5 parfor b = 1:5 M2(a,b) = a*10 + b + M1(a,b)/10000; endendM2In this case,

Strany 634

3Single Program Multiple Data (spmd)• “Execute Simultaneously on Multiple Data Sets” on page 3-2• “Access Worker Variables with Composites” on page 3-

Strany 635

viii ContentsCreate Codistributed Arrays . . . . . . . . . . . . . . . . . . . . . . . . 3-11Programming Tips . . . . . . . . . . . . . . . . . . . .

Strany 636

3 Single Program Multiple Data (spmd)3-2Execute Simultaneously on Multiple Data SetsIn this section...“Introduction” on page 3-2“When to Use spmd” on

Strany 637

Execute Simultaneously on Multiple Data Sets3-3Define an spmd StatementThe general form of an spmd statement is:spmd <statements>endNote If

Strany 638

3 Single Program Multiple Data (spmd)3-4 R = rand(4,4);endNote All subsequent examples in this chapter assume that a parallel pool is open andremai

Strany 639

Execute Simultaneously on Multiple Data Sets3-5Display OutputWhen running an spmd statement on a parallel pool, all command-line output from theworke

Strany 640

3 Single Program Multiple Data (spmd)3-6Access Worker Variables with CompositesIn this section...“Introduction to Composites” on page 3-6“Create Compo

Strany 641 - Create gpuArray True Matrix

Access Worker Variables with Composites3-7 3 5 7 4 9 2MM{2} 16 2 3 13 5 11 10 8 9 7 6

Strany 642

3 Single Program Multiple Data (spmd)3-8 0 0 1 0 0 0 0 1Data transfers from worker to client when you explicit

Strany 643

Access Worker Variables with Composites3-9AA(:) % Composite [1] [2] [3] [4]spmd AA = AA * 2; % Multiply existing valueendAA(:) % Com

Strany 644

3 Single Program Multiple Data (spmd)3-10Distribute ArraysIn this section...“Distributed Versus Codistributed Arrays” on page 3-10“Create Distributed

Strany 645

Distribute Arrays3-11requirements. These overloaded functions include eye(___,'distributed'),rand(___,'distributed'), etc. For a

Strany 646

ixWorking with Codistributed Arrays . . . . . . . . . . . . . . . . . . . . 5-5How MATLAB Software Distributes Arrays . . . . . . . . . . . . . 5-5Cre

Strany 647

3 Single Program Multiple Data (spmd)3-12parpool('local',2) % Create poolspmd codist = codistributor1d(3,[4,12]); Z = zeros(3,3,16,cod

Strany 648

Programming Tips3-13Programming TipsIn this section...“MATLAB Path” on page 3-13“Error Handling” on page 3-13“Limitations” on page 3-13MATLAB PathAll

Strany 649

3 Single Program Multiple Data (spmd)3-14X = 5;spmd eval('X');endSimilarly, you cannot clear variables from a worker's workspace by

Strany 650

Programming Tips3-15run in parallel in another parallel pool, but runs serially in a single thread on the workerrunning its containing function.Neste

Strany 652

4Interactive Parallel Computation withpmodeThis chapter describes interactive pmode in the following sections:• “pmode Versus spmd” on page 4-2• “Run

Strany 653 - Glossary

4 Interactive Parallel Computation with pmode4-2pmode Versus spmdpmode lets you work interactively with a communicating job running simultaneouslyon s

Strany 654

Run Communicating Jobs Interactively Using pmode4-3Run Communicating Jobs Interactively Using pmodeThis example uses a local scheduler and runs the w

Strany 655 - Glossary-5

4 Interactive Parallel Computation with pmode4-44A variable does not necessarily have the same value on every worker. The labindexfunction returns the

Strany 656

Run Communicating Jobs Interactively Using pmode4-57Assign a unique value to the array on each worker, dependent on the worker number(labindex). With

Komentáře k této Příručce

Žádné komentáře