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