Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 并行计算中的复合数据_Matlab_Parallel Processing_Spmd - Fatal编程技术网

Matlab 并行计算中的复合数据

Matlab 并行计算中的复合数据,matlab,parallel-processing,spmd,Matlab,Parallel Processing,Spmd,我第一次使用并行计算(spmd) 启动池并执行一些并行计算后,我的工作区中只有复合变量,无法打开它们。或者当我双击打开它们时,它们是空的。我如何使用这些数据 这是我的密码: matlabpool open local 4 spmd if labindex==1 a = randn(300,1); end if labindex==2 b = randn(300,1); end if labindex==3 c = randn(3

我第一次使用并行计算(spmd)

启动池并执行一些并行计算后,我的工作区中只有复合变量,无法打开它们。或者当我双击打开它们时,它们是空的。我如何使用这些数据

这是我的密码:

matlabpool open local 4

spmd
    if labindex==1
    a = randn(300,1);
    end
    if labindex==2
     b = randn(300,1);
    end
    if labindex==3
    c = randn(300,1);
    end
    if labindex==4
     d = randn(300,1);
    end
 end

matlabpool close

如果希望在单个辅助进程上分别生成4个大小为(300,1)的数组,最好按以下方式执行。请注意,我的计算机/Matlab池中有4个内核

clc
clear

spmd    
    RandomArray = rand(300,1); % Matlab automatically creates a (300,1) array in each worker.
end

FinalArray = [RandomArray{:}]; % Concatenate everything outside of the spmd block.

whos % Check the results


Name               Size            Bytes  Class        Attributes

  FinalArray       300x4              9600  double                 
  RandomArray        1x4              1145  Composite              
如您所见,FinalArray的大小(300,4)如您所愿。使用上面的代码,将所有内容放在第二个spmd块中将是一件非常痛苦的事情,因为每个worker都不知道其他worker中的内容,并且每个变量在未使用它们的worker中都是未定义的。我不知道正确的术语抱歉,但是你可以阅读文档以获得更好的解释:)

编辑:

为了回答您的评论,这里有一个简单的例子。希望这就是你的意思:)

WHO的输出是:

Name            Size            Bytes  Class        Attributes

  FinalArray      4x10              320  double                 
  a               1x4               497  Composite              
  b               1x4               497  Composite              
  c               1x4               497  Composite              
  d               1x4               497  Composite              
  w               1x10               80  double                 
  x               1x10               80  double                 
  y               1x10               80  double                 
  z               1x10               80  double      

非常感谢。我理解这个例子,但如果我希望每个核心运行不同的作业,例如运行一个函数,该函数计算一些值,但每个核心使用不同的变量作为输入,该怎么办?好的,我明白了。请看我编辑的答案。希望这就是你想要的!这就是你想要的吗?对不起,我没看到。是的,太好了,非常感谢!
Name            Size            Bytes  Class        Attributes

  FinalArray      4x10              320  double                 
  a               1x4               497  Composite              
  b               1x4               497  Composite              
  c               1x4               497  Composite              
  d               1x4               497  Composite              
  w               1x10               80  double                 
  x               1x10               80  double                 
  y               1x10               80  double                 
  z               1x10               80  double