performance tuning – read a block of data from a stream using parallelism

I'm trying to read a feed and perform parallel operations. Here is the logic of the code inside ParallelDo:

1- open flow

2- Read a block of data

3- Close the flow

4- Process the data

5- Store the final result for this block of data in variable gI

6- Increment the shared progression variable between the kernels

7- Repeat with the next block of data

Note that this code works when you use Do instead of ParallelDo. It also works for small files using ParallelDo but returns errors:

Unable to take positions 4812 through 5062 in 
{1,2,3,4,4,3,4,3,3,2,1,0,0,0, -1, -1,0, -1,0, -1, -1, -2 , -2, -3, -2, -2, -2, -3, - 
2, -2, -2, -2, -1, -2, -1,0,1,1,1,2,2,3,3,3,3,2,2,1,0, <<4951>>}.

I managed to find that the error comes from the following line of the code:

    Yes[firstPeaks > 0, dG = data[[firstPeaks + xGS ;; firstPeaks + xGS + xGL]], dG = {0}

;

Therefore, I would have two questions:

1- Why does the code work with Do and not with ParallelDo? My only assumption is that the variable data containing the flow information block are somehow affected, but I do not see how.

2- How to solve this problem and use ParallelDo in my code? The improvement in performance seems to be quite important.

Thanks in advance!

SetSharedVariable[pr]
pr = 0;

Monitor[

ParallelDo[
  str = OpenRead[FileNameJoin[{path, fileName <> fileExtension}], BinaryFormat -> True];
data = f1 / @ Flatten[readlines[i, dataLength][[start ;; length + start]]];
To close[str];

allPeaks = findPeaks[data, 0.1, .01, maxHeight;
  firstPeaks = If[Length[allPeaks] > 0, first[allPeaks][[1]]+ 1, 0];
Yes[firstPeaks > 0, dG = data[[firstPeaks + xGS ;; firstPeaks + xGS + xGL]], dG = {0}

;
gI[[i]]= Abs[Total[dG]];
pr ++;
, {i, 1, width * height}
];
, ProgressIndicator[pr/(width*height)]

  ]// AbsoluteTiming