Gunmen have opened fire on vehicles carrying Shi'ite Muslims in Pakistan's northwest, killing more than 40 people and wounding 20 others.