works correctly with MPI only. changed calculation of end row number to elminate vertical blank rows