matlab composite,Create Composite object

Composite

Create Composite object

Syntax

C = Composite()

C = Composite(nlabs)

Description

C = Composite() creates a Composite object on the client

using workers from the parallel pool. The actual number of workers referenced by

this Composite object depends on the size of the pool and any existing Composite

objects. Generally, you should construct Composite objects outside any

spmd statement.

C = Composite(nlabs) creates a Composite object on the

parallel pool set that matches the specified constraint. nlabs

must be a vector of length 1 or 2, containing integers or Inf. If

nlabs is of length 1, it specifies the exact number of

workers to use. If nlabs is of size 2, it specifies the minimum

and maximum number of workers to use. The actual number of workers used is the

maximum number of workers compatible with the size of the parallel pool, and with

other existing Composite objects. An error is thrown if the constraints on the

number of workers cannot be met.

A Composite object has one entry for each lab; initially each entry contains no

data. Use either indexing or an spmd block to define values for

the entries.

Examples

The following examples all use a local parallel pool of four workers, opened with

the statement:

p = parpool('local',4);

This example shows how to create a Composite object with no defined elements, then

assign values using a for-loop in the client.

c = Composite(); % One element per worker in the pool

for w = 1:length(c)

c{w} = 0; % Value stored on each worker

end

This example shows how to assign Composite elements in an spmd

block.

c = Composite();

spmd

c = 0; % Value stored on each worker

end

This example shows how to assign the elements of a Composite with a value from

each worker.

c = Composite();

spmd

c = labindex;

end

c{:}

1

2

3

4

This example shows how to use a distributed array vector to set the values of a

Composite.

d = distributed([3 1 4 2]); % One integer per worker

spmd

c = getLocalPart(d); % Unique value on each worker

end

c{:}

3

1

4

2

Tips

A Composite is created on the workers of the existing parallel pool. If no

pool exists, Composite starts a new parallel pool, unless

the automatic starting of pools is disabled in your parallel preferences. If

there is no parallel pool and Composite cannot start one,

the result is a 1-by-1 Composite in the client workspace.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值