Problem just found. It is due to the global variables. So looks like spmd does not accept global variables. The error message is very misleading.
Just to benefit anyone who has the same problem.
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!