Main Content

broadcast

Class: matlab.compiler.mlspark.SparkContext
Package: matlab.compiler.mlspark

Broadcast a read-only variable to the cluster

Syntax

result = broadcast(sc,value)

Description

result = broadcast(sc,value) broadcasts a read-only variable value to the cluster initialized by SparkContext sc.

Input Arguments

expand all

The SparkContext to use, specified as a SparkContext object.

The value to be broadcast, specified as any supported data type.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | struct | table | cell | function_handle | categorical | string

Output Arguments

expand all

Broadcast variable, returned as a broadcast object with the following properties:

  • id

  • value

  • path

Examples

expand all

Broadcast a read-only variable to the cluster.

%% Connect to Spark
sparkProp = containers.Map({'spark.executor.cores'}, {'1'});
conf = matlab.compiler.mlspark.SparkConf('AppName','myApp', ...
                        'Master','local[1]','SparkProperties',sparkProp);
sc = matlab.compiler.mlspark.SparkContext(conf);

%% broadcast
myRdd = sc.parallelize({1,2,3,4,5});
myBroadcast = sc.broadcast('Hello, World');
newRdd = myRdd.map(@(x) myBroadcast.value);
countdata = newRdd.collect()
Introduced in R2016b