0

使用 matlab 的 spmd 计算简单的三重积分给了我不正确的解决方案,对我做错了什么有什么想法吗?

close all; clear all; clc;
% Create a parallel pool if none exists
if isempty(gcp())
    parpool();
end
nworkers = gcp().NumWorkers;
% Define the function
f = @(x,y,z) z
% Discretize the interval on the client
x = linspace(0,4,nworkers+1)
y = linspace(0,4,nworkers+1)
z = linspace(0,4,nworkers+1)
% On the workers
spmd
    ainit = x(labindex()) 
    bfin =  x(labindex()+1)
    cinit = y(labindex()) 
    dfin =  y(labindex()+1)
    einit = z(labindex()) 
    ffin =  z(labindex()+1)
%     locint = integral3(f,ainit,bfin,cinit,dfin,einit,ffin) % subinterval integration
    locint = integral3(f,ainit,bfin,ainit,bfin,ainit,bfin) % subinterval integration
    totalint = gplus(locint) % Add all values.
end
% Send the value back the client
totalvalue = totalint{1}

fun = @(x,y,z) z
q = integral3(fun,0,4,0,4,0,4)

q 是正确的解决方案。

4

1 回答 1

1

这里的问题是您的块正在划分要在每个spmd维度中集成的 3 维区域,而不仅仅是一个维度。您需要选择一个维度来划分积分,并仅在该维度上改变限制。例如,您可以通过将内部调用替换为以下内容来纠正问题:integral3spmd

spmd
    ...
    locint = integral3(f,0,4,0,4,einit,ffin)
    ...
end
于 2020-10-20T10:23:00.337 回答