multi-thread version; and fix PieceWiseLinear bug when num_seg=1