Yes, I believe your code is correct, and is basically the same initialization that is already carried out by Parallel Computing Toolbox.
You can safely merge the two spmd blocks.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!