beam search code which run on cluster.