You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: StationaryDist_Case2_Simulation_raw.m
    path of file: ./repos/VFIToolkit-matlab/StationaryDist
    
    the code of the file until where you have to start completion: function StationaryDistKron=StationaryDist_Case2_Simulation_raw(PolicyIndexesKron,Phi_aprimeKron, Case2_Type,N_d,N_a,N_z,pi_z, simoptions)
%Simulates a path based on PolicyIndexes (and Phi_aprime) of length 'periods' after a burn
%in of length 'burnin' (burn-in are the initial run of points that are then
%dropped)

    
function StationaryDistKron=StationaryDist_Case2_Simulation_raw(PolicyIndexesKron,Phi_aprimeKron, Case2_Type,N_d,N_a,N_z,pi_z, simoptions)
%Simulates a path based on PolicyIndexes (and Phi_aprime) of length 'periods' after a burn
%in of length 'burnin' (burn-in are the initial run of points that are then
%dropped)
%Note: N_d is not actually needed, it is just left in so inputs are more
%like those for Case1

% Options needed
%    simoptions.seedpoint
%    simoptions.simperiods
%    simoptions.burnin
%    simoptions.parallel
%    simoptions.verbose
%    simoptions.ncores

MoveSSDKtoGPU=0;
if simoptions.parallel==2
    % Simulation on GPU is really slow.
    % So instead, switch to CPU, use all available cores, and then switch
    % back. For anything but ridiculously short simulations it is more than
    % worth the overhead.
    PolicyIndexesKron=gather(PolicyIndexesKron);
    Phi_aprimeKron=gather(Phi_aprimeKron);
    pi_z=gather(pi_z);
    simoptions.parallel=1;
    MoveSSDKtoGPU=1;
end