主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

dload

加载分布式数组和 Composite 对象

    说明

    dload filename 从名为 filename 的文件中加载所有变量。如果您未指定扩展名,该函数将假定扩展名是 .mat。该函数将分布式数组和 Composite 对象的内容加载到并行池工作单元上。该函数将其他数据类型直接加载到 MATLAB® 客户端的工作区中。

    • 当您加载分布式数组时,该函数会使用默认分发方案将数据分发到当前并行池工作单元上。使用此函数加载变量时,不需要打开相同大小的池。

    • 当您加载 Composite 对象时,该函数将数据发送给当前并行池工作单元。如果 Composite 太大,无法容纳在当前并行池中,则软件不会加载数据。如果 Composite 小于当前并行池,软件将返回警告。

    如果未打开并行池,则默认情况下 dload 函数将使用默认配置文件启动并行工作单元池。

    示例

    dload filename variables 从名为 filename 的文件中加载指定的变量。

    该函数不支持通配符,也不支持 -regexp 选项。如果文件不包含一个或多个指定的变量,软件将返回警告。

    示例

    dload -scatter ___ 尝试分发未分发的数据。如果 dload 无法分发数据,则会返回警告。

    示例

    dload(filename) 执行与 dload filename 相同的操作。

    例如,这些函数调用是等效的:

     dload("test.mat")
    dload test.mat

    示例

    [out1,...,outN] = dload(filename,variables) 加载指定的变量并将它们作为单独的输出参量返回。如果文件不包含一个或多个指定的变量,该函数将返回错误。

    示例

    示例

    全部折叠

    fname MAT 文件中的所有分布式数组加载到 MATLAB 工作区中。

    首先,列出工作区中的变量。

    whos

    列出 fname 中的变量。

    whos("-file","fname.mat")
      Name                 Size             Bytes  Class     Attributes
    
      DMAT_MANIFEST        1x1               4171  struct              
      X                  100x100            80000  double              
      Y                   90x90             64800  double              
      Z                  110x110            96800  double              
    

    加载 fname,然后再次列出工作区中的变量。默认情况下,dload 函数启动一个并行工作单元池来分配变量。

    dload fname.mat
    Starting parallel pool (parpool) using the 'Processes' profile ...
    Connected to parallel pool with 6 workers.
    
    whos
      Name        Size             Bytes  Class          Attributes
    
      X         100x100            80000  distributed              
      Y          90x90             64800  distributed              
      Z         110x110            96800  distributed              
    

    您还可以使用函数语法来加载变量。清除变量并调用 dload 函数。

    clear X Y Z
    dload("fname.mat")

    创建 Composite 对象,将其保存到文件,然后将数据加载回不同大小的并行池中。

    创建一个有四个工作单元的并行池,并使用 spmd 语句在客户端上创建 Composite 对象。将 Composite 对象保存到 mydata MAT 文件,然后清除工作区。

    p = parpool(4);
    Starting parallel pool (parpool) using the 'Processes' profile ...
    Connected to parallel pool with 4 workers.
    
    spmd
    P = magic(1000);
    Q = randn(2000);
    end
    dsave mydata P Q
    clear P Q
    delete(p);
    Parallel pool using the 'Processes' profile is shutting down.
    

    从 MAT 文件中加载 Composite 对象 PQ。新的并行池大于用于创建 Composite 对象的池,因此软件返回警告。

    [P,Q] = dload("mydata.mat","P","Q");
    Starting parallel pool (parpool) using the 'Processes' profile ...
    Connected to parallel pool with 6 workers.
    
    Warning: The Composite "P" was created with a pool of size 4, and is being loaded into a Composite of size 6 (the current default Composite size).
    
    Warning: The Composite "Q" was created with a pool of size 4, and is being loaded into a Composite of size 6 (the current default Composite size).
    

    列出工作区中的变量。

    whos
      Name      Size            Bytes  Class                   Attributes
    
      P         1x6               505  Composite                         
      Q         1x6               505  Composite                         
      p         1x1                 8  parallel.ProcessPool              
    

    从文件加载并分发表变量。

    查看 student_scores MAT 文件的内容。

    whos("-file","student_scores.mat")
      Name               Size            Bytes  Class    Attributes
    
      studentScores       -              13541  table              
    

    studentScores MAT 文件加载并分发 student_scores 表。

    scores = dload("-scatter","student_scores.mat");
    Starting parallel pool (parpool) using the 'Processes' profile ...
    Connected to parallel pool with 4 workers.
    

    检查分配给每个工作单元的数据量。

    spmd
        scores
    end
    Worker 1: 
      This worker stores scores(1:9,:).
              LocalPart: [9x26 table]
          Codistributor: [1x1 codistributor1d]
    Worker 2: 
      This worker stores scores(10:18,:).
              LocalPart: [9x26 table]
          Codistributor: [1x1 codistributor1d]
    Worker 3: 
      This worker stores scores(19:26,:).
              LocalPart: [8x26 table]
          Codistributor: [1x1 codistributor1d]
    Worker 4: 
      This worker stores scores(27:34,:).
              LocalPart: [8x26 table]
          Codistributor: [1x1 codistributor1d]
    

    输入参数

    全部折叠

    要加载的文件的名称,指定为字符串标量或字符向量。如果您未指定 filename,则 dload 函数将搜索名为 matlab 的 MAT 文件。如果函数找不到该文件,它将返回错误。

    如果没有为 filename 指定扩展名,dload 将搜索名为 filename 且扩展名为 .mat 的文件。

    根据文件的位置,filename 具有以下一种形式。

    • 如果文件位于当前文件夹或 MATLAB 路径上的文件夹中,则仅在 filename 中指定文件的名称。

    • 如果文件不在当前文件夹或 MATLAB 路径上的文件夹中,请在 filename 中指定完整路径或相对路径。

    示例: "myFile.mat" 指定文件的名称。

    示例: C:\myFolder\myFile.mat 指定文件的完整路径。

    数据类型: char | string

    要加载的变量的名称,指定为一个或多个字符串标量或字符向量。

    dload 函数不支持通配符,也不支持 -regexp 选项。如果函数找不到一个或多个指定的变量,它会返回警告。

    数据类型: char | string

    提示

    • dload 函数在现有并行池的工作单元上加载分布式数组或 Composite 对象。如果不存在池,则 dload 函数将启动一个新的并行池,除非在并行设置中禁用了自动启动池。如果不存在并行池并且 dload 无法启动并行池,则 dload 将加载分布式对象但无法加载 Composite 对象。

    版本历史记录

    在 R2010a 中推出

    另请参阅

    | | | |