An efficient algorithm for the evaluation of master stability function in networks of coupled oscillators