MATLAB Answers

Matlab and SPICE toolkit and parfor

13 views (last 30 days)
Leos Pohl
Leos Pohl on 9 Jun 2021
Commented: Leos Pohl on 11 Jun 2021
I am using NASA's SPICE toolkit MICE for matlab. The relevant code is
addpath(path_to_spice_src);
addpath(path_to_spice_lib);
cspice_furnsh('spice.ker');
tmutc = '2004 jun 15 9:32:00';
tmet = cspice_str2et(tmutc);
tend = tmet + 30*24*3600;
t_v = tmet:100:tend;
sun_pos = zeros(length(t_v),3);
for i = 1:length(t_v)
sun_pos_tmp = zeros(1,3);
% ask SPICE where the sun is
time = t_v(i);
% this is where the issue occurs
[r, ~] = cspice_spkpos('SUN',time,'MOON_ME','LT+S','MOON');
[~,lon,lat] = cspice_reclat(r);
sun_pos_tmp(1) = time;
sun_pos_tmp(2) = rad2deg(lon);
sun_pos_tmp(3) = rad2deg(lat);
sun_pos(i,:) = sun_pos_tmp;
end
When I run it like this all works. As usual, when i switch to parfor, i get into trouble:
Error using cspice_spkpos (line 874)
Error using mice
SPICE(UNKNOWNFRAME): [spkpos_c->SPKPOS->SPKEZP] The requested output frame 'MOON_ME' is not recognized by the reference frame subsystem. Please check that the appropriate kernels have been loaded and that you have correctly entered the name of the output frame.
I guess this has something to do with matlab being incapable of providing variables to workers, i cannot really change the SPICE toolkit or how it is designed. Is there a way, i can use parfor with the SPICE toolkit?
I hava provided the necessary kernels including the 'spice.ker' file here.

Answers (1)

Edric Ellis
Edric Ellis on 11 Jun 2021
I know nothing about SPICE, but at a guess, you probably need to initialise SPICE on the workers. I would try adding
fetchOutputs(parfevalOnAll(@()cspice_furnsh('spice.ker'),0));
before attempting your parfor loop. (You technically aren't requesting any outputs from your parfevalOnAll call, but fetchOutputs will throw an error if something goes wrong...)
  3 Comments

Sign in to comment.

Tags

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!