Using matlab's spmd to compute simple triple integral is giving me incorrect solution, any thoughts on what I am doing wrong?
Show older comments
close all; clear all; clc;
% I want to do this triple integral using SPMD
fun = @(x,y,z) z
totalval_s = integral3(fun,0,4,0,4,0,4)
% So I know the answer is 128, and integral3 works well
%
% Now I want to do the same triple integral but using SPMD
% 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()) %left point of subinterval
bfin = x(labindex()+1) %right point of subinterval
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
totalint = gplus(locint) % Add all values.
end
% Send the value back the client
totalvalue_spmd = totalint{1}
% However, the answer, totalvalue_spmd = 32, is incorrect.
% I am novice at using SPMD, need help troubleshooting what I did wrong
I want to break the three intervals into two subintervals each, and use integral3 in spmd to integrate in each dimension.
2 Comments
Raymond Norris
on 19 Oct 2020
Hi Austin,
Can you be a bit more specific about what solution you're getting and what you're expecting?
Raymond
Austin Taylor
on 20 Oct 2020
Accepted Answer
More Answers (0)
Categories
Find more on Parallel Computing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!