make this function general for vector classes based on distributed memory approach.