Using matlab's spmd to compute simple triple integral is giving me incorrect solution, any thoughts on what I am doing wrong?
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Austin Taylor
il 19 Ott 2020
Commentato: Walter Roberson
il 20 Ott 2020
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 Commenti
Raymond Norris
il 19 Ott 2020
Hi Austin,
Can you be a bit more specific about what solution you're getting and what you're expecting?
Raymond
Risposta accettata
Walter Roberson
il 19 Ott 2020
You integrate the first section of x with the first section of y and the first section of z, and the second section of x with the second section of y and the second section of z, and so on.
You never integrate the first section of x with the third section of y and the second section of z.
2 Commenti
Walter Roberson
il 20 Ott 2020
I want to be able to use MATLAB's spmd, using two cores, one doing subinterval [0,2] and the other doing [2,4] for each of the three integrands that make up the triple integral, not just one like I am using here
Then you would need 8 cores. Each core should decode (labindex minus one) to binary, add one to each digit result (getting 1 or 2), and use the first value to select the half-interval for x, the second value to select the half-interval for y, and the third value to select the half-interval for z.
More generally, for N sub-intervals, you need N^3 cores and each lab should decode (labindex-1) to a base N number, add one to each digit, and use that as an index to determine the N'th portion of the interval for x, y, z.
selectors = dec2base(labindex-1, N, 3) - '0' + 1;
ainit = x(selectors(1));
bfin = x(selectors(1)+1);
cinit = y(selectors(2));
dfin = y(selectors(2)+1);
einit = z(selectors(3));
ffin = z(selectors(3)+1);
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Parallel Computing Fundamentals in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!