Shmem sendrecv refactored

The code that implemented the sendrecv operation in shmem has been
extracted to a set of external functions.